blacklight 7.15.1 → 7.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/VERSION +1 -1
  4. data/app/components/blacklight/advanced_search_form_component.html.erb +9 -3
  5. data/app/components/blacklight/advanced_search_form_component.rb +48 -35
  6. data/app/components/blacklight/constraints_component.html.erb +19 -3
  7. data/app/components/blacklight/constraints_component.rb +5 -1
  8. data/app/components/blacklight/content_areas_shim.rb +12 -0
  9. data/app/components/blacklight/document/action_component.html.erb +1 -1
  10. data/app/components/blacklight/document/action_component.rb +6 -1
  11. data/app/components/blacklight/document/actions_component.html.erb +3 -5
  12. data/app/components/blacklight/document/actions_component.rb +16 -2
  13. data/app/components/blacklight/document_component.html.erb +4 -7
  14. data/app/components/blacklight/document_component.rb +73 -73
  15. data/app/components/blacklight/document_metadata_component.html.erb +2 -2
  16. data/app/components/blacklight/document_metadata_component.rb +13 -2
  17. data/app/components/blacklight/document_title_component.html.erb +17 -0
  18. data/app/components/blacklight/document_title_component.rb +59 -0
  19. data/app/components/blacklight/facet_field_checkboxes_component.html.erb +2 -2
  20. data/app/components/blacklight/facet_field_component.rb +4 -1
  21. data/app/components/blacklight/facet_field_list_component.html.erb +2 -2
  22. data/app/components/blacklight/facet_field_no_layout_component.rb +4 -1
  23. data/app/components/blacklight/metadata_field_component.html.erb +2 -2
  24. data/app/components/blacklight/metadata_field_layout_component.html.erb +3 -1
  25. data/app/components/blacklight/metadata_field_layout_component.rb +26 -1
  26. data/app/components/blacklight/response/view_type_button_component.html.erb +4 -0
  27. data/app/components/blacklight/response/view_type_button_component.rb +38 -0
  28. data/app/components/blacklight/response/view_type_component.html.erb +2 -5
  29. data/app/components/blacklight/response/view_type_component.rb +9 -13
  30. data/app/components/blacklight/search_bar_component.rb +9 -2
  31. data/app/components/blacklight/system/dropdown_component.html.erb +4 -7
  32. data/app/components/blacklight/system/dropdown_component.rb +24 -0
  33. data/app/components/blacklight/system/flash_message_component.html.erb +1 -1
  34. data/app/components/blacklight/system/flash_message_component.rb +7 -1
  35. data/app/components/blacklight/system/modal_component.rb +7 -1
  36. data/app/controllers/concerns/blacklight/catalog.rb +1 -1
  37. data/app/helpers/blacklight/blacklight_helper_behavior.rb +3 -4
  38. data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -0
  39. data/app/helpers/blacklight/component_helper_behavior.rb +2 -2
  40. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -2
  41. data/app/presenters/blacklight/document_presenter.rb +8 -4
  42. data/app/services/blacklight/search_service.rb +1 -1
  43. data/app/views/bookmarks/_tools.html.erb +1 -1
  44. data/app/views/catalog/_citation.html.erb +1 -1
  45. data/app/views/catalog/_document.html.erb +2 -2
  46. data/app/views/catalog/_facet_layout.html.erb +2 -2
  47. data/app/views/catalog/_show_main_content.html.erb +3 -3
  48. data/app/views/catalog/email.html.erb +2 -2
  49. data/app/views/catalog/email_success.html.erb +1 -1
  50. data/app/views/catalog/facet.html.erb +3 -3
  51. data/app/views/catalog/sms.html.erb +2 -2
  52. data/app/views/catalog/sms_success.html.erb +1 -1
  53. data/blacklight.gemspec +1 -1
  54. data/config/locales/blacklight.de.yml +2 -2
  55. data/lib/blacklight/configuration.rb +50 -5
  56. data/lib/blacklight/configuration/view_config.rb +18 -5
  57. data/lib/blacklight/engine.rb +3 -1
  58. data/lib/blacklight/open_struct_with_hash_access.rb +22 -1
  59. data/lib/blacklight/search_state.rb +2 -2
  60. data/lib/blacklight/solr/facet_paginator.rb +2 -0
  61. data/lib/blacklight/solr/request.rb +31 -0
  62. data/lib/blacklight/solr/response.rb +2 -16
  63. data/lib/blacklight/solr/response/facets.rb +76 -22
  64. data/lib/blacklight/solr/response/params.rb +104 -0
  65. data/lib/blacklight/solr/search_builder_behavior.rb +57 -27
  66. data/lib/generators/blacklight/assets_generator.rb +6 -2
  67. data/lib/generators/blacklight/user_generator.rb +1 -1
  68. data/spec/components/blacklight/document_component_spec.rb +3 -3
  69. data/spec/lib/blacklight/configuration/view_config_spec.rb +1 -1
  70. data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +20 -0
  71. data/spec/models/blacklight/configuration_spec.rb +64 -0
  72. data/spec/models/blacklight/solr/facet_paginator_spec.rb +4 -0
  73. data/spec/models/blacklight/solr/request_spec.rb +62 -29
  74. data/spec/models/blacklight/solr/response/facets_spec.rb +109 -0
  75. data/spec/models/blacklight/solr/response_spec.rb +10 -0
  76. data/spec/models/blacklight/solr/search_builder_spec.rb +49 -0
  77. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +8 -9
  78. data/spec/views/catalog/index.atom.builder_spec.rb +1 -1
  79. metadata +10 -4
@@ -3,7 +3,13 @@
3
3
  module Blacklight
4
4
  module System
5
5
  class ModalComponent < ViewComponent::Base
6
- with_content_areas :prefix, :header, :title, :body, :footer
6
+ include Blacklight::ContentAreasShim
7
+
8
+ renders_one :prefix
9
+ renders_one :header
10
+ renders_one :title
11
+ renders_one :body
12
+ renders_one :footer
7
13
  end
8
14
  end
9
15
  end
@@ -198,7 +198,7 @@ module Blacklight::Catalog
198
198
  # @example
199
199
  # config.index.respond_to.txt = Proc.new { render plain: "A list of docs." }
200
200
  def additional_response_formats(format)
201
- blacklight_config.index.respond_to.each do |key, config|
201
+ blacklight_config.view_config(action_name: :index).respond_to.each do |key, config|
202
202
  format.send key do
203
203
  case config
204
204
  when false
@@ -380,7 +380,7 @@ module Blacklight::BlacklightHelperBehavior
380
380
  def show_presenter_class(_document)
381
381
  Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#show_presenter_class is deprecated; use #document_presenter_class instead')
382
382
 
383
- blacklight_config.show.document_presenter_class
383
+ blacklight_config.view_config(:show, action_name: action_name).document_presenter_class
384
384
  end
385
385
 
386
386
  # @deprecated
@@ -388,13 +388,12 @@ module Blacklight::BlacklightHelperBehavior
388
388
  def index_presenter_class(_document)
389
389
  Deprecation.warn(Blacklight::BlacklightHelperBehavior, '#index_presenter_class is deprecated; use #document_presenter_class instead')
390
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
391
+ blacklight_config.view_config(document_index_view_type, action_name: action_name).document_presenter_class
393
392
  end
394
393
 
395
394
  # @return [Class]
396
395
  def search_bar_presenter_class
397
- blacklight_config.index.search_bar_presenter_class
396
+ blacklight_config.view_config(action_name: :index).search_bar_presenter_class
398
397
  end
399
398
 
400
399
  # @!group Layout helpers
@@ -253,11 +253,13 @@ module Blacklight::CatalogHelperBehavior
253
253
  ##
254
254
  # Render the view type icon for the results view picker
255
255
  #
256
+ # @deprecated
256
257
  # @param [String] view
257
258
  # @return [String]
258
259
  def render_view_type_group_icon view
259
260
  blacklight_icon(view)
260
261
  end
262
+ deprecation_deprecate render_view_type_group_icon: 'call blacklight_icon instead'
261
263
 
262
264
  ##
263
265
  # Get the default view type classes for a view in the results view picker
@@ -94,11 +94,11 @@ module Blacklight
94
94
  end
95
95
 
96
96
  def show_doc_actions?(document = @document, options = {})
97
- filter_partials(blacklight_config.show.document_actions, { document: document }.merge(options)).any?
97
+ filter_partials(blacklight_config.view_config(:show).document_actions, { document: document }.merge(options)).any?
98
98
  end
99
99
 
100
100
  def document_actions(document, options: {})
101
- filter_partials(blacklight_config.show.document_actions, { document: document }.merge(options)).map { |_k, v| v }
101
+ filter_partials(blacklight_config.view_config(:show).document_actions, { document: document }.merge(options)).map { |_k, v| v }
102
102
  end
103
103
 
104
104
  private
@@ -101,9 +101,9 @@ module Blacklight::ConfigurationHelperBehavior
101
101
 
102
102
  # Return the label for a search view
103
103
  # @return [String]
104
- def view_label view
104
+ def view_label(view)
105
105
  view_config = blacklight_config.view[view]
106
- view_config.display_label(view)
106
+ view_config.display_label
107
107
  end
108
108
  deprecation_deprecate view_label: 'Moving to ViewConfig#display_label and Blacklight::Response::ViewTypeComponent'
109
109
 
@@ -72,9 +72,9 @@ module Blacklight
72
72
  fields += Array.wrap(view_config[:"#{base_name}_display_type_field"]) if base_name && view_config.key?(:"#{base_name}_display_type_field")
73
73
  fields += Array.wrap(view_config.display_type_field)
74
74
 
75
- if fields.empty?
76
- fields += Array.wrap(configuration.show[:"#{base_name}_display_type_field"]) if base_name && configuration.show.key?(:"#{base_name}_display_type_field")
77
- fields += Array.wrap(configuration.show.display_type_field)
75
+ if fields.empty? && show_view_config != view_config
76
+ fields += Array.wrap(show_view_config[:"#{base_name}_display_type_field"]) if base_name && show_view_config.key?(:"#{base_name}_display_type_field")
77
+ fields += Array.wrap(show_view_config.display_type_field)
78
78
  end
79
79
 
80
80
  fields += ['format'] if fields.empty? # backwards compatibility with the old default value for display_type_field
@@ -118,7 +118,11 @@ module Blacklight
118
118
  end
119
119
 
120
120
  def view_config
121
- @view_config ||= configuration.view_config(:show)
121
+ @view_config ||= show_view_config
122
+ end
123
+
124
+ def show_view_config
125
+ configuration.view_config(:show)
122
126
  end
123
127
 
124
128
  private
@@ -95,7 +95,7 @@ module Blacklight
95
95
  ##
96
96
  # The key to use to retrieve the grouped field to display
97
97
  def grouped_key_for_results
98
- blacklight_config.index.group
98
+ blacklight_config.view_config(action_name: :index).group
99
99
  end
100
100
 
101
101
  ##
@@ -1,5 +1,5 @@
1
1
  <% if render_show_doc_actions_method_from_blacklight? %>
2
- <%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'ul', classes: "#{controller_name}Tools nav nav-pills", wrapping_tag: 'li', wrapping_classes: 'nav-item', actions: document_actions(document_list, options: { document: nil }), options: { document_list: @response.documents }, url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h))) %>
2
+ <%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools", wrapping_tag: 'span', wrapping_classes: 'btn btn-outline-primary', link_classes: '', actions: document_actions(document_list, options: { document: nil }), options: { document_list: @response.documents }, url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h))) %>
3
3
  <% else %>
4
4
  <% Deprecation.warn(self, '#render_show_doc_actions is deprecated; use ActionComponents instead') %>
5
5
  <ul class="<%= controller_name %>Tools nav nav-pills">
@@ -1,5 +1,5 @@
1
1
  <%= render Blacklight::System::ModalComponent.new do |component| %>
2
- <% component.with(:title, t('blacklight.tools.citation')) %>
2
+ <% component.title { t('blacklight.tools.citation') } %>
3
3
 
4
4
  <%= render Blacklight::Document::CitationComponent.with_collection(@documents) if @documents.present? %>
5
5
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <% # container for a single doc -%>
2
- <%= render (blacklight_config.view_config(document_index_view_type).document_component || Blacklight::DocumentComponent).new(document: document, counter: document_counter_with_offset(document_counter)) do |component| %>
3
- <% component.with(blacklight_config.view_config(document_index_view_type).document_component.blank? && blacklight_config.view_config(document_index_view_type).partials.any? ? :body : :partials) do %>
2
+ <%= render (blacklight_config.view_config(document_index_view_type).document_component || Blacklight::DocumentComponent).new(presenter: document_presenter(document), counter: document_counter_with_offset(document_counter)) do |component| %>
3
+ <% component.public_send(blacklight_config.view_config(document_index_view_type).document_component.blank? && blacklight_config.view_config(document_index_view_type).partials.any? ? :body : :partial) do %>
4
4
  <%= render_document_partials document, blacklight_config.view_config(document_index_view_type).partials, component: component, document_counter: document_counter %>
5
5
  <% end %>
6
6
  <% end %>
@@ -1,8 +1,8 @@
1
1
  <%= render(Blacklight::FacetFieldComponent.new(facet_field: facet_field_presenter(facet_field, nil))) do |component| %>
2
- <% component.with(:label) do %>
2
+ <% component.label do %>
3
3
  <%= facet_field_label(facet_field.key) %>
4
4
  <% end %>
5
- <% component.with(:body) do %>
5
+ <% component.body do %>
6
6
  <%= yield %>
7
7
  <% end %>
8
8
  <% end %>
@@ -3,8 +3,8 @@
3
3
  <% @page_title = t('blacklight.search.show.title', document_title: Deprecation.silence(Blacklight::BlacklightHelperBehavior) { document_show_html_title }, application_name: application_name).html_safe %>
4
4
  <% content_for(:head) { render_link_rel_alternates } %>
5
5
 
6
- <%= render (blacklight_config.show.document_component || Blacklight::DocumentComponent).new(document: @document, component: :div, title_component: :h1, show: true) do |component| %>
7
- <% component.with(:footer) do %>
6
+ <%= render (blacklight_config.view_config(:show).document_component || Blacklight::DocumentComponent).new(presenter: document_presenter(@document), component: :div, title_component: :h1, show: true) do |component| %>
7
+ <% component.footer do %>
8
8
  <% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
9
9
  <!--
10
10
  // COinS, for Zotero among others.
@@ -17,7 +17,7 @@
17
17
 
18
18
  <%# Use :body for complete backwards compatibility (overriding the component body markup),
19
19
  but if the app explicitly opted-in to components, make the partials data available as :partials to ease migrations pain %>
20
- <% component.with(blacklight_config.show.document_component.blank? && blacklight_config.view_config(:show).partials.any? ? :body : :partials) do %>
20
+ <% component.public_send(blacklight_config.view_config(:show).document_component.blank? && blacklight_config.view_config(:show).partials.any? ? :body : :partial) do %>
21
21
  <div id="doc_<%= @document.id.to_s.parameterize %>">
22
22
  <%= render_document_partials @document, blacklight_config.view_config(:show).partials, component: component %>
23
23
  </div>
@@ -1,7 +1,7 @@
1
1
  <%= render Blacklight::System::ModalComponent.new do |component| %>
2
- <% component.with(:title, t('blacklight.email.form.title')) %>
2
+ <% component.title { t('blacklight.email.form.title') } %>
3
3
 
4
- <% component.with(:body) do %>
4
+ <% component.body do %>
5
5
  <%= render 'email_form' %>
6
6
  <% end %>
7
7
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <%= render Blacklight::System::ModalComponent.new do |component| %>
2
- <% component.with(:title, t('blacklight.email.form.title')) %>
2
+ <% component.title { t('blacklight.email.form.title') } %>
3
3
 
4
4
  <%= render partial: '/shared/flash_msg' %>
5
5
  <span data-blacklight-modal="close"></span>
@@ -1,11 +1,11 @@
1
1
  <%= render Blacklight::System::ModalComponent.new do |component| %>
2
- <% component.with(:prefix) do %>
2
+ <% component.prefix do %>
3
3
  <div class="facet-pagination top row justify-content-between">
4
4
  <%= render :partial=>'facet_pagination' %>
5
5
  </div>
6
6
  <% end %>
7
7
 
8
- <% component.with(:title, facet_field_label(@facet.key)) %>
8
+ <% component.title { facet_field_label(@facet.key) } %>
9
9
 
10
10
  <%= render partial: 'facet_index_navigation' if @facet.index_range && @display_facet.index? %>
11
11
 
@@ -13,7 +13,7 @@
13
13
  <%= render_facet_limit(@display_facet, layout: false) %>
14
14
  </div>
15
15
 
16
- <% component.with(:footer) do %>
16
+ <% component.footer do %>
17
17
  <div class="facet-pagination bottom row justify-content-between">
18
18
  <%= render :partial=>'facet_pagination' %>
19
19
  </div>
@@ -1,7 +1,7 @@
1
1
  <%= render Blacklight::System::ModalComponent.new do |component| %>
2
- <% component.with(:title, t('blacklight.sms.form.title')) %>
2
+ <% component.title { t('blacklight.sms.form.title') } %>
3
3
 
4
- <% component.with(:body) do %>
4
+ <% component.body do %>
5
5
  <%= render 'sms_form' %>
6
6
  <% end %>
7
7
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <%= render Blacklight::System::ModalComponent.new do |component| %>
2
- <% component.with(:title, t('blacklight.sms.form.title')) %>
2
+ <% component.title { t('blacklight.sms.form.title') } %>
3
3
 
4
4
  <%= render partial: '/shared/flash_msg' %>
5
5
  <span data-blacklight-modal="close"></span>
data/blacklight.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_dependency "deprecation"
33
33
  s.add_dependency "i18n", '>= 1.7.0' # added named parameters
34
34
  s.add_dependency "ostruct", '>= 0.3.2'
35
- s.add_dependency "view_component", '>= 2.23.0'
35
+ s.add_dependency "view_component", '>= 2.28.0'
36
36
 
37
37
  s.add_development_dependency "rsolr", ">= 1.0.6", "< 3" # Library for interacting with rSolr.
38
38
  s.add_development_dependency "rspec-rails", "~> 4.0.0.beta2"
@@ -3,7 +3,7 @@ de:
3
3
  pagination:
4
4
  first: '&laquo; Erste'
5
5
  last: 'Letzte &raquo;'
6
- previous: '&laquo; Voherige'
6
+ previous: '&laquo; Vorherige'
7
7
  next: 'Nächste &raquo;'
8
8
  truncate: '…'
9
9
  aria:
@@ -16,7 +16,7 @@ de:
16
16
  go_to_previous_page: Zurück zur letzten Seite
17
17
 
18
18
  pagination_compact:
19
- previous: '&laquo; Voherige'
19
+ previous: '&laquo; Vorherige'
20
20
  next: 'Nächste &raquo;'
21
21
 
22
22
  blacklight:
@@ -95,6 +95,12 @@ module Blacklight
95
95
  partials: [:show_header, :show],
96
96
  document_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
97
97
  ),
98
+ action_mapping: NestedOpenStructWithHashAccess.new(
99
+ ViewConfig,
100
+ default: { top_level_config: :index },
101
+ show: { top_level_config: :show },
102
+ citation: { parent_config: :show }
103
+ ),
98
104
  # Configurations for specific types of index views
99
105
  view: NestedOpenStructWithHashAccess.new(ViewConfig,
100
106
  list: {},
@@ -307,13 +313,35 @@ module Blacklight
307
313
  end
308
314
  alias_method :inheritable_copy, :build
309
315
 
310
- # Get a view configuration for the given view type
311
- # including default values from the index configuration
316
+ # Get a view configuration for the given view type + action. The effective
317
+ # view configuration is inherited from:
318
+ # - the configuration from blacklight_config.view with the key `view_type`
319
+ # - the configuration from blacklight_config.action_mapping with the key `action_name`
320
+ # - any parent config for the action map result above
321
+ # - the action_mapping default configuration
322
+ # - the top-level index/show view configuration
323
+ #
312
324
  # @param [Symbol,#to_sym] view_type
313
325
  # @return [Blacklight::Configuration::ViewConfig]
314
- def view_config(view_type)
315
- view_type = view_type.to_sym unless view_type.is_a? Symbol
316
- index.merge(view_type == :show ? show : view.fetch(view_type, {}))
326
+ def view_config(view_type = nil, action_name: :index)
327
+ view_type &&= view_type.to_sym
328
+ action_name &&= action_name.to_sym
329
+ action_name ||= :index
330
+
331
+ if view_type == :show
332
+ action_name = view_type
333
+ view_type = nil
334
+ end
335
+
336
+ @view_config ||= {}
337
+ @view_config[[view_type, action_name]] ||= begin
338
+ if view_type.nil?
339
+ action_config(action_name)
340
+ else
341
+ base_config = action_config(action_name)
342
+ base_config.merge(view.fetch(view_type, {}))
343
+ end
344
+ end
317
345
  end
318
346
 
319
347
  # YARD will include inline disabling as docs, cannot do multiline inside @!macro. AND this must be separate from doc block.
@@ -441,5 +469,22 @@ module Blacklight
441
469
  yield(object)
442
470
  end
443
471
  end
472
+
473
+ def action_config(action, default: :index)
474
+ action_config = action_mapping[action]
475
+ action_config ||= action_mapping[:default]
476
+
477
+ if action_config.parent_config && action_config.parent_config != :default
478
+ parent_config = action_mapping[action_config.parent_config]
479
+ raise "View configuration error: the parent configuration of #{action_config.key}, #{parent_config.key}, must not specific its own parent configuration" if parent_config.parent_config
480
+
481
+ action_config = action_config.reverse_merge(parent_config)
482
+ end
483
+ action_config = action_config.reverse_merge(action_mapping[:default]) if action_config != action_mapping[:default]
484
+
485
+ action_config = action_config.reverse_merge(self[action_config.top_level_config]) if action_config.top_level_config
486
+ action_config = action_config.reverse_merge(show) if default == :show && action_config.top_level_config != :show
487
+ action_config.reverse_merge(index)
488
+ end
444
489
  end
445
490
  end
@@ -11,21 +11,26 @@ class Blacklight::Configuration
11
11
  # @return [String, Symbol] solr field to use to render a document title
12
12
  # @!attribute display_type_field
13
13
  # @return [String, Symbol] solr field to use to render format-specific partials
14
+ # @!attribute icon
15
+ # @return [String, Symbol] icon file to use in the view picker
14
16
  # @!attribute document_actions
15
17
  # @return [NestedOpenStructWithHashAccess{Symbol => Blacklight::Configuration::ToolConfig}] 'tools' to render for each document
16
18
  def search_bar_presenter_class
17
19
  super || Blacklight::SearchBarPresenter
18
20
  end
19
21
 
20
- def display_label(key)
22
+ def display_label(deprecated_key = nil, **options)
23
+ Deprecation.warn('Passing the key argument to ViewConfig#display_label is deprecated') if deprecated_key.present?
24
+
21
25
  I18n.t(
22
- :"blacklight.search.view_title.#{key}",
26
+ :"blacklight.search.view_title.#{deprecated_key || key}",
23
27
  default: [
24
- :"blacklight.search.view.#{key}",
28
+ :"blacklight.search.view.#{deprecated_key || key}",
25
29
  label,
26
30
  title,
27
- key.to_s.humanize
28
- ]
31
+ (deprecated_key || key).to_s.humanize
32
+ ],
33
+ **options
29
34
  )
30
35
  end
31
36
 
@@ -38,6 +43,10 @@ class Blacklight::Configuration
38
43
  def document_presenter_class
39
44
  super || Blacklight::ShowPresenter
40
45
  end
46
+
47
+ def to_h
48
+ super.merge(document_presenter_class: document_presenter_class)
49
+ end
41
50
  end
42
51
 
43
52
  class Index < ViewConfig
@@ -52,6 +61,10 @@ class Blacklight::Configuration
52
61
  def document_presenter_class
53
62
  super || Blacklight::IndexPresenter
54
63
  end
64
+
65
+ def to_h
66
+ super.merge(document_presenter_class: document_presenter_class)
67
+ end
55
68
  end
56
69
  end
57
70
  end
@@ -8,7 +8,9 @@ module Blacklight
8
8
  # BlacklightHelper is needed by all helpers, so we inject it
9
9
  # into action view base here.
10
10
  initializer 'blacklight.helpers' do
11
- ActionView::Base.include BlacklightHelper
11
+ config.after_initialize do
12
+ ActionView::Base.include BlacklightHelper
13
+ end
12
14
  end
13
15
 
14
16
  # This makes our rake tasks visible.
@@ -4,7 +4,9 @@ module Blacklight
4
4
  ##
5
5
  # An OpenStruct that responds to common Hash methods
6
6
  class OpenStructWithHashAccess < OpenStruct
7
- delegate :keys, :each, :map, :has_key?, :key?, :include?, :empty?, :length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!, :replace, :fetch, :to_json, :as_json, :any?, to: :to_h
7
+ delegate :keys, :each, :map, :has_key?, :key?, :include?, :empty?,
8
+ :length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!,
9
+ :replace, :fetch, :to_json, :as_json, :any?, to: :to_h
8
10
 
9
11
  ##
10
12
  # Expose the internal hash
@@ -42,8 +44,27 @@ module Blacklight
42
44
  @table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
43
45
  end
44
46
 
47
+ def reverse_merge(other_hash)
48
+ self.class.new to_h.reverse_merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
49
+ end
50
+
45
51
  def deep_dup
46
52
  self.class.new @table.deep_dup
47
53
  end
54
+
55
+ if Rails.version < '6'
56
+ # Ported from Rails 6 to fix an incompatibility with ostruct
57
+ def try(method_name = nil, *args, &block)
58
+ if method_name.nil? && block_given?
59
+ if b.arity.zero?
60
+ instance_eval(&block)
61
+ else
62
+ yield self
63
+ end
64
+ elsif respond_to?(method_name)
65
+ public_send(method_name, *args, &b)
66
+ end
67
+ end
68
+ end
48
69
  end
49
70
  end