Skip to content

Commit adf2f2a

Browse files
committed
Extract Blacklight::Configuration#defaults to contain truly shared configuration between search + document views.
1 parent eb33224 commit adf2f2a

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

lib/blacklight/configuration.rb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,35 @@ def initialized_default_configuration?
142142
# set to nil if a checkbox is prefered to the icon
143143
property :bookmark_icon_component, default: Blacklight::Icons::BookmarkIconComponent
144144

145-
# @!attribute index
146-
# General configuration for all views
145+
# @!attribute defaults
146+
# Default configuration for all views
147147
# @return [Blacklight::Configuration::ViewConfig::Index]
148-
property :index, default: ViewConfig::Index.new(
148+
property :defaults, default: ViewConfig.new(
149149
# document presenter class used by helpers and views
150150
document_presenter_class: nil,
151-
# document presenter used for json responses
152-
json_presenter_class: Blacklight::JsonPresenter,
153151
# component class used to render a document
154152
document_component: Blacklight::DocumentComponent,
155153
document_embed_component: nil,
156154
document_metadata_component: Blacklight::DocumentMetadataComponent,
157155
document_thumbnail_component: Blacklight::Document::ThumbnailComponent,
158156
document_title_component: Blacklight::DocumentTitleComponent,
159-
sidebar_component: Blacklight::Search::SidebarComponent,
160-
dropdown_component: Blacklight::System::DropdownComponent,
161157
# solr field to use to render a document title
162158
title_field: nil,
163159
# solr field to use to render format-specific partials
164-
display_type_field: nil,
160+
display_type_field: nil
161+
)
162+
163+
# @!attribute index
164+
# General configuration for search views
165+
# @return [Blacklight::Configuration::ViewConfig::Index]
166+
property :index, default: ViewConfig::Index.new(
167+
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
168+
# document presenter used for json responses
169+
json_presenter_class: Blacklight::JsonPresenter,
170+
sidebar_component: Blacklight::Search::SidebarComponent,
171+
dropdown_component: Blacklight::System::DropdownComponent,
165172
# the "field access" key to use to look up the document display fields
166173
document_fields_key: :index_fields,
167-
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
168174
collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
169175
# what field, if any, to use to render grouped results
170176
group: false,
@@ -190,9 +196,7 @@ def initialized_default_configuration?
190196
# Additional configuration when displaying a single document
191197
# @return [Blacklight::Configuration::ViewConfig::Show]
192198
property :show, default: ViewConfig::Show.new(
193-
# document presenter class used by helpers and views
194-
document_presenter_class: nil,
195-
document_component: Blacklight::DocumentComponent,
199+
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
196200
document_thumbnail_component: nil,
197201
show_tools_component: Blacklight::Document::ShowToolsComponent,
198202
show_header_tools_component: nil,
@@ -205,7 +209,6 @@ def initialized_default_configuration?
205209
# Set this to a hash with additional arguments to merge into the route,
206210
# or set `controller: :current` to route to the current controller.
207211
route: nil,
208-
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
209212
header_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
210213
)
211214

@@ -214,8 +217,8 @@ def initialized_default_configuration?
214217
# @return [Hash{Symbol => Blacklight::Configuration::ViewConfig}]
215218
property :action_mapping, default: NestedOpenStructWithHashAccess.new(
216219
ViewConfig,
217-
default: { top_level_config: :index },
218-
show: { top_level_config: :show },
220+
default: { top_level_config: :index, default_top_level_config: :defaults },
221+
show: { top_level_config: :show, default_top_level_config: :index },
219222
citation: { parent_config: :show },
220223
email_record: { top_level_config: :email },
221224
sms_record: { top_level_config: :sms }
@@ -660,7 +663,12 @@ def action_config(action, default: :index)
660663

661664
action_config = action_config.reverse_merge(self[action_config.top_level_config]) if action_config.top_level_config
662665
action_config = action_config.reverse_merge(show) if default == :show && action_config.top_level_config != :show
663-
action_config.reverse_merge(index)
666+
action_config = action_config.reverse_merge(self[action_config.default_top_level_config])
667+
668+
# provide backwards compatibility for e.g. the show action falling back on the index defaults
669+
action_config = action_config.reverse_merge(defaults) if action_config.default_top_level_config == :index
670+
671+
action_config
664672
end
665673
end
666674
end

spec/views/catalog/_document.html.erb_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
stub_template "catalog/_a_default.html.erb" => "a_partial"
1717
stub_template "catalog/_b_default.html.erb" => "b_partial"
1818
stub_template "catalog/_c_default.html.erb" => "c_partial"
19-
render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: blacklight_config.index }
19+
render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: blacklight_config.view_config(:index) }
2020
expect(rendered).to match /a_partial/
2121
expect(rendered).to match /b_partial/
2222
expect(rendered).to match /c_partial/
@@ -38,7 +38,7 @@ def call
3838
end
3939

4040
it 'renders the document component' do
41-
render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: blacklight_config.index }
41+
render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: blacklight_config.view_config(:index) }
4242
expect(rendered).to match /blah/
4343
end
4444
end

0 commit comments

Comments
 (0)