blacklight 7.5.1 → 7.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +23 -34
  3. data/.travis.yml +3 -3
  4. data/VERSION +1 -1
  5. data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -2
  6. data/app/helpers/blacklight/catalog_helper_behavior.rb +0 -2
  7. data/app/presenters/blacklight/document_presenter.rb +27 -36
  8. data/app/presenters/blacklight/field_presenter.rb +31 -6
  9. data/app/presenters/blacklight/index_presenter.rb +2 -2
  10. data/app/presenters/blacklight/show_presenter.rb +3 -3
  11. data/app/views/catalog/_constraints.html.erb +1 -1
  12. data/app/views/catalog/_facet_pagination.html.erb +2 -2
  13. data/app/views/catalog/_field.json.jbuilder +2 -2
  14. data/app/views/catalog/_index.html.erb +3 -3
  15. data/app/views/catalog/_search_form.html.erb +1 -1
  16. data/app/views/catalog/_show.html.erb +3 -3
  17. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  18. data/app/views/catalog/_start_over.html.erb +1 -0
  19. data/app/views/catalog/_thumbnail.html.erb +1 -1
  20. data/app/views/catalog/index.json.jbuilder +2 -1
  21. data/app/views/catalog/show.html.erb +1 -1
  22. data/app/views/catalog/show.json.jbuilder +2 -1
  23. data/app/views/layouts/blacklight/base.html.erb +2 -2
  24. data/config/locales/blacklight.ar.yml +2 -0
  25. data/config/locales/blacklight.de.yml +2 -0
  26. data/config/locales/blacklight.en.yml +2 -0
  27. data/config/locales/blacklight.es.yml +2 -0
  28. data/config/locales/blacklight.fr.yml +2 -0
  29. data/config/locales/blacklight.hu.yml +2 -0
  30. data/config/locales/blacklight.it.yml +2 -0
  31. data/config/locales/blacklight.nl.yml +2 -0
  32. data/config/locales/blacklight.pt-BR.yml +2 -0
  33. data/config/locales/blacklight.sq.yml +2 -0
  34. data/config/locales/blacklight.zh.yml +2 -0
  35. data/lib/blacklight/configuration/field.rb +5 -4
  36. data/spec/helpers/blacklight_helper_spec.rb +17 -0
  37. data/spec/helpers/catalog_helper_spec.rb +0 -7
  38. data/spec/presenters/blacklight/document_presenter_spec.rb +22 -62
  39. data/spec/presenters/blacklight/field_presenter_spec.rb +268 -0
  40. data/spec/presenters/blacklight/index_presenter_spec.rb +0 -142
  41. data/spec/presenters/blacklight/show_presenter_spec.rb +0 -177
  42. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b85d437eb826605fb701c8c18e4263528b67f4c881a43288e46b8f46ad48881b
4
- data.tar.gz: daa54afe4a032f8ab13348850decaa8340dca486f993b3b508943e00103225c4
3
+ metadata.gz: '087bb21bf2c345072d1fade572f09741ab819c5f44e8b563c6818530c1da6da8'
4
+ data.tar.gz: eebaefbf5c6ec5b3f245ef17ce59c006ac09ffefb047f336aa185cace7bd293e
5
5
  SHA512:
6
- metadata.gz: caab714113f5900e604ee045cbea1c28410d4c099ef340a4bc2c97f1f36806861eea82ab5d5b85cbe4f686dc796282fe678d1886f2d090d44825797a1da759be
7
- data.tar.gz: 7446370ad47268865a69220be2b5c43120781666500c9bd97dff7e368718faad227a02ac542a6441a53c99f6f9f72242cc142918431af9e1b6e480eaa5f6e943
6
+ metadata.gz: edce2eb3d01ea8ea635515c70db1b9e584ea96d4a360378897bc8340a94919f9ffa6f7be6824aa644c07929b3623f0f90f14280eef71b180f0d2022da8f0f677
7
+ data.tar.gz: ac8cc8d0432746cc80b01d330cc6bad45fc54ac4a2386a11c7c54285a1202ced0cd5b0f51f603e0281c4e33520565514ffadc8f549fa66ca0fb45533afe8c774
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-09-11 10:59:32 -0500 using RuboCop version 0.63.1.
3
+ # on 2020-02-03 11:07:48 -0800 using RuboCop version 0.63.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -36,17 +36,16 @@ Layout/ClosingParenthesisIndentation:
36
36
  Exclude:
37
37
  - 'app/views/catalog/index.atom.builder'
38
38
 
39
- # Offense count: 108
39
+ # Offense count: 109
40
40
  # Cop supports --auto-correct.
41
41
  Layout/EmptyLineAfterMagicComment:
42
42
  Enabled: false
43
43
 
44
- # Offense count: 8
44
+ # Offense count: 7
45
45
  # Cop supports --auto-correct.
46
46
  # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
47
47
  Layout/ExtraSpacing:
48
48
  Exclude:
49
- - 'app/helpers/blacklight/catalog_helper_behavior.rb'
50
49
  - 'app/models/concerns/blacklight/document/dublin_core.rb'
51
50
  - 'app/models/record_mailer.rb'
52
51
  - 'app/views/catalog/index.atom.builder'
@@ -126,13 +125,6 @@ Layout/SpaceInsideParens:
126
125
  - 'app/views/catalog/_document.rss.builder'
127
126
  - 'app/views/catalog/index.atom.builder'
128
127
 
129
- # Offense count: 1
130
- # Cop supports --auto-correct.
131
- # Configuration parameters: AllowInHeredoc.
132
- Layout/TrailingWhitespace:
133
- Exclude:
134
- - 'app/views/catalog/_document.rss.builder'
135
-
136
128
  # Offense count: 1
137
129
  Lint/AmbiguousBlockAssociation:
138
130
  Exclude:
@@ -185,7 +177,7 @@ Lint/UselessComparison:
185
177
  Exclude:
186
178
  - 'spec/models/blacklight/document/active_model_shim_spec.rb'
187
179
 
188
- # Offense count: 58
180
+ # Offense count: 59
189
181
  Metrics/AbcSize:
190
182
  Max: 49
191
183
 
@@ -207,26 +199,26 @@ Metrics/ClassLength:
207
199
 
208
200
  # Offense count: 19
209
201
  Metrics/CyclomaticComplexity:
210
- Max: 12
202
+ Max: 11
211
203
 
212
- # Offense count: 48
204
+ # Offense count: 54
213
205
  # Configuration parameters: CountComments, ExcludedMethods.
214
206
  Metrics/MethodLength:
215
- Max: 35
207
+ Max: 31
216
208
 
217
209
  # Offense count: 8
218
210
  # Configuration parameters: CountComments.
219
211
  Metrics/ModuleLength:
220
212
  Max: 212
221
213
 
222
- # Offense count: 1
214
+ # Offense count: 2
223
215
  # Configuration parameters: CountKeywordArgs.
224
216
  Metrics/ParameterLists:
225
217
  Max: 6
226
218
 
227
219
  # Offense count: 16
228
220
  Metrics/PerceivedComplexity:
229
- Max: 14
221
+ Max: 13
230
222
 
231
223
  # Offense count: 4
232
224
  # Configuration parameters: EnforcedStyleForLeadingUnderscores.
@@ -253,12 +245,11 @@ Naming/UncommunicativeMethodParamName:
253
245
  - 'spec/features/search_context_spec.rb'
254
246
  - 'spec/features/search_results_spec.rb'
255
247
 
256
- # Offense count: 16
248
+ # Offense count: 14
257
249
  # Configuration parameters: EnforcedStyle.
258
250
  # SupportedStyles: snake_case, normalcase, non_integer
259
251
  Naming/VariableNumber:
260
252
  Exclude:
261
- - 'spec/views/catalog/_facets.html.erb_spec.rb'
262
253
  - 'spec/views/catalog/_index.html.erb_spec.rb'
263
254
  - 'spec/views/catalog/_show.html.erb_spec.rb'
264
255
 
@@ -290,13 +281,13 @@ RSpec/BeforeAfterAll:
290
281
  - 'spec/models/blacklight/document/sms_spec.rb'
291
282
  - 'spec/models/blacklight/solr/document_spec.rb'
292
283
 
293
- # Offense count: 71
284
+ # Offense count: 77
294
285
  # Configuration parameters: Prefixes.
295
286
  # Prefixes: when, with, without
296
287
  RSpec/ContextWording:
297
288
  Enabled: false
298
289
 
299
- # Offense count: 54
290
+ # Offense count: 55
300
291
  RSpec/DescribeClass:
301
292
  Enabled: false
302
293
 
@@ -306,7 +297,7 @@ RSpec/EmptyExampleGroup:
306
297
  Exclude:
307
298
  - 'spec/models/blacklight/solr/search_builder_spec.rb'
308
299
 
309
- # Offense count: 127
300
+ # Offense count: 129
310
301
  # Configuration parameters: Max.
311
302
  RSpec/ExampleLength:
312
303
  Enabled: false
@@ -330,7 +321,7 @@ RSpec/FilePath:
330
321
  - 'spec/presenters/pipeline_spec.rb'
331
322
  - 'spec/presenters/thumbnail_presenter_spec.rb'
332
323
 
333
- # Offense count: 196
324
+ # Offense count: 192
334
325
  # Configuration parameters: AssignmentOnly.
335
326
  RSpec/InstanceVariable:
336
327
  Enabled: false
@@ -358,10 +349,10 @@ RSpec/LeakyConstantDeclaration:
358
349
  RSpec/MessageChain:
359
350
  Exclude:
360
351
  - 'spec/controllers/bookmarks_controller_spec.rb'
361
- - 'spec/presenters/blacklight/show_presenter_spec.rb'
352
+ - 'spec/presenters/blacklight/field_presenter_spec.rb'
362
353
  - 'spec/views/shared/_user_util_links.html.erb_spec.rb'
363
354
 
364
- # Offense count: 67
355
+ # Offense count: 61
365
356
  # Configuration parameters: EnforcedStyle.
366
357
  # SupportedStyles: have_received, receive
367
358
  RSpec/MessageSpies:
@@ -377,16 +368,15 @@ RSpec/MessageSpies:
377
368
  - 'spec/lib/blacklight/configuration/facet_field_spec.rb'
378
369
  - 'spec/models/blacklight/search_builder_spec.rb'
379
370
  - 'spec/models/blacklight/suggest_search_spec.rb'
380
- - 'spec/presenters/blacklight/index_presenter_spec.rb'
381
- - 'spec/presenters/blacklight/show_presenter_spec.rb'
371
+ - 'spec/presenters/blacklight/field_presenter_spec.rb'
382
372
  - 'spec/presenters/thumbnail_presenter_spec.rb'
383
373
 
384
- # Offense count: 346
374
+ # Offense count: 340
385
375
  # Configuration parameters: AggregateFailuresByDefault.
386
376
  RSpec/MultipleExpectations:
387
377
  Max: 16
388
378
 
389
- # Offense count: 332
379
+ # Offense count: 337
390
380
  # Configuration parameters: IgnoreSharedExamples.
391
381
  RSpec/NamedSubject:
392
382
  Enabled: false
@@ -403,10 +393,9 @@ RSpec/RepeatedDescription:
403
393
  - 'spec/helpers/catalog_helper_spec.rb'
404
394
  - 'spec/models/blacklight/solr/search_builder_spec.rb'
405
395
 
406
- # Offense count: 4
396
+ # Offense count: 2
407
397
  RSpec/RepeatedExample:
408
398
  Exclude:
409
- - 'spec/features/search_filters_spec.rb'
410
399
  - 'spec/models/blacklight/solr/document_spec.rb'
411
400
 
412
401
  # Offense count: 4
@@ -423,7 +412,7 @@ RSpec/SubjectStub:
423
412
  - 'spec/models/blacklight/search_builder_spec.rb'
424
413
  - 'spec/services/blacklight/search_service_spec.rb'
425
414
 
426
- # Offense count: 119
415
+ # Offense count: 120
427
416
  # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
428
417
  RSpec/VerifiedDoubles:
429
418
  Enabled: false
@@ -548,12 +537,12 @@ Style/GuardClause:
548
537
  - 'app/helpers/blacklight/catalog_helper_behavior.rb'
549
538
  - 'lib/blacklight/solr/search_builder_behavior.rb'
550
539
 
551
- # Offense count: 40
540
+ # Offense count: 39
552
541
  # Cop supports --auto-correct.
553
542
  Style/IfUnlessModifier:
554
543
  Enabled: false
555
544
 
556
- # Offense count: 124
545
+ # Offense count: 122
557
546
  # Cop supports --auto-correct.
558
547
  # Configuration parameters: EnforcedStyle.
559
548
  # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
@@ -11,11 +11,11 @@ matrix:
11
11
  - rvm: 2.7.0
12
12
  env: "RAILS_VERSION=6.0.2.1"
13
13
  - rvm: 2.6.5
14
- env: "RAILS_VERSION=6.0.0 ENGINE_CART_RAILS_OPTIONS=\"--skip-webpack-install\""
14
+ env: "RAILS_VERSION=6.0.2.1 ENGINE_CART_RAILS_OPTIONS=\"--skip-webpack-install\""
15
15
  - rvm: 2.6.5
16
- env: "RAILS_VERSION=5.2.3"
16
+ env: "RAILS_VERSION=5.2.4.1"
17
17
  - rvm: 2.5.7
18
- env: "RAILS_VERSION=5.2.3 BLACKLIGHT_API_TEST=true ENGINE_CART_RAILS_OPTIONS=\"--api --skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-action-cable --skip-coffee --skip-test\""
18
+ env: "RAILS_VERSION=5.2.4.1 BLACKLIGHT_API_TEST=true ENGINE_CART_RAILS_OPTIONS=\"--api --skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-action-cable --skip-coffee --skip-test\""
19
19
  - rvm: 2.4.9
20
20
  env: "RAILS_VERSION=5.2.4.1"
21
21
  - rvm: jruby-9.2.8.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.5.1
1
+ 7.6.0
@@ -148,7 +148,8 @@ module Blacklight::BlacklightHelperBehavior
148
148
  document = args.first
149
149
 
150
150
  field = options[:field]
151
- html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: index_field_label(document, field))
151
+ label = options[:label] || index_field_label(document, field)
152
+ html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: label)
152
153
  end
153
154
 
154
155
  ##
@@ -169,8 +170,9 @@ module Blacklight::BlacklightHelperBehavior
169
170
  document = args.first
170
171
 
171
172
  field = options[:field]
173
+ label = options[:label] || document_show_field_label(document, field)
172
174
 
173
- t(:'blacklight.search.show.label', label: document_show_field_label(document, field))
175
+ t(:'blacklight.search.show.label', label: label)
174
176
  end
175
177
 
176
178
  ##
@@ -40,8 +40,6 @@ module Blacklight::CatalogHelperBehavior
40
40
  # @param [RSolr::Resource] collection (or other Kaminari-compatible objects)
41
41
  # @return [String]
42
42
  def page_entries_info(collection, entry_name: nil)
43
- return unless show_pagination? collection
44
-
45
43
  entry_name = if entry_name
46
44
  entry_name.pluralize(collection.size, I18n.locale)
47
45
  else
@@ -19,10 +19,14 @@ module Blacklight
19
19
 
20
20
  # @return [Hash<String,Configuration::Field>] all the fields for this index view that should be rendered
21
21
  def fields_to_render
22
- fields.select do |_name, field_config|
23
- # rubocop:disable Style/PreferredHashMethods
24
- render_field?(field_config) && has_value?(field_config)
25
- # rubocop:enable Style/PreferredHashMethods
22
+ return to_enum(:fields_to_render) unless block_given?
23
+
24
+ fields.each do |name, field_config|
25
+ field_presenter = field_presenter(field_config)
26
+
27
+ next unless field_presenter.render_field? && field_presenter.any?
28
+
29
+ yield name, field_config, field_presenter
26
30
  end
27
31
  end
28
32
 
@@ -32,11 +36,11 @@ module Blacklight
32
36
  #
33
37
  # @return [String]
34
38
  def heading
35
- return field_values(view_config.title_field) if view_config.title_field.is_a? Blacklight::Configuration::Field
39
+ return field_value(view_config.title_field) if view_config.title_field.is_a? Blacklight::Configuration::Field
36
40
 
37
41
  fields = Array.wrap(view_config.title_field) + [configuration.document_model.unique_key]
38
- f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| retrieve_values(field_config).any? }
39
- field_values(f, except_operations: [Rendering::HelperMethod])
42
+ f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| field_presenter(field_config).any? }
43
+ field_value(f, except_operations: [Rendering::HelperMethod])
40
44
  end
41
45
 
42
46
  def display_type(base_name = nil, default: nil)
@@ -44,7 +48,7 @@ module Blacklight
44
48
  fields += Array.wrap(view_config[:"#{base_name}_display_type_field"]) if base_name && view_config.key?(:"#{base_name}_display_type_field")
45
49
  fields += Array.wrap(view_config.display_type_field)
46
50
 
47
- display_type = fields.lazy.map { |field| retrieve_values(field_config(field)) }.detect(&:any?)
51
+ display_type = fields.lazy.map { |field| field_presenter(field_config(field)) }.detect(&:any?)&.values
48
52
  display_type ||= Array(default) if default
49
53
 
50
54
  display_type || []
@@ -55,11 +59,11 @@ module Blacklight
55
59
  #
56
60
  # Allow an extention point where information in the document
57
61
  # may drive the value of the field
58
- # @param [Configuration::Field] field
62
+ # @param [Configuration::Field] field_config
59
63
  # @param [Hash] options
60
64
  # @option options [String] :value
61
- def field_value field, options = {}
62
- field_values(field, options)
65
+ def field_value field_config, options = {}
66
+ field_presenter(field_config, options).render
63
67
  end
64
68
 
65
69
  def thumbnail
@@ -68,41 +72,28 @@ module Blacklight
68
72
 
69
73
  private
70
74
 
71
- ##
72
- # Check to see if the given field should be rendered in this context
73
- # @param [Blacklight::Configuration::Field] field_config
74
- # @return [Boolean]
75
75
  def render_field?(field_config)
76
- view_context.should_render_field?(field_config, document)
76
+ field_presenter(field_config).render_field?
77
77
  end
78
+ deprecation_deprecate render_field?: 'Use FieldPresenter#render_field?'
78
79
 
79
- ##
80
- # Check if a document has (or, might have, in the case of accessor methods) a value for
81
- # the given solr field
82
- # @param [Blacklight::Configuration::Field] field_config
83
- # @return [Boolean]
84
80
  def has_value?(field_config)
85
- retrieve_values(field_config).present?
81
+ field_presenter(field_config).any?
86
82
  end
83
+ deprecation_deprecate has_value?: 'Use FieldPresenter#any?'
87
84
 
88
- ##
89
- # Get the value for a document's field, and prepare to render it.
90
- # - highlight_field
91
- # - accessor
92
- # - solr field
93
- #
94
- # Rendering:
95
- # - helper_method
96
- # - link_to_facet
97
- # @param [Blacklight::Configuration::Field] field_config solr field configuration
98
- # @param [Hash] options additional options to pass to the rendering helpers
99
85
  def field_values(field_config, options = {})
100
- options[:values] ||= retrieve_values(field_config) unless options.key? :value
101
- FieldPresenter.new(view_context, document, field_config, options).render
86
+ field_value(field_config, options)
102
87
  end
88
+ deprecation_deprecate field_values: 'Use #field_value'
103
89
 
104
90
  def retrieve_values(field_config)
105
- FieldRetriever.new(document, field_config).fetch
91
+ field_presenter(field_config).values
92
+ end
93
+ deprecation_deprecate retrieve_values: 'Use FieldPresenter#values'
94
+
95
+ def field_presenter(field_config, options = {})
96
+ FieldPresenter.new(view_context, document, field_config, options)
106
97
  end
107
98
  end
108
99
  end
@@ -3,7 +3,7 @@
3
3
  module Blacklight
4
4
  # Renders a field and handles link_to_facet or helper_method if supplied
5
5
  class FieldPresenter
6
- # @param controller [Object] the context in which to execute helper methods
6
+ # @param view_context [Object] the context in which to execute helper methods
7
7
  # @param document [SolrDocument] the document
8
8
  # @param field_config [Blacklight::Configuration::Field] the field's configuration
9
9
  # @param options [Hash]
@@ -11,8 +11,8 @@ module Blacklight
11
11
  # @option options [Array] :except_operations
12
12
  # @option options [Object] :value
13
13
  # @option options [Array] :steps
14
- def initialize(controller, document, field_config, options = {})
15
- @controller = controller
14
+ def initialize(view_context, document, field_config, options = {})
15
+ @view_context = view_context
16
16
  @document = document
17
17
  @field_config = field_config
18
18
  @options = options
@@ -28,10 +28,35 @@ module Blacklight
28
28
  @except_operations += [Rendering::HelperMethod] if options.key? :value
29
29
  end
30
30
 
31
- attr_reader :controller, :document, :field_config, :values, :except_operations, :options
31
+ attr_reader :view_context, :document, :field_config, :except_operations, :options
32
32
 
33
33
  def render
34
- Rendering::Pipeline.new(values || retrieve_values, field_config, document, controller, pipeline_steps, options).render
34
+ Rendering::Pipeline.new(values, field_config, document, view_context, pipeline_steps, options).render
35
+ end
36
+
37
+ def values
38
+ @values ||= retrieve_values
39
+ end
40
+
41
+ def label(context = 'index', **options)
42
+ field_config.display_label(context, count: retrieve_values.count, **options)
43
+ end
44
+
45
+ ##
46
+ # Check to see if the given field should be rendered in this context
47
+ # @param [Blacklight::Configuration::Field] field_config
48
+ # @return [Boolean]
49
+ def render_field?
50
+ view_context.should_render_field?(field_config, document)
51
+ end
52
+
53
+ ##
54
+ # Check if a document has (or, might have, in the case of accessor methods) a value for
55
+ # the given solr field
56
+ # @param [Blacklight::Configuration::Field] field_config
57
+ # @return [Boolean]
58
+ def any?
59
+ values.present?
35
60
  end
36
61
 
37
62
  private
@@ -40,7 +65,7 @@ module Blacklight
40
65
  (options[:steps] || Rendering::Pipeline.operations) - except_operations
41
66
  end
42
67
 
43
- def retrieve_values(field_config)
68
+ def retrieve_values
44
69
  FieldRetriever.new(document, field_config).fetch
45
70
  end
46
71
  end
@@ -12,7 +12,7 @@ module Blacklight
12
12
  value = case field_or_string_or_proc
13
13
  when Symbol
14
14
  config = field_config(field_or_string_or_proc)
15
- retrieve_values(config)
15
+ field_presenter(config).values
16
16
  when Proc
17
17
  Deprecation.warn(self, "calling IndexPresenter.label with a Proc is deprecated. " \
18
18
  "First argument must be a symbol. This will be removed in Blacklight 8")
@@ -24,7 +24,7 @@ module Blacklight
24
24
  end
25
25
 
26
26
  value = document.id if value.blank?
27
- field_values(config, values: Array.wrap(value), except_operations: [Rendering::HelperMethod])
27
+ field_value(config, values: Array.wrap(value), except_operations: [Rendering::HelperMethod])
28
28
  end
29
29
 
30
30
  deprecation_deprecate label: 'Use #heading'