blacklight 7.18.1 → 7.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/components/blacklight/content_areas_shim.rb +2 -1
- data/app/components/blacklight/document_component.rb +6 -6
- data/app/components/blacklight/metadata_field_layout_component.rb +1 -1
- data/app/helpers/blacklight/render_partials_helper_behavior.rb +5 -1
- data/app/views/catalog/_document.html.erb +4 -3
- data/app/views/catalog/_document_list.html.erb +3 -2
- data/lib/blacklight/configuration.rb +7 -1
- data/lib/blacklight/configuration/view_config.rb +3 -1
- data/lib/blacklight/nested_open_struct_with_hash_access.rb +14 -11
- data/lib/blacklight/open_struct_with_hash_access.rb +1 -1
- data/lib/blacklight/search_builder.rb +1 -1
- data/lib/blacklight/solr/search_builder_behavior.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +18 -0
- data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +23 -1
- data/spec/models/blacklight/configuration_spec.rb +10 -0
- data/spec/views/catalog/_document.html.erb_spec.rb +9 -0
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b17640ea1dd81a41048bfbb2362bf692300e228045fac8f0d42aa0fbd281a63
|
4
|
+
data.tar.gz: 6956aa4b0fd67802b24d04b0f27677ca9f84d5692bdf8a34cd21b043d3fe8df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc71e8e6c0ee060b4303052caf0b9341c58a42c71e5f9badfe03f8013c6e3b96ba43f66d0d477c525edb58263a1993b9d9da143cf3f5f1c7fdb032568df5db87
|
7
|
+
data.tar.gz: e31975c219b1b709bdc6b765f123ffbf13978f56a26936f75d08cc7796e38703f163dc459e735f37bc36da3338e43f481d24b57d8308052509f6d19c0864bb7c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.19.0
|
@@ -5,7 +5,8 @@ module Blacklight
|
|
5
5
|
module ContentAreasShim
|
6
6
|
# Shim the `with` helper to write content into slots instead
|
7
7
|
def with(slot_name, *args, **kwargs, &block)
|
8
|
-
Deprecation.warn(
|
8
|
+
Deprecation.warn(Blacklight::ContentAreasShim,
|
9
|
+
'ViewComponents deprecated `with` and it will be removed in ViewComponents 3.0. content_areas. Use slots (https://viewcomponent.org/guide/slots.html) instead.')
|
9
10
|
public_send(slot_name, *args, **kwargs, &block)
|
10
11
|
end
|
11
12
|
end
|
@@ -25,7 +25,7 @@ module Blacklight
|
|
25
25
|
next static_content if static_content.present?
|
26
26
|
next unless component
|
27
27
|
|
28
|
-
Deprecation.warn('Pass the presenter to the DocumentComponent') if @presenter.nil?
|
28
|
+
Deprecation.warn(Blacklight::DocumentComponent, 'Pass the presenter to the DocumentComponent') if @presenter.nil?
|
29
29
|
|
30
30
|
component.new(*args, document: @document, presenter: @presenter, document_counter: @document_counter, **kwargs)
|
31
31
|
end)
|
@@ -34,7 +34,7 @@ module Blacklight
|
|
34
34
|
renders_one :metadata, (lambda do |static_content = nil, *args, component: nil, fields: nil, **kwargs|
|
35
35
|
next static_content if static_content.present?
|
36
36
|
|
37
|
-
Deprecation.warn('Pass the presenter to the DocumentComponent') if !fields && @presenter.nil?
|
37
|
+
Deprecation.warn(Blacklight::DocumentComponent, 'Pass the presenter to the DocumentComponent') if !fields && @presenter.nil?
|
38
38
|
|
39
39
|
component ||= Blacklight::DocumentMetadataComponent
|
40
40
|
|
@@ -48,7 +48,7 @@ module Blacklight
|
|
48
48
|
next image_options_or_static_content if image_options_or_static_content.is_a? String
|
49
49
|
|
50
50
|
component ||= @presenter&.view_config&.thumbnail_component || Blacklight::Document::ThumbnailComponent
|
51
|
-
Deprecation.warn('Pass the presenter to the DocumentComponent') if !component && @presenter.nil?
|
51
|
+
Deprecation.warn(Blacklight::DocumentComponent, 'Pass the presenter to the DocumentComponent') if !component && @presenter.nil?
|
52
52
|
|
53
53
|
component.new(*args, document: @document, presenter: @presenter, counter: @counter, image_options: image_options_or_static_content, **kwargs)
|
54
54
|
end)
|
@@ -93,13 +93,13 @@ module Blacklight
|
|
93
93
|
@id = id || ('document' if show)
|
94
94
|
@classes = classes
|
95
95
|
|
96
|
-
Deprecation.warn('Passing embed_component is deprecated') if @embed_component.present?
|
96
|
+
Deprecation.warn(Blacklight::DocumentComponent, 'Passing embed_component is deprecated') if @embed_component.present?
|
97
97
|
@embed_component = embed_component
|
98
98
|
|
99
|
-
Deprecation.warn('Passing metadata_component is deprecated') if @metadata_component.present?
|
99
|
+
Deprecation.warn(Blacklight::DocumentComponent, 'Passing metadata_component is deprecated') if @metadata_component.present?
|
100
100
|
@metadata_component = metadata_component || Blacklight::DocumentMetadataComponent
|
101
101
|
|
102
|
-
Deprecation.warn('Passing thumbnail_component is deprecated') if @thumbnail_component.present?
|
102
|
+
Deprecation.warn(Blacklight::DocumentComponent, 'Passing thumbnail_component is deprecated') if @thumbnail_component.present?
|
103
103
|
@thumbnail_component = thumbnail_component || Blacklight::Document::ThumbnailComponent
|
104
104
|
|
105
105
|
@document_counter = document_counter
|
@@ -25,7 +25,7 @@ module Blacklight
|
|
25
25
|
def value(*args, **kwargs, &block)
|
26
26
|
return set_slot(:values, *args, **kwargs, &block) if block_given?
|
27
27
|
|
28
|
-
Deprecation.warn('The `value` content area is deprecated; render from the values slot instead')
|
28
|
+
Deprecation.warn(Blacklight::MetadataFieldLayoutComponent, 'The `value` content area is deprecated; render from the values slot instead')
|
29
29
|
|
30
30
|
values.first
|
31
31
|
end
|
@@ -84,12 +84,16 @@ module Blacklight::RenderPartialsHelperBehavior
|
|
84
84
|
# @param [Hash] locals to pass to the render call
|
85
85
|
# @return [String]
|
86
86
|
def render_document_index_with_view view, documents, locals = {}
|
87
|
+
view_config = blacklight_config&.view_config(view)
|
88
|
+
|
89
|
+
return render partial: view_config.template, locals: locals.merge(documents: documents, view_config: view_config) if view_config&.template
|
90
|
+
|
87
91
|
template = cached_view ['index', view].join('_') do
|
88
92
|
find_document_index_template_with_view(view, locals)
|
89
93
|
end
|
90
94
|
|
91
95
|
if template
|
92
|
-
template.render(self, locals.merge(documents: documents))
|
96
|
+
template.render(self, locals.merge(documents: documents, view_config: view_config))
|
93
97
|
else
|
94
98
|
''
|
95
99
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<% # container for a single doc -%>
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
<% view_config = local_assigns[:view_config] || blacklight_config.view_config(document_index_view_type) %>
|
3
|
+
<%= render (view_config.document_component || Blacklight::DocumentComponent).new(presenter: document_presenter(document), counter: document_counter_with_offset(document_counter)) do |component| %>
|
4
|
+
<% component.public_send(view_config.document_component.blank? && view_config.partials.any? ? :body : :partial) do %>
|
5
|
+
<%= render_document_partials document, view_config.partials, component: component, document_counter: document_counter %>
|
5
6
|
<% end %>
|
6
7
|
<% end %>
|
@@ -1,4 +1,5 @@
|
|
1
1
|
<% # container for all documents in index list view -%>
|
2
|
-
|
3
|
-
|
2
|
+
<% view_config = local_assigns[:view_config] || blacklight_config&.view_config(document_index_view_type) %>
|
3
|
+
<div id="documents" class="documents-<%= view_config&.key || document_index_view_type %>">
|
4
|
+
<%= render documents, as: :document, view_config: view_config %>
|
4
5
|
</div>
|
@@ -170,6 +170,8 @@ module Blacklight
|
|
170
170
|
def initialize(hash = {})
|
171
171
|
super(self.class.default_values.deep_dup.merge(hash))
|
172
172
|
yield(self) if block_given?
|
173
|
+
|
174
|
+
@view_config ||= {}
|
173
175
|
end
|
174
176
|
|
175
177
|
def document_model
|
@@ -333,7 +335,6 @@ module Blacklight
|
|
333
335
|
view_type = nil
|
334
336
|
end
|
335
337
|
|
336
|
-
@view_config ||= {}
|
337
338
|
@view_config[[view_type, action_name]] ||= begin
|
338
339
|
if view_type.nil?
|
339
340
|
action_config(action_name)
|
@@ -428,6 +429,11 @@ module Blacklight
|
|
428
429
|
fields.merge(show_fields)
|
429
430
|
end
|
430
431
|
|
432
|
+
def freeze
|
433
|
+
each { |_k, v| v.is_a?(OpenStruct) && v.freeze }
|
434
|
+
super
|
435
|
+
end
|
436
|
+
|
431
437
|
private
|
432
438
|
|
433
439
|
def add_action(config_hash, name, opts)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class Blacklight::Configuration
|
3
3
|
class ViewConfig < Blacklight::OpenStructWithHashAccess
|
4
|
+
# @!attribute template
|
5
|
+
# @return [String] partial to render around the documents
|
4
6
|
# @!attribute partials
|
5
7
|
# @return [Array<String>] partials to render for each document(see #render_document_partials)
|
6
8
|
# @!attribute document_presenter_class
|
@@ -20,7 +22,7 @@ class Blacklight::Configuration
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def display_label(deprecated_key = nil, **options)
|
23
|
-
Deprecation.warn('Passing the key argument to ViewConfig#display_label is deprecated') if deprecated_key.present?
|
25
|
+
Deprecation.warn(Blacklight::Configuration::ViewConfig, 'Passing the key argument to ViewConfig#display_label is deprecated') if deprecated_key.present?
|
24
26
|
|
25
27
|
I18n.t(
|
26
28
|
:"blacklight.search.view_title.#{deprecated_key || key}",
|
@@ -14,12 +14,12 @@ module Blacklight
|
|
14
14
|
|
15
15
|
def initialize(klass, hash = {})
|
16
16
|
@nested_class = klass
|
17
|
-
value = hash.
|
18
|
-
if v.is_a? Hash
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
value = hash.each_with_object({}) do |(k, v), h|
|
18
|
+
h[k] = if v.is_a? Hash
|
19
|
+
nested_class.new({ key: k.to_sym }.merge(v))
|
20
|
+
else
|
21
|
+
v
|
22
|
+
end
|
23
23
|
end
|
24
24
|
|
25
25
|
super value
|
@@ -37,7 +37,7 @@ module Blacklight
|
|
37
37
|
# into another NestedOpenStructWithHashAccess
|
38
38
|
def []=(key, value)
|
39
39
|
if value.is_a? Hash
|
40
|
-
send "#{key}=", nested_class.new(value)
|
40
|
+
send "#{key}=", nested_class.new({ key: key.to_sym }.merge(value))
|
41
41
|
else
|
42
42
|
super
|
43
43
|
end
|
@@ -93,19 +93,22 @@ module Blacklight
|
|
93
93
|
len = args.length
|
94
94
|
|
95
95
|
res = if mid.to_s.end_with?('!')
|
96
|
-
m = mid[0...-1]
|
96
|
+
m = mid[0...-1].to_sym
|
97
97
|
new_ostruct_member!(m)
|
98
98
|
@table[m]
|
99
99
|
elsif mid.to_s.end_with?('=')
|
100
|
-
m = mid[0...-1]
|
100
|
+
m = mid[0...-1].to_sym
|
101
101
|
new_ostruct_member!(m)
|
102
102
|
@table[m] = args.first
|
103
103
|
elsif len.zero? && kwargs.blank? && !block
|
104
|
-
Deprecation.warn(
|
104
|
+
Deprecation.warn(Blacklight::NestedOpenStructWithHashAccess,
|
105
|
+
"Initializing a #{nested_class} implicitly (by calling #{mid}) is deprecated. Call it as #{mid}! or pass initialize arguments")
|
106
|
+
|
107
|
+
new_ostruct_member!(mid)
|
105
108
|
@table[mid]
|
106
109
|
else
|
107
110
|
new_ostruct_member!(mid)
|
108
|
-
@table[mid] = nested_class.new(
|
111
|
+
@table[mid] = nested_class.new(key: mid, **(args.first || {}), **kwargs)
|
109
112
|
end
|
110
113
|
|
111
114
|
block&.call(res)
|
@@ -6,7 +6,7 @@ module Blacklight
|
|
6
6
|
class OpenStructWithHashAccess < OpenStruct
|
7
7
|
delegate :keys, :each, :map, :has_key?, :key?, :include?, :empty?,
|
8
8
|
:length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!,
|
9
|
-
:replace, :fetch, :to_json, :as_json, :any?, to: :to_h
|
9
|
+
:replace, :fetch, :to_json, :as_json, :any?, :freeze, :unfreeze, :frozen?, to: :to_h
|
10
10
|
|
11
11
|
##
|
12
12
|
# Expose the internal hash
|
@@ -45,7 +45,7 @@ module Blacklight
|
|
45
45
|
##
|
46
46
|
# Update the :q (query) parameter
|
47
47
|
def where(conditions)
|
48
|
-
Deprecation.warn("SearchBuilder#where must be called with a hash, received #{conditions.inspect}.") unless conditions.is_a? Hash
|
48
|
+
Deprecation.warn(Blacklight::SearchBuilder, "SearchBuilder#where must be called with a hash, received #{conditions.inspect}.") unless conditions.is_a? Hash
|
49
49
|
params_will_change!
|
50
50
|
@search_state = @search_state.reset(@search_state.params.merge(q: conditions))
|
51
51
|
@blacklight_params = @search_state.params.dup
|
@@ -66,7 +66,7 @@ module Blacklight::Solr
|
|
66
66
|
add_search_field_with_local_parameters(solr_parameters)
|
67
67
|
elsif search_state.query_param.is_a? Hash
|
68
68
|
if search_state.query_param == @additional_filters && !processor_chain.include?(:add_additional_filters)
|
69
|
-
Deprecation.warn('Expecting to see the processor step add_additional_filters; falling back to legacy query handling')
|
69
|
+
Deprecation.warn(Blacklight::Solr::SearchBuilderBehavior, 'Expecting to see the processor step add_additional_filters; falling back to legacy query handling')
|
70
70
|
add_additional_filters(solr_parameters, search_state.query_param)
|
71
71
|
end
|
72
72
|
elsif search_state.query_param
|
@@ -320,6 +320,24 @@ RSpec.describe BlacklightHelper do
|
|
320
320
|
response = helper.render_document_index_with_view :view_type, [obj1, obj1]
|
321
321
|
expect(response).to have_selector "div#documents"
|
322
322
|
end
|
323
|
+
|
324
|
+
context 'with a template partial provided by the view config' do
|
325
|
+
before do
|
326
|
+
blacklight_config.view.gallery(template: '/my/partial')
|
327
|
+
end
|
328
|
+
|
329
|
+
def stub_template(hash)
|
330
|
+
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'renders that template' do
|
334
|
+
stub_template 'my/_partial.html.erb' => 'some content'
|
335
|
+
|
336
|
+
response = helper.render_document_index_with_view :gallery, [obj1, obj1]
|
337
|
+
|
338
|
+
expect(response).to eq 'some content'
|
339
|
+
end
|
340
|
+
end
|
323
341
|
end
|
324
342
|
|
325
343
|
describe "#document_index_view_type" do
|
@@ -1,6 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Blacklight::NestedOpenStructWithHashAccess do
|
4
|
+
subject { described_class.new(Blacklight::OpenStructWithHashAccess) }
|
5
|
+
|
6
|
+
describe '#key' do
|
7
|
+
context 'for an object provided by the initializer' do
|
8
|
+
subject { described_class.new(Blacklight::OpenStructWithHashAccess, a: { b: 1 }) }
|
9
|
+
|
10
|
+
it 'copies the key to the initialized value' do
|
11
|
+
expect(subject.a).to have_attributes key: :a, b: 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for an object provided through assignment' do
|
16
|
+
it 'copies the key to the initialized value' do
|
17
|
+
subject.a!
|
18
|
+
|
19
|
+
expect(subject.a).to have_attributes key: :a
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
4
24
|
describe "#deep_dup" do
|
5
25
|
it "preserves the current class" do
|
6
26
|
expect(described_class.new(described_class).deep_dup).to be_a_kind_of described_class
|
@@ -28,13 +48,15 @@ RSpec.describe Blacklight::NestedOpenStructWithHashAccess do
|
|
28
48
|
subject { described_class.new(Blacklight::Configuration::Field) }
|
29
49
|
|
30
50
|
it 'strips the trailing !' do
|
31
|
-
subject.
|
51
|
+
subject.blah!
|
32
52
|
expect(subject.blah).to have_attributes(key: :blah)
|
53
|
+
expect(subject.keys).to eq [:blah]
|
33
54
|
end
|
34
55
|
|
35
56
|
it 'supports direct assignment' do
|
36
57
|
subject.blah = '123'
|
37
58
|
expect(subject.blah).to eq '123'
|
59
|
+
expect(subject.keys).to eq [:blah]
|
38
60
|
end
|
39
61
|
end
|
40
62
|
end
|
@@ -621,4 +621,14 @@ RSpec.describe "Blacklight::Configuration", api: true do
|
|
621
621
|
end
|
622
622
|
end
|
623
623
|
end
|
624
|
+
|
625
|
+
describe '#freeze' do
|
626
|
+
it 'freezes the configuration' do
|
627
|
+
config.freeze
|
628
|
+
|
629
|
+
expect(config.a).to be_nil
|
630
|
+
expect { config.a = '123' }.to raise_error(FrozenError)
|
631
|
+
expect { config.view.a = '123' }.to raise_error(FrozenError)
|
632
|
+
end
|
633
|
+
end
|
624
634
|
end
|
@@ -46,4 +46,13 @@ RSpec.describe "catalog/_document" do
|
|
46
46
|
expect(rendered).to have_selector 'article.document header', text: '22. xyz'
|
47
47
|
expect(rendered).not_to match(/partial/)
|
48
48
|
end
|
49
|
+
|
50
|
+
it 'renders the partial using a provided view config' do
|
51
|
+
view_config = Blacklight::Configuration::ViewConfig.new partials: %w[a]
|
52
|
+
stub_template "catalog/_a_default.html.erb" => "partial"
|
53
|
+
|
54
|
+
render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: view_config }
|
55
|
+
|
56
|
+
expect(rendered).to match(/partial/)
|
57
|
+
end
|
49
58
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RSpec.describe "catalog/_document_list", type: :view do
|
4
4
|
before do
|
5
|
-
allow(view).to receive_messages(document_index_view_type: "some-view", documents: [])
|
5
|
+
allow(view).to receive_messages(document_index_view_type: "some-view", documents: [], blacklight_config: nil)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "includes a class for the current view" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
@@ -17,7 +17,7 @@ authors:
|
|
17
17
|
autorequire:
|
18
18
|
bindir: exe
|
19
19
|
cert_chain: []
|
20
|
-
date: 2021-
|
20
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|