blacklight 7.3.0 → 7.4.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/helpers/blacklight/blacklight_helper_behavior.rb +2 -1
- data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -3
- data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -2
- data/app/helpers/blacklight/layout_helper_behavior.rb +7 -0
- data/app/helpers/blacklight/render_partials_helper_behavior.rb +1 -9
- data/app/helpers/blacklight/url_helper_behavior.rb +2 -2
- data/app/presenters/blacklight/document_presenter.rb +74 -4
- data/app/presenters/blacklight/field_presenter.rb +22 -11
- data/app/presenters/blacklight/index_presenter.rb +9 -50
- data/app/presenters/blacklight/show_presenter.rb +6 -53
- data/app/presenters/blacklight/thumbnail_presenter.rb +14 -4
- data/app/services/blacklight/field_retriever.rb +7 -1
- data/app/views/catalog/_document.atom.builder +1 -1
- data/app/views/catalog/_document.rss.builder +2 -2
- data/app/views/catalog/_facet_layout.html.erb +3 -3
- data/app/views/catalog/_opensearch_response_metadata.html.erb +3 -3
- data/app/views/catalog/_search_results.html.erb +1 -1
- data/app/views/catalog/index.json.jbuilder +2 -3
- data/app/views/catalog/show.json.jbuilder +3 -3
- data/app/views/layouts/blacklight/base.html.erb +2 -2
- data/config/i18n-tasks.yml +1 -1
- data/config/locales/blacklight.ar.yml +250 -0
- data/config/locales/blacklight.hu.yml +8 -0
- data/config/locales/blacklight.nl.yml +8 -0
- data/config/locales/blacklight.sq.yml +9 -0
- data/config/locales/blacklight.zh.yml +8 -0
- data/lib/blacklight/configuration.rb +16 -4
- data/spec/features/search_spec.rb +5 -0
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +4 -0
- data/spec/helpers/blacklight/layout_helper_behavior_spec.rb +10 -0
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
- data/spec/helpers/catalog_helper_spec.rb +9 -0
- data/spec/models/blacklight/configuration_spec.rb +32 -10
- data/spec/presenters/blacklight/document_presenter_spec.rb +9 -14
- data/spec/presenters/blacklight/show_presenter_spec.rb +23 -6
- data/spec/presenters/thumbnail_presenter_spec.rb +1 -2
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -2
- data/spec/views/catalog/index.html.erb_spec.rb +1 -1
- metadata +3 -2
@@ -357,16 +357,28 @@ module Blacklight
|
|
357
357
|
##
|
358
358
|
# Return a list of fields for the index display that should be used for the
|
359
359
|
# provided document. This respects any configuration made using for_display_type
|
360
|
-
def index_fields_for(
|
361
|
-
display_type =
|
360
|
+
def index_fields_for(document_or_display_type)
|
361
|
+
display_type = if document_or_display_type.is_a? Blacklight::Document
|
362
|
+
Deprecation.warn self, "Calling index_fields_for with a #{document_or_display_type.class} is deprecated and will be removed in Blacklight 8. Pass the display type instead."
|
363
|
+
document_or_display_type.first(index.display_type_field)
|
364
|
+
else
|
365
|
+
document_or_display_type
|
366
|
+
end
|
367
|
+
|
362
368
|
for_display_type(display_type).index_fields.merge(index_fields)
|
363
369
|
end
|
364
370
|
|
365
371
|
##
|
366
372
|
# Return a list of fields for the show page that should be used for the
|
367
373
|
# provided document. This respects any configuration made using for_display_type
|
368
|
-
def show_fields_for(
|
369
|
-
display_type =
|
374
|
+
def show_fields_for(document_or_display_type)
|
375
|
+
display_type = if document_or_display_type.is_a? Blacklight::Document
|
376
|
+
Deprecation.warn self, "Calling show_fields_for with a #{document_or_display_type.class} is deprecated and will be removed in Blacklight 8. Pass the display type instead."
|
377
|
+
document_or_display_type.first(show.display_type_field)
|
378
|
+
else
|
379
|
+
document_or_display_type
|
380
|
+
end
|
381
|
+
|
370
382
|
for_display_type(display_type).show_fields.merge(show_fields)
|
371
383
|
end
|
372
384
|
|
@@ -1,6 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe "Search Page" do
|
4
|
+
it 'declares the page language in the html lang attribute' do
|
5
|
+
visit root_path
|
6
|
+
expect(page).to have_selector('html[lang=en]')
|
7
|
+
end
|
8
|
+
|
4
9
|
it "shows welcome" do
|
5
10
|
visit root_path
|
6
11
|
expect(page).to have_selector("input#q")
|
@@ -103,6 +103,10 @@ RSpec.describe Blacklight::ConfigurationHelperBehavior do
|
|
103
103
|
describe "#document_show_link_field" do
|
104
104
|
let(:document) { SolrDocument.new id: 123, a: 1, b: 2, c: 3 }
|
105
105
|
|
106
|
+
before do
|
107
|
+
allow(Deprecation).to receive(:warn)
|
108
|
+
end
|
109
|
+
|
106
110
|
it "allows single values" do
|
107
111
|
blacklight_config.index.title_field = :a
|
108
112
|
f = helper.document_show_link_field document
|
@@ -35,4 +35,14 @@ RSpec.describe Blacklight::LayoutHelperBehavior do
|
|
35
35
|
expect(helper.container_classes).to eq 'container'
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
describe '#html_tag_attributes' do
|
40
|
+
before do
|
41
|
+
allow(I18n).to receive(:locale).and_return('x')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the current locale as the lang' do
|
45
|
+
expect(helper.html_tag_attributes).to include lang: 'x'
|
46
|
+
end
|
47
|
+
end
|
38
48
|
end
|
@@ -206,7 +206,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
206
206
|
end
|
207
207
|
|
208
208
|
it "consists of the document title wrapped in a <a>" do
|
209
|
-
|
209
|
+
allow(Deprecation).to receive(:warn)
|
210
210
|
expect(helper.link_to_document(document, :title_tsim)).to have_selector("a", text: '654321', count: 1)
|
211
211
|
end
|
212
212
|
|
@@ -215,7 +215,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
215
215
|
end
|
216
216
|
|
217
217
|
it "accepts and returns a Proc" do
|
218
|
-
|
218
|
+
allow(Deprecation).to receive(:warn)
|
219
219
|
expect(helper.link_to_document(document, proc { |doc, _opts| doc[:id] + ": " + doc.first(:title_tsim) })).to have_selector("a", text: '123456: 654321', count: 1)
|
220
220
|
end
|
221
221
|
|
@@ -223,12 +223,12 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
223
223
|
let(:data) { { 'id' => id } }
|
224
224
|
|
225
225
|
it "returns id" do
|
226
|
-
|
226
|
+
allow(Deprecation).to receive(:warn)
|
227
227
|
expect(helper.link_to_document(document, :title_tsim)).to have_selector("a", text: '123456', count: 1)
|
228
228
|
end
|
229
229
|
|
230
230
|
it "is html safe" do
|
231
|
-
|
231
|
+
allow(Deprecation).to receive(:warn)
|
232
232
|
expect(helper.link_to_document(document, :title_tsim)).to be_html_safe
|
233
233
|
end
|
234
234
|
|
@@ -250,7 +250,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
|
|
250
250
|
end
|
251
251
|
|
252
252
|
it "converts the counter parameter into a data- attribute" do
|
253
|
-
|
253
|
+
allow(Deprecation).to receive(:warn)
|
254
254
|
expect(helper.link_to_document(document, :title_tsim, counter: 5)).to include 'data-context-href="tracking url"'
|
255
255
|
expect(helper.main_app).to have_received(:track_test_path).with(hash_including(id: have_attributes(id: '123456'), counter: 5))
|
256
256
|
end
|
@@ -46,6 +46,15 @@ RSpec.describe CatalogHelper do
|
|
46
46
|
expect(html).to be_blank
|
47
47
|
end
|
48
48
|
|
49
|
+
context "when response.entry_name is nil" do
|
50
|
+
it "does not raise an error" do
|
51
|
+
collection = mock_response total: 10
|
52
|
+
allow(collection).to receive(:entry_name).and_return(nil)
|
53
|
+
|
54
|
+
expect { page_entries_info(collection) }.not_to raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
49
58
|
describe "with a single result" do
|
50
59
|
it "uses the provided entry name" do
|
51
60
|
response = mock_response total: 1
|
@@ -87,16 +87,38 @@ RSpec.describe "Blacklight::Configuration", api: true do
|
|
87
87
|
let(:image) { SolrDocument.new(format: 'Image') }
|
88
88
|
let(:sound) { SolrDocument.new(format: 'Sound') }
|
89
89
|
|
90
|
+
context 'with deprecated behavior' do
|
91
|
+
before do
|
92
|
+
allow(Deprecation).to receive(:warn)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'accepts documents as an argument to index_fields_for' do
|
96
|
+
config.for_display_type "Image" do |c|
|
97
|
+
c.add_index_field :dimensions
|
98
|
+
end
|
99
|
+
config.add_index_field :title
|
100
|
+
expect(config.index_fields_for(image)).to have_key 'dimensions'
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'accepts documents as an argument to show_fields_for' do
|
104
|
+
config.for_display_type "Image" do |c|
|
105
|
+
c.add_show_field :dimensions
|
106
|
+
end
|
107
|
+
config.add_show_field :title
|
108
|
+
expect(config.show_fields_for(image)).to have_key 'dimensions'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
90
112
|
it "adds index fields just for a certain type" do
|
91
113
|
config.for_display_type "Image" do |c|
|
92
114
|
c.add_index_field :dimensions
|
93
115
|
end
|
94
116
|
config.add_index_field :title
|
95
117
|
|
96
|
-
expect(config.index_fields_for(
|
97
|
-
expect(config.index_fields_for(
|
98
|
-
expect(config.index_fields_for(
|
99
|
-
expect(config.index_fields_for(
|
118
|
+
expect(config.index_fields_for('Image')).to have_key 'dimensions'
|
119
|
+
expect(config.index_fields_for('Image')).to have_key 'title'
|
120
|
+
expect(config.index_fields_for('Sound')).not_to have_key 'dimensions'
|
121
|
+
expect(config.index_fields_for('Image')).to have_key 'title'
|
100
122
|
expect(config.index_fields).not_to have_key 'dimensions'
|
101
123
|
end
|
102
124
|
|
@@ -106,10 +128,10 @@ RSpec.describe "Blacklight::Configuration", api: true do
|
|
106
128
|
end
|
107
129
|
config.add_show_field :title
|
108
130
|
|
109
|
-
expect(config.show_fields_for(
|
110
|
-
expect(config.show_fields_for(
|
111
|
-
expect(config.show_fields_for(
|
112
|
-
expect(config.show_fields_for(
|
131
|
+
expect(config.show_fields_for('Image')).to have_key 'dimensions'
|
132
|
+
expect(config.show_fields_for('Image')).to have_key 'title'
|
133
|
+
expect(config.show_fields_for('Sound')).not_to have_key 'dimensions'
|
134
|
+
expect(config.show_fields_for('Image')).to have_key 'title'
|
113
135
|
expect(config.show_fields).not_to have_key 'dimensions'
|
114
136
|
end
|
115
137
|
|
@@ -121,8 +143,8 @@ RSpec.describe "Blacklight::Configuration", api: true do
|
|
121
143
|
c.add_show_field :photographer
|
122
144
|
end
|
123
145
|
|
124
|
-
expect(config.show_fields_for(
|
125
|
-
expect(config.show_fields_for(
|
146
|
+
expect(config.show_fields_for('Image')).to have_key 'dimensions'
|
147
|
+
expect(config.show_fields_for('Image')).to have_key 'photographer'
|
126
148
|
end
|
127
149
|
end
|
128
150
|
|
@@ -1,14 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Blacklight::DocumentPresenter do
|
4
|
-
let(:presenter) { described_class.new }
|
4
|
+
let(:presenter) { described_class.new(doc, view_context) }
|
5
5
|
let(:doc) { instance_double(SolrDocument) }
|
6
|
-
let(:
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(presenter).to receive(:document).and_return(doc)
|
10
|
-
allow(presenter).to receive(:view_context).and_return(view_context)
|
11
|
-
end
|
6
|
+
let(:blacklight_config) { instance_double(Blacklight::Configuration) }
|
7
|
+
let(:view_context) { double('View context', should_render_field?: true, blacklight_config: blacklight_config) }
|
12
8
|
|
13
9
|
describe '#fields_to_render' do
|
14
10
|
subject { presenter.fields_to_render }
|
@@ -38,7 +34,7 @@ RSpec.describe Blacklight::DocumentPresenter do
|
|
38
34
|
it { is_expected.to be true }
|
39
35
|
|
40
36
|
context 'when the view context says not to render the field' do
|
41
|
-
let(:view_context) { double('View context', should_render_field?: false) }
|
37
|
+
let(:view_context) { double('View context', should_render_field?: false, blacklight_config: blacklight_config) }
|
42
38
|
|
43
39
|
before do
|
44
40
|
allow(field_config).to receive_messages(if: false)
|
@@ -52,10 +48,10 @@ RSpec.describe Blacklight::DocumentPresenter do
|
|
52
48
|
subject { presenter.send(:has_value?, field_config) }
|
53
49
|
|
54
50
|
context 'when the document has the field value' do
|
55
|
-
let(:field_config) { double(field: 'asdf') }
|
51
|
+
let(:field_config) { double(field: 'asdf', highlight: false, accessor: nil, default: nil, values: nil) }
|
56
52
|
|
57
53
|
before do
|
58
|
-
allow(doc).to receive(:
|
54
|
+
allow(doc).to receive(:fetch).with('asdf', nil).and_return(['value'])
|
59
55
|
end
|
60
56
|
|
61
57
|
it { is_expected.to be true }
|
@@ -66,18 +62,17 @@ RSpec.describe Blacklight::DocumentPresenter do
|
|
66
62
|
|
67
63
|
before do
|
68
64
|
allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(true)
|
69
|
-
allow(doc).to receive(:
|
65
|
+
allow(doc).to receive(:highlight_field).with('asdf').and_return(['value'])
|
70
66
|
end
|
71
67
|
|
72
68
|
it { is_expected.to be true }
|
73
69
|
end
|
74
70
|
|
75
71
|
context 'when the field is a model accessor' do
|
76
|
-
let(:field_config) { double(field: 'asdf', highlight:
|
72
|
+
let(:field_config) { double(field: 'asdf', highlight: false, accessor: true) }
|
77
73
|
|
78
74
|
before do
|
79
|
-
allow(doc).to receive(:
|
80
|
-
allow(doc).to receive(:has?).with('asdf').and_return(true)
|
75
|
+
allow(doc).to receive(:send).with('asdf').and_return(['value'])
|
81
76
|
end
|
82
77
|
|
83
78
|
it { is_expected.to be true }
|
@@ -122,6 +122,7 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
|
|
122
122
|
config.add_show_field 'solr_doc_accessor', accessor: true
|
123
123
|
config.add_show_field 'explicit_accessor', accessor: :solr_doc_accessor
|
124
124
|
config.add_show_field 'explicit_array_accessor', accessor: [:solr_doc_accessor, :some_method]
|
125
|
+
config.add_show_field 'explicit_values', values: ->(_config, _doc) { ['some-value'] }
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
@@ -248,6 +249,14 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
|
|
248
249
|
expect(subject).to eq '123'
|
249
250
|
end
|
250
251
|
end
|
252
|
+
|
253
|
+
context 'when the values lambda is provided' do
|
254
|
+
let(:field_name) { 'explicit_values' }
|
255
|
+
|
256
|
+
it 'calls the accessors on the return of the preceeding' do
|
257
|
+
expect(subject).to eq 'some-value'
|
258
|
+
end
|
259
|
+
end
|
251
260
|
end
|
252
261
|
|
253
262
|
describe '#fields' do
|
@@ -271,17 +280,21 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
|
|
271
280
|
it "returns the value of the field" do
|
272
281
|
config.show.title_field = :x
|
273
282
|
allow(document).to receive(:has?).with(:x).and_return(true)
|
274
|
-
allow(document).to receive(:
|
283
|
+
allow(document).to receive(:fetch).with(:x, nil).and_return("value")
|
275
284
|
expect(subject.heading).to eq "value"
|
276
285
|
end
|
277
286
|
|
278
287
|
it "returns the first present value" do
|
279
288
|
config.show.title_field = [:x, :y]
|
280
|
-
allow(document).to receive(:
|
281
|
-
allow(document).to receive(:
|
282
|
-
allow(document).to receive(:[]).with(:y).and_return("value")
|
289
|
+
allow(document).to receive(:fetch).with(:x, nil).and_return(nil)
|
290
|
+
allow(document).to receive(:fetch).with(:y, nil).and_return("value")
|
283
291
|
expect(subject.heading).to eq "value"
|
284
292
|
end
|
293
|
+
|
294
|
+
it "can use explicit field configuration" do
|
295
|
+
config.show.title_field = Blacklight::Configuration::Field.new(field: 'x', values: ->(*_) { 'hardcoded' })
|
296
|
+
expect(subject.heading).to eq 'hardcoded'
|
297
|
+
end
|
285
298
|
end
|
286
299
|
|
287
300
|
describe "#html_title" do
|
@@ -299,11 +312,15 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
|
|
299
312
|
|
300
313
|
it "returns the first present value" do
|
301
314
|
config.show.html_title_field = [:x, :y]
|
302
|
-
allow(document).to receive(:
|
303
|
-
allow(document).to receive(:has?).with(:y).and_return(true)
|
315
|
+
allow(document).to receive(:fetch).with(:x, nil).and_return(nil)
|
304
316
|
allow(document).to receive(:fetch).with(:y, nil).and_return("value")
|
305
317
|
expect(subject.html_title).to eq "value"
|
306
318
|
end
|
319
|
+
|
320
|
+
it "can use explicit field configuration" do
|
321
|
+
config.show.html_title_field = Blacklight::Configuration::Field.new(field: 'x', values: ->(*_) { 'hardcoded' })
|
322
|
+
expect(subject.html_title).to eq 'hardcoded'
|
323
|
+
end
|
307
324
|
end
|
308
325
|
|
309
326
|
describe '#field_values' do
|
@@ -105,14 +105,13 @@ RSpec.describe Blacklight::ThumbnailPresenter do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "creates an image tag from the given field" do
|
108
|
-
allow(document).to receive(:
|
108
|
+
allow(document).to receive(:fetch).with(:xyz, nil).and_return("http://example.com/some.jpg")
|
109
109
|
allow(view_context).to receive(:image_tag).with("http://example.com/some.jpg", {}).and_return('<img src="image.jpg">')
|
110
110
|
expect(view_context).to receive(:link_to_document).with(document, '<img src="image.jpg">', {})
|
111
111
|
subject
|
112
112
|
end
|
113
113
|
|
114
114
|
it "returns nil if no thumbnail is in the document" do
|
115
|
-
allow(document).to receive(:first).with(:xyz).and_return(nil)
|
116
115
|
expect(subject).to be_nil
|
117
116
|
end
|
118
117
|
end
|
@@ -27,14 +27,15 @@ RSpec.describe "catalog/facet_layout" do
|
|
27
27
|
|
28
28
|
it "is collapsable" do
|
29
29
|
render partial: 'catalog/facet_layout', locals: { facet_field: facet_field }
|
30
|
-
expect(rendered).to have_selector 'button
|
30
|
+
expect(rendered).to have_selector 'button[data-toggle="collapse"][aria-expanded="false"]'
|
31
31
|
expect(rendered).to have_selector '.collapse .card-body'
|
32
32
|
end
|
33
33
|
|
34
34
|
it "is configured to be open by default" do
|
35
35
|
allow(facet_field).to receive_messages(collapse: false)
|
36
36
|
render partial: 'catalog/facet_layout', locals: { facet_field: facet_field }
|
37
|
+
expect(rendered).to have_selector 'button[data-toggle="collapse"][aria-expanded="true"]'
|
37
38
|
expect(rendered).not_to have_selector '.card-header.collapsed'
|
38
|
-
expect(rendered).to have_selector '.show .card-body'
|
39
|
+
expect(rendered).to have_selector '.collapse.show .card-body'
|
39
40
|
end
|
40
41
|
end
|
@@ -23,7 +23,7 @@ RSpec.describe "catalog/index.html.erb" do
|
|
23
23
|
stub_template "catalog/_search_header.html.erb" => "header_content"
|
24
24
|
allow(view).to receive(:blacklight_config).and_return(Blacklight::Configuration.new)
|
25
25
|
allow(view).to receive(:render_opensearch_response_metadata).and_return("")
|
26
|
-
|
26
|
+
@response = instance_double(Blacklight::Solr::Response, empty?: true, total: 11, start: 1, limit_value: 10)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "renders the search_header partial" 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.4.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: 2019-
|
20
|
+
date: 2019-11-08 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|
@@ -503,6 +503,7 @@ files:
|
|
503
503
|
- app/views/shared/_user_util_links.html.erb
|
504
504
|
- blacklight.gemspec
|
505
505
|
- config/i18n-tasks.yml
|
506
|
+
- config/locales/blacklight.ar.yml
|
506
507
|
- config/locales/blacklight.de.yml
|
507
508
|
- config/locales/blacklight.en.yml
|
508
509
|
- config/locales/blacklight.es.yml
|