blacklight 6.5.0 → 6.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +5 -0
  4. data/.rubocop_todo.yml +114 -213
  5. data/{.solr_wrapper → .solr_wrapper.yml} +0 -0
  6. data/.yardopts +3 -1
  7. data/Gemfile +0 -3
  8. data/Rakefile +1 -1
  9. data/VERSION +1 -1
  10. data/Vagrantfile +0 -2
  11. data/app/controllers/bookmarks_controller.rb +0 -2
  12. data/app/controllers/catalog_controller.rb +0 -2
  13. data/app/controllers/concerns/blacklight/base.rb +0 -1
  14. data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
  15. data/app/controllers/concerns/blacklight/catalog.rb +7 -11
  16. data/app/controllers/concerns/blacklight/controller.rb +11 -7
  17. data/app/controllers/concerns/blacklight/default_component_configuration.rb +24 -37
  18. data/app/controllers/concerns/blacklight/facet.rb +2 -11
  19. data/app/controllers/concerns/blacklight/request_builders.rb +1 -3
  20. data/app/controllers/concerns/blacklight/search_context.rb +0 -1
  21. data/app/controllers/concerns/blacklight/search_fields.rb +2 -2
  22. data/app/controllers/concerns/blacklight/search_helper.rb +14 -24
  23. data/app/controllers/concerns/blacklight/token_based_user.rb +0 -2
  24. data/app/helpers/blacklight/blacklight_helper_behavior.rb +27 -28
  25. data/app/helpers/blacklight/catalog_helper_behavior.rb +15 -15
  26. data/app/helpers/blacklight/component_helper_behavior.rb +2 -5
  27. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -3
  28. data/app/helpers/blacklight/deprecated_url_helper_behavior.rb +1 -3
  29. data/app/helpers/blacklight/facets_helper_behavior.rb +21 -25
  30. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +1 -2
  31. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +8 -9
  32. data/app/helpers/blacklight/render_partials_helper.rb +14 -13
  33. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +1 -4
  34. data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
  35. data/app/models/blacklight/facet_paginator.rb +2 -2
  36. data/app/models/concerns/blacklight/document.rb +1 -6
  37. data/app/models/concerns/blacklight/document/active_model_shim.rb +0 -1
  38. data/app/models/concerns/blacklight/document/cache_key.rb +3 -3
  39. data/app/models/concerns/blacklight/document/dublin_core.rb +0 -1
  40. data/app/models/concerns/blacklight/document/email.rb +0 -2
  41. data/app/models/concerns/blacklight/document/export.rb +1 -2
  42. data/app/models/concerns/blacklight/document/schema_org.rb +0 -2
  43. data/app/models/concerns/blacklight/document/sms.rb +0 -2
  44. data/app/models/concerns/blacklight/solr/document.rb +0 -1
  45. data/app/models/record_mailer.rb +0 -1
  46. data/app/models/solr_document.rb +0 -2
  47. data/app/presenters/blacklight/document_presenter.rb +14 -11
  48. data/app/presenters/blacklight/index_presenter.rb +5 -5
  49. data/app/presenters/blacklight/json_presenter.rb +0 -1
  50. data/app/presenters/blacklight/rendering/abstract_step.rb +0 -1
  51. data/app/presenters/blacklight/rendering/helper_method.rb +5 -5
  52. data/app/presenters/blacklight/rendering/link_to_facet.rb +1 -1
  53. data/app/presenters/blacklight/show_presenter.rb +4 -5
  54. data/app/services/blacklight/field_retriever.rb +8 -9
  55. data/app/views/catalog/_facet_limit.html.erb +1 -1
  56. data/blacklight.gemspec +4 -0
  57. data/lib/blacklight.rb +2 -2
  58. data/lib/blacklight/abstract_repository.rb +4 -3
  59. data/lib/blacklight/configuration.rb +57 -92
  60. data/lib/blacklight/configuration/context.rb +3 -3
  61. data/lib/blacklight/configuration/fields.rb +24 -7
  62. data/lib/blacklight/exceptions.rb +0 -2
  63. data/lib/blacklight/parameters.rb +1 -1
  64. data/lib/blacklight/search_builder.rb +92 -96
  65. data/lib/blacklight/search_state.rb +2 -1
  66. data/lib/blacklight/solr/repository.rb +3 -4
  67. data/lib/blacklight/solr/request.rb +0 -2
  68. data/lib/blacklight/solr/response/facets.rb +23 -28
  69. data/lib/blacklight/solr/response/group.rb +0 -1
  70. data/lib/blacklight/solr/response/group_response.rb +1 -5
  71. data/lib/blacklight/solr/response/pagination_methods.rb +0 -1
  72. data/lib/blacklight/solr/response/response.rb +1 -1
  73. data/lib/blacklight/solr/response/spelling.rb +0 -4
  74. data/lib/blacklight/solr/search_builder_behavior.rb +29 -41
  75. data/lib/blacklight/utils.rb +10 -7
  76. data/lib/generators/blacklight/assets_generator.rb +0 -1
  77. data/lib/generators/blacklight/document_generator.rb +0 -1
  78. data/lib/generators/blacklight/install_generator.rb +2 -6
  79. data/lib/generators/blacklight/models_generator.rb +0 -3
  80. data/lib/generators/blacklight/search_builder_generator.rb +0 -1
  81. data/lib/generators/blacklight/solr4_generator.rb +0 -2
  82. data/lib/generators/blacklight/solr5_generator.rb +15 -1
  83. data/lib/generators/blacklight/test_support_generator.rb +0 -1
  84. data/lib/railties/blacklight.rake +3 -3
  85. data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +1 -4
  86. data/spec/controllers/blacklight/search_helper_spec.rb +5 -7
  87. data/spec/controllers/blacklight/suggest_search_spec.rb +2 -2
  88. data/spec/controllers/bookmarks_controller_spec.rb +2 -2
  89. data/spec/controllers/catalog_controller_spec.rb +6 -6
  90. data/spec/features/search_context_spec.rb +4 -5
  91. data/spec/features/search_formats_spec.rb +0 -6
  92. data/spec/helpers/blacklight_helper_spec.rb +7 -7
  93. data/spec/helpers/catalog_helper_spec.rb +10 -10
  94. data/spec/helpers/configuration_helper_spec.rb +3 -3
  95. data/spec/helpers/facets_helper_spec.rb +1 -2
  96. data/spec/helpers/render_constraints_helper_spec.rb +8 -0
  97. data/spec/integration/generators/blacklight/solr5_generator_spec.rb +60 -0
  98. data/spec/models/blacklight/document_spec.rb +1 -1
  99. data/spec/models/blacklight/search_builder_spec.rb +5 -4
  100. data/spec/models/blacklight/solr/search_builder_spec.rb +12 -18
  101. data/spec/presenters/pipeline_spec.rb +1 -1
  102. data/spec/spec_helper.rb +43 -0
  103. data/spec/views/catalog/_index_header_default.html.erb_spec.rb +1 -1
  104. data/spec/views/catalog/_show_tools.html.erb_spec.rb +1 -1
  105. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
  106. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +1 -1
  107. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +3 -3
  108. data/spec/views/catalog/index.html.erb_spec.rb +1 -1
  109. data/spec/views/catalog/index.json.jbuilder_spec.rb +2 -2
  110. data/tasks/blacklight.rake +3 -0
  111. metadata +61 -3
@@ -21,4 +21,3 @@ module Blacklight
21
21
  end
22
22
  end
23
23
  end
24
-
@@ -2,8 +2,11 @@ module Blacklight
2
2
  module Rendering
3
3
  class HelperMethod < AbstractStep
4
4
  def render
5
- return next_step(values) unless config.helper_method
6
- return render_helper # short circut the rest of the steps
5
+ if config.helper_method
6
+ render_helper # short circut the rest of the steps
7
+ else
8
+ next_step(values)
9
+ end
7
10
  end
8
11
 
9
12
  private
@@ -18,6 +21,3 @@ module Blacklight
18
21
  end
19
22
  end
20
23
  end
21
-
22
-
23
-
@@ -15,7 +15,7 @@ module Blacklight
15
15
  end
16
16
 
17
17
  def link_field
18
- return config.key if config.link_to_search === true
18
+ return config.key if config.link_to_search == true
19
19
  config.link_to_search
20
20
  end
21
21
 
@@ -7,7 +7,7 @@ module Blacklight
7
7
  attr_reader :document, :configuration, :view_context
8
8
 
9
9
  # @param [SolrDocument] document
10
- # @param [ActionView::Base] view context scope for linking and generating urls
10
+ # @param [ActionView::Base] view_context scope for linking and generating urls
11
11
  # @param [Blacklight::Configuration] configuration
12
12
  def initialize(document, view_context, configuration = view_context.blacklight_config)
13
13
  @document = document
@@ -19,7 +19,7 @@ module Blacklight
19
19
  # Create <link rel="alternate"> links from a documents dynamically
20
20
  # provided export formats. Returns empty string if no links available.
21
21
  #
22
- # @params [Hash] options
22
+ # @param [Hash] options
23
23
  # @option options [Boolean] :unique ensures only one link is output for every
24
24
  # content type, e.g. as required by atom
25
25
  # @option options [Array<String>] :exclude array of format shortnames to not include in the output
@@ -55,7 +55,6 @@ module Blacklight
55
55
  # Get the value of the document's "title" field, or a placeholder
56
56
  # value (if empty)
57
57
  #
58
- # @param [SolrDocument] document
59
58
  # @return [String]
60
59
  def heading
61
60
  fields = Array.wrap(view_config.title_field)
@@ -77,7 +76,7 @@ module Blacklight
77
76
  # may drive the value of the field
78
77
  # @param [String] field
79
78
  # @param [Hash] options
80
- # @options opts [String] :value
79
+ # @option options [String] :value
81
80
  def field_value field, options={}
82
81
  field_values(field_config(field), options)
83
82
  end
@@ -117,7 +116,7 @@ module Blacklight
117
116
  # Rendering:
118
117
  # - helper_method
119
118
  # - link_to_search
120
- # @param [Blacklight::Configuration::Field] solr field configuration
119
+ # @param [Blacklight::Configuration::Field] field_config solr field configuration
121
120
  # @param [Hash] options additional options to pass to the rendering helpers
122
121
  def field_values(field_config, options={})
123
122
  FieldPresenter.new(view_context, document, field_config, options).render
@@ -13,13 +13,12 @@ module Blacklight
13
13
  # @return [Array]
14
14
  def fetch
15
15
  Array.wrap(
16
- case
17
- when field_config.highlight
18
- retrieve_highlight
19
- when field_config.accessor
20
- retieve_using_accessor
21
- when field_config
22
- retrieve_simple
16
+ if field_config.highlight
17
+ retrieve_highlight
18
+ elsif field_config.accessor
19
+ retieve_using_accessor
20
+ elsif field_config
21
+ retrieve_simple
23
22
  end
24
23
  )
25
24
  end
@@ -37,10 +36,10 @@ module Blacklight
37
36
 
38
37
  def retieve_using_accessor
39
38
  # implicit method call
40
- if field_config.accessor === true
39
+ if field_config.accessor == true
41
40
  document.send(field)
42
41
  # arity-1 method call (include the field name in the call)
43
- elsif !field_config.accessor.is_a?(Array) && document.method(field_config.accessor).arity != 0
42
+ elsif !field_config.accessor.is_a?(Array) && document.method(field_config.accessor).arity.nonzero?
44
43
  document.send(field_config.accessor, field)
45
44
  # chained method calls
46
45
  else
@@ -5,7 +5,7 @@
5
5
  <% unless paginator.last_page? || params[:action] == "facet" %>
6
6
  <li class="more_facets_link">
7
7
  <%= link_to t("more_#{field_name}_html", scope: 'blacklight.search.facets', default: :more_html, field_name: facet_field.label),
8
- search_facet_url(id: field_name), class: "more_facets_link" %>
8
+ search_facet_path(id: field_name), class: "more_facets_link" %>
9
9
  </li>
10
10
  <% end %>
11
11
  </ul>
@@ -42,4 +42,8 @@ Gem::Specification.new do |s|
42
42
  s.add_development_dependency "poltergeist"
43
43
  s.add_development_dependency 'engine_cart', '~> 0.10'
44
44
  s.add_development_dependency "equivalent-xml"
45
+ s.add_development_dependency "coveralls"
46
+ s.add_development_dependency "simplecov"
47
+ s.add_development_dependency "rubocop"
48
+ s.add_development_dependency "rubocop-rspec"
45
49
  end
@@ -36,7 +36,7 @@ module Blacklight
36
36
 
37
37
  ##
38
38
  # The configured repository class. By convention, this is
39
- # the class Blacklight::{name of the adapter}::Repository, e.g.
39
+ # the class Blacklight::(name of the adapter)::Repository, e.g.
40
40
  # elastic_search => Blacklight::ElasticSearch::Repository
41
41
  def self.repository_class
42
42
  case connection_config[:adapter]
@@ -92,7 +92,7 @@ module Blacklight
92
92
  raise("#{blacklight_config_file} was found, but was blank or malformed.\n")
93
93
  end
94
94
 
95
- return @blacklight_yml
95
+ @blacklight_yml
96
96
  end
97
97
 
98
98
  def self.logger
@@ -19,20 +19,21 @@ module Blacklight
19
19
 
20
20
  ##
21
21
  # Find a single document result by a known id
22
- # @param [String] document's unique key value
23
- # @param [Hash] additional query parameters
22
+ # @param [String] id document's unique key value
23
+ # @param [Hash] params additional query parameters
24
24
  def find(id, params = {})
25
25
  raise NotImplementedError
26
26
  end
27
27
 
28
28
  ##
29
29
  # Execute a search query against a search index
30
- # @param [Hash] query parameters
30
+ # @param [Hash] params query parameters
31
31
  def search(params = {})
32
32
  raise NotImplementedError
33
33
  end
34
34
 
35
35
  protected
36
+
36
37
  def connection_config
37
38
  blacklight_config.connection_config
38
39
  end
@@ -4,12 +4,10 @@ module Blacklight
4
4
  # Blacklight::Configuration holds the configuration for a Blacklight::Controller, including
5
5
  # fields to display, facets to show, sort options, and search fields.
6
6
  class Configuration < OpenStructWithHashAccess
7
-
8
-
9
7
  # Using required_dependency to work around Rails autoloading
10
8
  # problems when developing blacklight. Without this, any change
11
9
  # to this class breaks other classes in this namespace
12
-
10
+
13
11
  require_dependency 'blacklight/configuration/context'
14
12
  require_dependency 'blacklight/configuration/view_config'
15
13
  require_dependency 'blacklight/configuration/tool_config'
@@ -26,7 +24,6 @@ module Blacklight
26
24
  # the basic, required Blacklight fields
27
25
  class << self
28
26
  def default_values
29
-
30
27
  @default_values ||= begin
31
28
  {
32
29
  ##
@@ -42,7 +39,7 @@ module Blacklight
42
39
  ##
43
40
  # === Single document request configuration
44
41
  ##
45
- # The solr rqeuest handler to use when requesting only a single document
42
+ # The solr rqeuest handler to use when requesting only a single document
46
43
  document_solr_request_handler: 'document',
47
44
  # THe path to send single document requests to solr
48
45
  document_solr_path: nil,
@@ -50,7 +47,7 @@ module Blacklight
50
47
  # Default values of parameters to send when requesting a single document
51
48
  default_document_solr_params: {
52
49
  ## Blacklight provides these settings in the /document request handler
53
- ## by default, we just ask for all fields.
50
+ ## by default, we just ask for all fields.
54
51
  #fl: '*',
55
52
  ## this is a fancy way to say "find the document by id using
56
53
  ## the value in the id query parameter"
@@ -95,17 +92,17 @@ module Blacklight
95
92
  group: false,
96
93
  # additional response formats for search results
97
94
  respond_to: OpenStructWithHashAccess.new
98
- ),
95
+ ),
99
96
  # Additional configuration when displaying a single document
100
97
  show: ViewConfig::Show.new(
101
98
  # document presenter class used by helpers and views
102
99
  document_presenter_class: nil,
103
100
  # default route parameters for 'show' requests
104
- # set this to a hash with additional arguments to merge into
105
- # the route, or set `controller: :current` to route to the
101
+ # set this to a hash with additional arguments to merge into
102
+ # the route, or set `controller: :current` to route to the
106
103
  # current controller.
107
104
  route: nil,
108
- # partials to render for each document(see #render_document_partials)
105
+ # partials to render for each document(see #render_document_partials)
109
106
  partials: [:show_header, :show],
110
107
  document_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
111
108
  ),
@@ -135,7 +132,7 @@ module Blacklight
135
132
  # Maximum number of results to show per page
136
133
  max_per_page: 100,
137
134
  # Options for the user for number of results to show per page
138
- per_page: [10,20,50,100],
135
+ per_page: [10, 20, 50, 100],
139
136
  default_per_page: nil,
140
137
  # how many searches to save in session history
141
138
  search_history_window: 100,
@@ -148,22 +145,21 @@ module Blacklight
148
145
  ##
149
146
  # Create collections of solr field configurations.
150
147
  # This will create array-like accessor methods for
151
- # the given field, and an #add_x_field convenience
148
+ # the given field, and an #add_x_field convenience
152
149
  # method for adding new fields to the configuration
153
-
150
+
154
151
  # facet fields
155
152
  define_field_access :facet_field
156
-
153
+
157
154
  # solr fields to display on search results
158
155
  define_field_access :index_field
159
-
156
+
160
157
  # solr fields to display when showing single documents
161
158
  define_field_access :show_field
162
-
163
- # solr "fields" to use for scoping user search queries
164
- # to particular fields
159
+
160
+ # solr "fields" to use for scoping user search queries to particular fields
165
161
  define_field_access :search_field
166
-
162
+
167
163
  # solr fields to use for sorting results
168
164
  define_field_access :sort_field
169
165
 
@@ -174,7 +170,6 @@ module Blacklight
174
170
  self
175
171
  end
176
172
 
177
- ##
178
173
  # Initialize default values from the class attribute
179
174
  def initialize_default_values!
180
175
  Marshal.load(Marshal.dump(self.class.default_values)).each do |k, v|
@@ -187,7 +182,7 @@ module Blacklight
187
182
  end
188
183
 
189
184
  # only here to support alias_method
190
- def document_model= *args
185
+ def document_model=(*args)
191
186
  super
192
187
  end
193
188
 
@@ -206,7 +201,7 @@ module Blacklight
206
201
  end
207
202
  deprecation_deprecate :document_presenter_class= => "replaced by show.presenter_class and index.presenter_class"
208
203
 
209
- def response_model= *args
204
+ def response_model=(*args)
210
205
  super
211
206
  end
212
207
 
@@ -234,54 +229,53 @@ module Blacklight
234
229
  super || per_page.first
235
230
  end
236
231
 
237
- ##
238
232
  # DSL helper
239
233
  def configure
240
234
  yield self if block_given?
241
235
  self
242
236
  end
243
237
 
244
- ##
245
238
  # Returns default search field, used for simpler display in history, etc.
246
239
  # if not set, defaults to first defined search field
247
240
  def default_search_field
248
241
  field = super
249
242
  field ||= search_fields.values.find { |f| f.default == true }
250
- field ||= search_fields.values.first
251
-
252
- field
243
+ field || search_fields.values.first
253
244
  end
254
245
 
255
- ##
256
246
  # Returns default sort field, used for simpler display in history, etc.
257
247
  # if not set, defaults to first defined sort field
258
248
  def default_sort_field
259
249
  field = super
260
250
  field ||= sort_fields.values.find { |f| f.default == true }
261
- field ||= sort_fields.values.first
262
-
263
- field
251
+ field || sort_fields.values.first
264
252
  end
265
-
253
+
266
254
  def default_title_field
267
255
  document_model.unique_key || 'id'
268
256
  end
269
257
 
270
- ##
258
+ # @param [String] field Solr facet name
259
+ # @return [Blacklight::Configuration::FacetField] Blacklight facet configuration for the solr field
260
+ def facet_configuration_for_field(field)
261
+ # short-circuit on the common case, where the solr field name and the blacklight field name are the same.
262
+ return facet_fields[field] if facet_fields[field] && facet_fields[field].field == field
263
+
264
+ # Find the facet field configuration for the solr field, or provide a default.
265
+ facet_fields.values.find { |v| v.field.to_s == field.to_s } ||
266
+ FacetField.new(field: field).normalize!
267
+ end
268
+
271
269
  # Add any configured facet fields to the default solr parameters hash
272
270
  # @overload add_facet_fields_to_solr_request!
273
271
  # add all facet fields to the solr request
274
- # @overload add_facet_fields_to_solr_request! field, field, field
275
- # @param [Symbol] Field names to add to the solr request
276
- # @param [Symbol]
277
- # @param [Symbol]
278
- def add_facet_fields_to_solr_request! *fields
272
+ # @overload add_facet_fields_to_solr_request! field, field, etc
273
+ # @param [Symbol] field Field names to add to the solr request
274
+ def add_facet_fields_to_solr_request!(*fields)
279
275
  if fields.empty?
280
276
  self.add_facet_fields_to_solr_request = true
281
277
  else
282
- facet_fields.slice(*fields).each do |k,v|
283
- v.include_in_request = true
284
- end
278
+ facet_fields.slice(*fields).each { |_k, v| v.include_in_request = true }
285
279
  end
286
280
  end
287
281
 
@@ -289,24 +283,15 @@ module Blacklight
289
283
  # Add any configured facet fields to the default solr parameters hash
290
284
  # @overload add_field_configuration_to_solr_request!
291
285
  # add all index, show, and facet fields to the solr request
292
- # @overload add_field_configuration_to_solr_request! field, field, field
293
- # @param [Symbol] Field names to add to the solr request
294
- # @param [Symbol]
295
- # @param [Symbol]
296
- def add_field_configuration_to_solr_request! *fields
286
+ # @overload add_field_configuration_to_solr_request! field, field, etc
287
+ # @param [Symbol] field Field names to add to the solr request
288
+ def add_field_configuration_to_solr_request!(*fields)
297
289
  if fields.empty?
298
290
  self.add_field_configuration_to_solr_request = true
299
291
  else
300
- index_fields.slice(*fields).each do |k,v|
301
- v.include_in_request = true
302
- end
303
-
304
- show_fields.slice(*fields).each do |k,v|
305
- v.include_in_request = true
306
- end
307
- facet_fields.slice(*fields).each do |k,v|
308
- v.include_in_request = true
309
- end
292
+ index_fields.slice(*fields).each { |_k, v| v.include_in_request = true }
293
+ show_fields.slice(*fields).each { |_k, v| v.include_in_request = true }
294
+ facet_fields.slice(*fields).each { |_k, v| v.include_in_request = true }
310
295
  end
311
296
  end
312
297
 
@@ -329,7 +314,7 @@ module Blacklight
329
314
  ##
330
315
  # Get a view configuration for the given view type
331
316
  # including default values from the index configuration
332
- def view_config view_type
317
+ def view_config(view_type)
333
318
  if view_type == :show
334
319
  self.index.merge self.show
335
320
  else
@@ -337,65 +322,45 @@ module Blacklight
337
322
  end
338
323
  end
339
324
 
340
- ##
325
+ # YARD will include inline disabling as docs, cannot do multiline inside @!macro. AND this must be separate from doc block.
326
+ # rubocop:disable Metrics/LineLength
327
+
341
328
  # Add a partial to the tools when rendering a document.
342
- # @param partial [String] the name of the document partial
343
- # @param opts [Hash]
344
- # @option opts [Symbol,Proc] :if render this action if the method identified by the symbol or the proc evaluates to true.
345
- # The proc will receive the action configuration and the document or documents for the action.
346
- # @option opts [Symbol,Proc] :unless render this action unless the method identified by the symbol or the proc evaluates to true
347
- # The proc will receive the action configuration and the document or documents for the action.
329
+ # @!macro partial_if_unless
330
+ # @param name [String] the name of the document partial
331
+ # @param opts [Hash]
332
+ # @option opts [Symbol,Proc] :if render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.
333
+ # @option opts [Symbol,Proc] :unless render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.
348
334
  def add_show_tools_partial(name, opts = {})
349
335
  opts[:partial] ||= 'document_action'
350
336
  add_action(show.document_actions, name, opts)
351
337
  end
338
+ # rubocop:enable Metrics/LineLength
352
339
 
353
- ##
354
340
  # Add a tool for the search result list itself
355
- # @param partial [String] the name of the document partial
356
- # @param opts [Hash]
357
- # @option opts [Symbol,Proc] :if render this action if the method identified by the symbol or the proc evaluates to true.
358
- # The proc will receive the action configuration and the document or documents for the action.
359
- # @option opts [Symbol,Proc] :unless render this action unless the method identified by the symbol or the proc evaluates to true
360
- # The proc will receive the action configuration and the document or documents for the action.
341
+ # @!macro partial_if_unless
361
342
  def add_results_collection_tool(name, opts = {})
362
343
  add_action(index.collection_actions, name, opts)
363
344
  end
364
345
 
365
- ##
366
346
  # Add a partial to the tools for each document in the search results.
367
- # @param partial [String] the name of the document partial
368
- # @param opts [Hash]
369
- # @option opts [Symbol,Proc] :if render this action if the method identified by the symbol or the proc evaluates to true.
370
- # The proc will receive the action configuration and the document or documents for the action.
371
- # @option opts [Symbol,Proc] :unless render this action unless the method identified by the symbol or the proc evaluates to true
372
- # The proc will receive the action configuration and the document or documents for the action.
347
+ # @!macro partial_if_unless
373
348
  def add_results_document_tool(name, opts = {})
374
349
  add_action(index.document_actions, name, opts)
375
350
  end
376
351
 
377
- ##
378
352
  # Add a partial to the header navbar
379
- # @param partial [String] the name of the document partial
380
- # @param opts [Hash]
381
- # @option opts [Symbol,Proc] :if render this action if the method identified by the symbol or the proc evaluates to true.
382
- # The proc will receive the action configuration and the document or documents for the action.
383
- # @option opts [Symbol,Proc] :unless render this action unless the method identified by the symbol or the proc evaluates to true
384
- # The proc will receive the action configuration and the document or documents for the action.
385
- def add_nav_action name, opts = {}
353
+ # @!macro partial_if_unless
354
+ def add_nav_action(name, opts = {})
386
355
  add_action(navbar.partials, name, opts)
387
356
  end
388
357
 
389
358
  private
390
359
 
391
- def add_action config_hash, name, opts
360
+ def add_action(config_hash, name, opts)
392
361
  config = Blacklight::Configuration::ToolConfig.new opts
393
362
  config.name = name
394
-
395
- if block_given?
396
- yield config
397
- end
398
-
363
+ yield(config) if block_given?
399
364
  config_hash[name] = config
400
365
  end
401
366
  end