blacklight 7.11.1 → 7.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.solr_wrapper.yml +5 -0
  4. data/VERSION +1 -1
  5. data/app/builders/blacklight/action_builder.rb +6 -0
  6. data/app/components/blacklight/constraint_component.html.erb +5 -0
  7. data/app/components/blacklight/constraint_component.rb +13 -0
  8. data/app/components/blacklight/constraint_layout_component.rb +2 -1
  9. data/app/components/blacklight/constraints_component.html.erb +10 -0
  10. data/app/components/blacklight/constraints_component.rb +65 -0
  11. data/app/components/blacklight/document/action_component.html.erb +9 -0
  12. data/app/components/blacklight/document/action_component.rb +38 -0
  13. data/app/components/blacklight/document/actions_component.html.erb +13 -0
  14. data/app/components/blacklight/document/actions_component.rb +26 -0
  15. data/app/components/blacklight/document/bookmark_component.html.erb +1 -1
  16. data/app/components/blacklight/document/bookmark_component.rb +8 -0
  17. data/app/components/blacklight/document/citation_component.html.erb +4 -2
  18. data/app/components/blacklight/document/citation_component.rb +8 -1
  19. data/app/components/blacklight/document/group_component.html.erb +9 -0
  20. data/app/components/blacklight/document/group_component.rb +26 -0
  21. data/app/components/blacklight/document/more_like_this_component.rb +2 -0
  22. data/app/components/blacklight/document/thumbnail_component.html.erb +12 -0
  23. data/app/components/blacklight/document/thumbnail_component.rb +25 -0
  24. data/app/components/blacklight/document_component.rb +27 -26
  25. data/app/components/blacklight/facet_field_filter_component.html.erb +12 -0
  26. data/app/components/blacklight/facet_field_filter_component.rb +25 -0
  27. data/app/components/blacklight/facet_field_pagination_component.html.erb +19 -0
  28. data/app/components/blacklight/facet_field_pagination_component.rb +21 -0
  29. data/app/components/blacklight/facet_item_component.rb +4 -8
  30. data/app/components/blacklight/response/facet_group_component.html.erb +3 -1
  31. data/app/components/blacklight/response/facet_group_component.rb +8 -1
  32. data/app/components/blacklight/response/pagination_component.rb +3 -0
  33. data/app/components/blacklight/response/sort_component.html.erb +1 -1
  34. data/app/components/blacklight/response/spellcheck_component.rb +9 -2
  35. data/app/components/blacklight/response/view_type_component.html.erb +11 -0
  36. data/app/components/blacklight/response/view_type_component.rb +36 -0
  37. data/app/components/blacklight/search_bar_component.html.erb +1 -1
  38. data/app/components/blacklight/search_bar_component.rb +6 -0
  39. data/app/components/blacklight/search_context_component.rb +6 -2
  40. data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
  41. data/app/components/blacklight/system/flash_message_component.html.erb +4 -0
  42. data/app/components/blacklight/system/flash_message_component.rb +24 -0
  43. data/app/controllers/concerns/blacklight/catalog.rb +7 -1
  44. data/app/controllers/concerns/blacklight/controller.rb +12 -3
  45. data/app/controllers/concerns/blacklight/facet.rb +19 -5
  46. data/app/controllers/concerns/blacklight/search_fields.rb +7 -1
  47. data/app/helpers/blacklight/blacklight_helper_behavior.rb +127 -17
  48. data/app/helpers/blacklight/catalog_helper_behavior.rb +36 -5
  49. data/app/helpers/blacklight/component_helper_behavior.rb +36 -6
  50. data/app/helpers/blacklight/configuration_helper_behavior.rb +32 -4
  51. data/app/helpers/blacklight/facets_helper_behavior.rb +31 -8
  52. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +5 -0
  53. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +28 -11
  54. data/app/helpers/blacklight/render_partials_helper_behavior.rb +8 -3
  55. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +4 -2
  56. data/app/helpers/blacklight/suggest_helper_behavior.rb +1 -0
  57. data/app/helpers/blacklight/url_helper_behavior.rb +23 -3
  58. data/app/models/blacklight/icon.rb +0 -1
  59. data/app/models/concerns/blacklight/document.rb +1 -1
  60. data/app/models/concerns/blacklight/suggest/response.rb +1 -1
  61. data/app/models/record_mailer.rb +1 -1
  62. data/app/presenters/blacklight/document_presenter.rb +42 -1
  63. data/app/presenters/blacklight/facet_field_presenter.rb +3 -1
  64. data/app/presenters/blacklight/facet_item_presenter.rb +8 -0
  65. data/app/presenters/blacklight/field_presenter.rb +9 -6
  66. data/app/presenters/blacklight/json_presenter.rb +3 -1
  67. data/app/presenters/blacklight/show_presenter.rb +4 -30
  68. data/app/presenters/blacklight/thumbnail_presenter.rb +5 -1
  69. data/app/services/blacklight/document_factory.rb +3 -0
  70. data/app/services/blacklight/field_retriever.rb +18 -4
  71. data/app/services/blacklight/search_service.rb +0 -1
  72. data/app/views/bookmarks/_tools.html.erb +12 -7
  73. data/app/views/catalog/_bookmark_control.html.erb +1 -1
  74. data/app/views/catalog/_constraints.html.erb +12 -7
  75. data/app/views/catalog/_document.atom.builder +9 -6
  76. data/app/views/catalog/_document.rss.builder +4 -2
  77. data/app/views/catalog/_facet_index_navigation.html.erb +1 -10
  78. data/app/views/catalog/_facet_pagination.html.erb +1 -19
  79. data/app/views/catalog/_facets.html.erb +1 -1
  80. data/app/views/catalog/_group.html.erb +1 -9
  81. data/app/views/catalog/_index.html.erb +1 -1
  82. data/app/views/catalog/_search_results.html.erb +1 -1
  83. data/app/views/catalog/_show.html.erb +1 -1
  84. data/app/views/catalog/_show_header.html.erb +1 -1
  85. data/app/views/catalog/_show_main_content.html.erb +2 -2
  86. data/app/views/catalog/_show_tools.html.erb +12 -8
  87. data/app/views/catalog/_start_over.html.erb +1 -1
  88. data/app/views/catalog/_thumbnail.html.erb +1 -5
  89. data/app/views/catalog/_view_type_group.html.erb +5 -13
  90. data/app/views/catalog/index.json.jbuilder +8 -6
  91. data/app/views/catalog/show.json.jbuilder +1 -1
  92. data/app/views/shared/_flash_msg.html.erb +1 -15
  93. data/blacklight.gemspec +1 -0
  94. data/config/locales/blacklight.ca.yml +241 -0
  95. data/lib/blacklight/abstract_repository.rb +13 -4
  96. data/lib/blacklight/configuration.rb +11 -5
  97. data/lib/blacklight/configuration/display_field.rb +50 -0
  98. data/lib/blacklight/configuration/facet_field.rb +58 -1
  99. data/lib/blacklight/configuration/field.rb +13 -0
  100. data/lib/blacklight/configuration/index_field.rb +5 -0
  101. data/lib/blacklight/configuration/search_field.rb +3 -0
  102. data/lib/blacklight/configuration/show_field.rb +5 -0
  103. data/lib/blacklight/configuration/sort_field.rb +3 -0
  104. data/lib/blacklight/configuration/tool_config.rb +1 -0
  105. data/lib/blacklight/configuration/view_config.rb +25 -0
  106. data/lib/blacklight/search_state.rb +4 -2
  107. data/lib/blacklight/solr/repository.rb +1 -1
  108. data/lib/generators/blacklight/templates/catalog_controller.rb +8 -7
  109. data/spec/components/blacklight/document/action_component_spec.rb +43 -0
  110. data/spec/components/blacklight/document/group_component_spec.rb +45 -0
  111. data/spec/components/blacklight/document_component_spec.rb +8 -0
  112. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +0 -1
  113. data/spec/components/blacklight/system/flash_message_component_spec.rb +54 -0
  114. data/spec/controllers/blacklight/search_fields_spec.rb +2 -0
  115. data/spec/controllers/catalog_controller_spec.rb +2 -0
  116. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +6 -1
  117. data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +2 -0
  118. data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +2 -0
  119. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +3 -1
  120. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +2 -0
  121. data/spec/helpers/blacklight_helper_spec.rb +10 -0
  122. data/spec/helpers/catalog_helper_spec.rb +4 -4
  123. data/spec/lib/blacklight/configuration/facet_field_spec.rb +17 -0
  124. data/spec/models/blacklight/search_builder_spec.rb +1 -1
  125. data/spec/models/blacklight/solr/search_builder_spec.rb +8 -0
  126. data/spec/presenters/blacklight/field_presenter_spec.rb +30 -5
  127. data/spec/services/blacklight/search_service_spec.rb +1 -5
  128. data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -1
  129. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -2
  130. data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
  131. data/spec/views/catalog/show.json.jbuilder_spec.rb +1 -0
  132. data/tasks/blacklight.rake +27 -12
  133. metadata +47 -2
@@ -4,20 +4,27 @@ module Blacklight
4
4
  # They are only dependent on `blacklight_config` and `@response`
5
5
  #
6
6
  module Facet
7
+ extend Deprecation
7
8
  delegate :facet_configuration_for_field, :facet_field_names, to: :blacklight_config
8
9
 
10
+ # @deprecated
11
+ # @param [Blacklight::Configuration::Facet] field_config
12
+ # @param [Object] response_data
13
+ # @return [Blacklight::FacetPaginator]
9
14
  def facet_paginator(field_config, response_data)
10
15
  blacklight_config.facet_paginator_class.new(
11
16
  response_data.items,
12
17
  sort: response_data.sort,
13
18
  offset: response_data.offset,
14
19
  prefix: response_data.prefix,
15
- limit: facet_limit_for(field_config.key)
20
+ limit: Deprecation.silence(Blacklight::Catalog) { facet_limit_for(field_config.key) }
16
21
  )
17
22
  end
23
+ deprecation_deprecate facet_paginator: 'Use Blacklight::FacetFieldPresenter#paginator instead'
18
24
 
19
25
  # @param fields [Array<String>] a list of facet field names
20
26
  # @return [Array<Solr::Response::Facets::FacetField>]
27
+ # @deprecated
21
28
  def facets_from_request(fields = facet_field_names, response = nil)
22
29
  unless response
23
30
  Deprecation.warn(self, 'Calling facets_from_request without passing the ' \
@@ -25,14 +32,20 @@ module Blacklight
25
32
  '8.0.0')
26
33
  response = @response
27
34
  end
28
- fields.map { |field| facet_by_field_name(field, response) }.compact
29
- end
30
35
 
31
- def facet_group_names
32
- blacklight_config.facet_fields.map { |_facet, opts| opts[:group] }.uniq
36
+ Deprecation.silence(Blacklight::Facet) do
37
+ fields.map { |field| facet_by_field_name(field, response) }.compact
38
+ end
33
39
  end
40
+ deprecation_deprecate facets_from_request: 'Removed without replacement'
41
+
42
+ delegate :facet_group_names, to: :blacklight_config
43
+ deprecation_deprecate facet_group_names: 'Use blacklight_config.facet_group_names instead'
34
44
 
35
45
  # Get a FacetField object from the @response
46
+ # @deprecated
47
+ # @private
48
+ # @return [Blacklight::Solr::Response::Facets::FacetField]
36
49
  def facet_by_field_name(field_or_field_name, response = nil)
37
50
  unless response
38
51
  Deprecation.warn(self, 'Calling facet_by_field_name without passing the ' \
@@ -51,5 +64,6 @@ module Blacklight
51
64
  field_or_field_name
52
65
  end
53
66
  end
67
+ deprecation_deprecate facet_by_field_name: 'Removed without replacement'
54
68
  end
55
69
  end
@@ -26,15 +26,21 @@
26
26
  #
27
27
  ##
28
28
  module Blacklight::SearchFields
29
+ extend Deprecation
30
+
29
31
  # Looks up search field config list from blacklight_config[:search_fields], and
30
32
  # 'normalizes' all field config hashes using normalize_config method.
33
+ # @deprecated
31
34
  def search_field_list
32
35
  blacklight_config.search_fields.values
33
36
  end
37
+ deprecation_deprecate search_field_list: 'Use blacklight_config.search_fields instead'
34
38
 
35
39
  # Returns default search field, used for simpler display in history, etc.
36
40
  # if not set in blacklight_config, defaults to first field listed in #search_field_list
41
+ # @deprecated
37
42
  def default_search_field
38
- blacklight_config.default_search_field || search_field_list.first
43
+ blacklight_config.default_search_field || (Deprecation.silence(Blacklight::SearchFields) { search_field_list.first })
39
44
  end
45
+ deprecation_deprecate default_search_field: 'Use Blacklight::Configuration#default_search_field'
40
46
  end
@@ -8,6 +8,8 @@ module Blacklight::BlacklightHelperBehavior
8
8
  include Blacklight::LayoutHelperBehavior
9
9
  include Blacklight::IconHelperBehavior
10
10
 
11
+ # @!group Layout helpers
12
+
11
13
  ##
12
14
  # Get the name of this application from an i18n string
13
15
  # key: blacklight.application_name
@@ -42,14 +44,16 @@ module Blacklight::BlacklightHelperBehavior
42
44
  # @option options [Boolean] :unique ensures only one link is output for every
43
45
  # content type, e.g. as required by atom
44
46
  # @option options [Array<String>] :exclude array of format shortnames to not include in the output
47
+ # @return [String]
45
48
  def render_link_rel_alternates(document = @document, options = {})
46
49
  return if document.nil?
47
50
 
48
- presenter(document).link_rel_alternates(options)
51
+ document_presenter(document).link_rel_alternates(options)
49
52
  end
50
53
 
51
54
  ##
52
55
  # Render OpenSearch headers for this search
56
+ # @deprecated
53
57
  # @return [String]
54
58
  def render_opensearch_response_metadata
55
59
  render partial: 'catalog/opensearch_response_metadata', locals: { response: @response }
@@ -78,13 +82,18 @@ module Blacklight::BlacklightHelperBehavior
78
82
  search_bar_presenter.render
79
83
  end
80
84
 
85
+ # @!group Presenter extension helpers
86
+ ##
87
+ # @return [Blacklight::SearchBarPresenter]
81
88
  def search_bar_presenter
82
89
  @search_bar ||= search_bar_presenter_class.new(controller, blacklight_config)
83
90
  end
84
91
 
92
+ # @!group Document helpers
85
93
  ##
86
94
  # Determine whether to render a given field in the index view.
87
95
  #
96
+ # @deprecated
88
97
  # @param [SolrDocument] document
89
98
  # @param [Blacklight::Configuration::Field] field_config
90
99
  # @return [Boolean]
@@ -96,6 +105,7 @@ module Blacklight::BlacklightHelperBehavior
96
105
  ##
97
106
  # Determine whether to render a given field in the show view
98
107
  #
108
+ # @deprecated
99
109
  # @param [SolrDocument] document
100
110
  # @param [Blacklight::Configuration::Field] field_config
101
111
  # @return [Boolean]
@@ -106,7 +116,8 @@ module Blacklight::BlacklightHelperBehavior
106
116
 
107
117
  ##
108
118
  # Check if a document has (or, might have, in the case of accessor methods) a value for
109
- # the given solr field
119
+ # the given solr
120
+ # @deprecated
110
121
  # @param [SolrDocument] document
111
122
  # @param [Blacklight::Configuration::Field] field_config
112
123
  # @return [Boolean]
@@ -117,24 +128,31 @@ module Blacklight::BlacklightHelperBehavior
117
128
  field_config.accessor
118
129
  end
119
130
 
131
+ # @!group Search result helpers
120
132
  ##
121
133
  # Determine whether to display spellcheck suggestions
122
134
  #
135
+ # @deprecated
123
136
  # @param [Blacklight::Solr::Response] response
124
137
  # @return [Boolean]
125
138
  def should_show_spellcheck_suggestions? response
126
- # The spelling response field may be missing from non solr repositories.
127
- response.total <= spell_check_max &&
128
- !response.spelling.nil? &&
129
- response.spelling.words.any?
139
+ Deprecation.silence(Blacklight::ConfigurationHelperBehavior) do
140
+ # The spelling response field may be missing from non solr repositories.
141
+ response.total <= spell_check_max &&
142
+ !response.spelling.nil? &&
143
+ response.spelling.words.any?
144
+ end
130
145
  end
146
+ deprecation_deprecate should_show_spellcheck_suggestions?: 'moving into a private method of Blacklight::Response::SpellcheckComponent'
131
147
 
148
+ # @!group Document helpers
132
149
  ##
133
150
  # Render the index field label for a document
134
151
  #
135
152
  # Translations for index field labels should go under blacklight.search.fields
136
153
  # They are picked up from there by a value "%{label}" in blacklight.search.index.label
137
154
  #
155
+ # @deprecated
138
156
  # @overload render_index_field_label(options)
139
157
  # Use the default, document-agnostic configuration
140
158
  # @param [Hash] opts
@@ -145,6 +163,7 @@ module Blacklight::BlacklightHelperBehavior
145
163
  # @param [SolrDocument] doc
146
164
  # @param [Hash] opts
147
165
  # @option opts [String] :field
166
+ # @return [String]
148
167
  def render_index_field_label *args
149
168
  options = args.extract_options!
150
169
  document = args.first
@@ -160,6 +179,7 @@ module Blacklight::BlacklightHelperBehavior
160
179
  ##
161
180
  # Render the show field label for a document
162
181
  #
182
+ # @deprecated
163
183
  # @overload render_document_show_field_label(options)
164
184
  # Use the default, document-agnostic configuration
165
185
  # @param [Hash] opts
@@ -170,6 +190,7 @@ module Blacklight::BlacklightHelperBehavior
170
190
  # @param [SolrDocument] doc
171
191
  # @param [Hash] opts
172
192
  # @option opts [String] :field
193
+ # @return [String]
173
194
  def render_document_show_field_label *args
174
195
  options = args.extract_options!
175
196
  document = args.first
@@ -187,28 +208,33 @@ module Blacklight::BlacklightHelperBehavior
187
208
  # Get the value of the document's "title" field, or a placeholder
188
209
  # value (if empty)
189
210
  #
211
+ # @deprecated
190
212
  # @param [SolrDocument] document
191
213
  # @return [String]
192
214
  def document_heading document = nil
193
215
  document ||= @document
194
- presenter(document).heading
216
+ document_presenter(document).heading
195
217
  end
218
+ deprecation_deprecate document_heading: 'Use Blacklight::DocumentPresenter#heading instead'
196
219
 
197
220
  ##
198
221
  # Get the document's "title" to display in the <title> element.
199
222
  # (by default, use the #document_heading)
200
223
  #
224
+ # @deprecated
201
225
  # @see #document_heading
202
226
  # @param [SolrDocument] document
203
227
  # @return [String]
204
228
  def document_show_html_title document = nil
205
229
  document ||= @document
206
230
 
207
- presenter(document).html_title
231
+ document_presenter(document).html_title
208
232
  end
233
+ deprecation_deprecate document_show_html_title: 'Use Blacklight::DocumentPresenter#html_title instead'
209
234
 
210
235
  ##
211
236
  # Render the document "heading" (title) in a content tag
237
+ # @deprecated
212
238
  # @overload render_document_heading(document, options)
213
239
  # @param [SolrDocument] document
214
240
  # @param [Hash] options
@@ -216,14 +242,16 @@ module Blacklight::BlacklightHelperBehavior
216
242
  # @overload render_document_heading(options)
217
243
  # @param [Hash] options
218
244
  # @option options [Symbol] :tag
245
+ # @return [String]
219
246
  def render_document_heading(*args)
220
247
  options = args.extract_options!
221
248
  document = args.first
222
249
  tag = options.fetch(:tag, :h4)
223
250
  document ||= @document
224
251
 
225
- content_tag(tag, presenter(document).heading, itemprop: "name")
252
+ content_tag(tag, document_presenter(document).heading, itemprop: "name")
226
253
  end
254
+ deprecation_deprecate render_document_heading: 'Removed without replacement'
227
255
 
228
256
  ##
229
257
  # Get the current "view type" (and ensure it is a valid type)
@@ -240,6 +268,7 @@ module Blacklight::BlacklightHelperBehavior
240
268
  end
241
269
  end
242
270
 
271
+ # @!group Search result helpers
243
272
  ##
244
273
  # Render a partial of an arbitrary format inside a
245
274
  # template of a different format. (e.g. render an HTML
@@ -263,47 +292,128 @@ module Blacklight::BlacklightHelperBehavior
263
292
  #
264
293
  # Default to false if there's no response object available (sometimes the case
265
294
  # for tests, but might happen in other circumstances too..)
295
+ # @return [Boolean]
266
296
  def render_grouped_response? response = @response
267
297
  response&.grouped?
268
298
  end
269
299
 
300
+ # @!group Presenter extension helpers
270
301
  ##
271
302
  # Returns a document presenter for the given document
272
303
  # TODO: Move this to the controller. It can just pass a presenter or set of presenters.
304
+ # @deprecated
305
+ # @return [Blacklight::DocumentPresenter]
273
306
  def presenter(document)
274
- case action_name
275
- when 'show', 'citation'
276
- show_presenter(document)
277
- else
278
- index_presenter(document)
307
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#presenter is deprecated; use #document_presenter instead')
308
+
309
+ # As long as the presenter methods haven't been overridden, we can use the new behavior
310
+ if method(:show_presenter).owner == Blacklight::BlacklightHelperBehavior &&
311
+ method(:index_presenter).owner == Blacklight::BlacklightHelperBehavior
312
+ return document_presenter_class(document).new(document, self)
313
+ end
314
+
315
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#show_presenter and/or #index_presenter have been overridden; please override #document_presenter instead')
316
+
317
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
318
+ case action_name
319
+ when 'show', 'citation'
320
+ show_presenter(document)
321
+ else
322
+ index_presenter(document)
323
+ end
324
+ end
325
+ end
326
+
327
+ ##
328
+ # Returns a document presenter for the given document
329
+ def document_presenter(document)
330
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
331
+ presenter(document)
279
332
  end
280
333
  end
281
334
 
335
+ # @deprecated
336
+ # @return [Blacklight::ShowPresenter]
282
337
  def show_presenter(document)
283
- show_presenter_class(document).new(document, self)
338
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#show_presenter is deprecated; use #document_presenter instead')
339
+
340
+ if method(:show_presenter_class).owner != Blacklight::BlacklightHelperBehavior
341
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#show_presenter_class has been overridden; please override #document_presenter_class instead')
342
+ end
343
+
344
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
345
+ show_presenter_class(document).new(document, self)
346
+ end
284
347
  end
285
348
 
349
+ # @deprecated
350
+ # @return [Blacklight::IndexPresenter]
286
351
  def index_presenter(document)
287
- index_presenter_class(document).new(document, self)
352
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#index_presenter is deprecated; use #document_presenter instead')
353
+
354
+ if method(:index_presenter_class).owner != Blacklight::BlacklightHelperBehavior
355
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#index_presenter_class has been overridden; please override #document_presenter_class instead')
356
+ end
357
+
358
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
359
+ index_presenter_class(document).new(document, self)
360
+ end
361
+ end
362
+
363
+ ##
364
+ # Override this method if you want to use a differnet presenter for your documents
365
+ def document_presenter_class(document)
366
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
367
+ case action_name
368
+ when 'show', 'citation'
369
+ show_presenter_class(document)
370
+ else
371
+ index_presenter_class(document)
372
+ end
373
+ end
288
374
  end
289
375
 
290
376
  ##
291
377
  # Override this method if you want to use a different presenter class
378
+ # @deprecated
379
+ # @return [Class]
292
380
  def show_presenter_class(_document)
381
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#show_presenter_class is deprecated; use #document_presenter_class instead')
382
+
293
383
  blacklight_config.show.document_presenter_class
294
384
  end
295
385
 
386
+ # @deprecated
387
+ # @return [Class]
296
388
  def index_presenter_class(_document)
297
- blacklight_config.index.document_presenter_class
389
+ Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#index_presenter_class is deprecated; use #document_presenter_class instead')
390
+
391
+ (blacklight_config.view.key?(document_index_view_type) && blacklight_config.dig(:view, document_index_view_type, :document_presenter_class)) ||
392
+ blacklight_config.index.document_presenter_class
298
393
  end
299
394
 
395
+ # @return [Class]
300
396
  def search_bar_presenter_class
301
397
  blacklight_config.index.search_bar_presenter_class
302
398
  end
303
399
 
400
+ # @!group Layout helpers
304
401
  ##
305
402
  # Open Search discovery tag for HTML <head> links
403
+ # @return [String]
306
404
  def opensearch_description_tag title, href
307
405
  tag :link, href: href, title: title, type: "application/opensearchdescription+xml", rel: "search"
308
406
  end
407
+
408
+ # @private
409
+
410
+ def self.blacklight_path
411
+ @blacklight_path ||= Gem.loaded_specs["blacklight"].source.path.to_s
412
+ end
413
+
414
+ def partial_from_blacklight?(partial)
415
+ path = lookup_context.find_all(partial, lookup_context.prefixes + [""], true).first&.identifier
416
+
417
+ path&.starts_with?(Blacklight::BlacklightHelperBehavior.blacklight_path)
418
+ end
309
419
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # Helper methods for catalog-like controllers
2
3
  module Blacklight::CatalogHelperBehavior
3
4
  extend Deprecation
4
5
  self.deprecation_horizon = 'blacklight 8.0'
@@ -13,18 +14,21 @@ module Blacklight::CatalogHelperBehavior
13
14
 
14
15
  # @param [Hash] options
15
16
  # @option options :route_set the route scope to use when constructing the link
17
+ # @return [String]
16
18
  def rss_feed_link_tag(options = {})
17
19
  auto_discovery_link_tag(:rss, feed_link_url('rss', options), title: t('blacklight.search.rss_feed'))
18
20
  end
19
21
 
20
22
  # @param [Hash] options
21
23
  # @option options :route_set the route scope to use when constructing the link
24
+ # @return [String]
22
25
  def atom_feed_link_tag(options = {})
23
26
  auto_discovery_link_tag(:atom, feed_link_url('atom', options), title: t('blacklight.search.atom_feed'))
24
27
  end
25
28
 
26
29
  # @param [Hash] options
27
30
  # @option options :route_set the route scope to use when constructing the link
31
+ # @return [String]
28
32
  def json_api_link_tag(options = {})
29
33
  auto_discovery_link_tag(:json, feed_link_url('json', options), type: 'application/json')
30
34
  end
@@ -96,6 +100,7 @@ module Blacklight::CatalogHelperBehavior
96
100
  # Like #page_entries_info above, but for an individual
97
101
  # item show page. Displays "showing X of Y items" message.
98
102
  #
103
+ # @deprecated
99
104
  # @see #page_entries_info
100
105
  # @return [String]
101
106
  def item_page_entry_info
@@ -108,6 +113,7 @@ module Blacklight::CatalogHelperBehavior
108
113
  ##
109
114
  # Look up search field user-displayable label
110
115
  # based on params[:qt] and blacklight_configuration.
116
+ # @return [String]
111
117
  def search_field_label(params)
112
118
  h(label_for_search_field(params[:search_field]))
113
119
  end
@@ -131,9 +137,10 @@ module Blacklight::CatalogHelperBehavior
131
137
  ##
132
138
  # Get the classes to add to a document's div
133
139
  #
140
+ # @param [Blacklight::Document] document
134
141
  # @return [String]
135
142
  def render_document_class(document = @document)
136
- types = presenter(document).display_type
143
+ types = document_presenter(document).display_type
137
144
  return if types.blank?
138
145
 
139
146
  Array(types).compact.map do |t|
@@ -141,6 +148,10 @@ module Blacklight::CatalogHelperBehavior
141
148
  end.join(' ')
142
149
  end
143
150
 
151
+ ##
152
+ # Return a prefix for the document classes infered from the document
153
+ # @see #render_document_class
154
+ # @return [String]
144
155
  def document_class_prefix
145
156
  'blacklight-'
146
157
  end
@@ -162,7 +173,7 @@ module Blacklight::CatalogHelperBehavior
162
173
  ##
163
174
  # Render the main content partial for a document
164
175
  #
165
- # @param [SolrDocument] document
176
+ # @param [SolrDocument] _document
166
177
  # @return [String]
167
178
  def render_document_main_content_partial(_document = @document)
168
179
  render partial: 'show_main_content'
@@ -192,6 +203,7 @@ module Blacklight::CatalogHelperBehavior
192
203
  # If no search parameters have been given, we should
193
204
  # auto-focus the user's cursor into the searchbox
194
205
  #
206
+ # @deprecated
195
207
  # @return [Boolean]
196
208
  def should_autofocus_on_search_box?
197
209
  controller.is_a?(Blacklight::Catalog) &&
@@ -203,10 +215,11 @@ module Blacklight::CatalogHelperBehavior
203
215
  ##
204
216
  # Does the document have a thumbnail to render?
205
217
  #
218
+ # @deprecated
206
219
  # @param [SolrDocument] document
207
220
  # @return [Boolean]
208
221
  def has_thumbnail? document
209
- index_presenter(document).thumbnail.exists?
222
+ document_presenter(document).thumbnail.exists?
210
223
  end
211
224
  deprecation_deprecate has_thumbnail?: "use IndexPresenter#thumbnail.exists?"
212
225
 
@@ -214,18 +227,20 @@ module Blacklight::CatalogHelperBehavior
214
227
  # Render the thumbnail, if available, for a document and
215
228
  # link it to the document record.
216
229
  #
230
+ # @deprecated
217
231
  # @param [SolrDocument] document
218
232
  # @param [Hash] image_options to pass to the image tag
219
233
  # @param [Hash] url_options to pass to #link_to_document
220
234
  # @return [String]
221
235
  def render_thumbnail_tag document, image_options = {}, url_options = {}
222
- index_presenter(document).thumbnail.thumbnail_tag(image_options, url_options)
236
+ document_presenter(document).thumbnail.thumbnail_tag(image_options, url_options)
223
237
  end
224
238
  deprecation_deprecate render_thumbnail_tag: "Use IndexPresenter#thumbnail.thumbnail_tag"
225
239
 
226
240
  ##
227
241
  # Get the URL to a document's thumbnail image
228
242
  #
243
+ # @deprecated
229
244
  # @param [SolrDocument] document
230
245
  # @return [String]
231
246
  def thumbnail_url document
@@ -247,6 +262,7 @@ module Blacklight::CatalogHelperBehavior
247
262
  ##
248
263
  # Get the default view type classes for a view in the results view picker
249
264
  #
265
+ # @deprecated
250
266
  # @param [String] view
251
267
  # @return [String]
252
268
  def default_view_type_group_icon_classes view
@@ -254,6 +270,10 @@ module Blacklight::CatalogHelperBehavior
254
270
  "glyphicon-#{view.to_s.parameterize} view-icon-#{view.to_s.parameterize}"
255
271
  end
256
272
 
273
+ ##
274
+ # return the Bookmarks on a set of documents
275
+ # @param [Enumerable<Blacklight::Document>] documents_or_response
276
+ # @return [Enumerable<Bookmark>]
257
277
  def current_bookmarks documents_or_response = nil
258
278
  documents = if documents_or_response.respond_to? :documents
259
279
  Deprecation.warn(Blacklight::CatalogHelperBehavior, "Passing a response to #current_bookmarks is deprecated; pass response.documents instead")
@@ -270,10 +290,18 @@ module Blacklight::CatalogHelperBehavior
270
290
 
271
291
  ##
272
292
  # Check if the document is in the user's bookmarks
293
+ # @param [Blacklight::Document] document
294
+ # @return [Boolean]
273
295
  def bookmarked? document
274
296
  current_bookmarks.any? { |x| x.document_id == document.id && x.document_type == document.class }
275
297
  end
276
298
 
299
+ # Render an html <title> appropriate string for a selected facet field and values
300
+ #
301
+ # @see #render_search_to_page_title
302
+ # @param [Symbol] facet the facet field
303
+ # @param [Array<String>] values the selected facet values
304
+ # @return [String]
277
305
  def render_search_to_page_title_filter(facet, values)
278
306
  facet_config = facet_configuration_for_field(facet)
279
307
  filter_label = facet_field_label(facet_config.key)
@@ -285,11 +313,14 @@ module Blacklight::CatalogHelperBehavior
285
313
  t('blacklight.search.page_title.constraint', label: filter_label, value: filter_value)
286
314
  end
287
315
 
316
+ # Render an html <title> appropriate string for a set of search parameters
317
+ # @param [ActionController::Parameters] params2
318
+ # @return [String]
288
319
  def render_search_to_page_title(params)
289
320
  constraints = []
290
321
 
291
322
  if params['q'].present?
292
- q_label = label_for_search_field(params[:search_field]) unless default_search_field && params[:search_field] == default_search_field[:key]
323
+ q_label = label_for_search_field(params[:search_field]) unless default_search_field?(params[:search_field])
293
324
 
294
325
  constraints += if q_label.present?
295
326
  [t('blacklight.search.page_title.constraint', label: q_label, value: params['q'])]