Skip to content

Commit cb99523

Browse files
authored
Merge pull request #3733 from projectblacklight/doc-comp
2 parents a5c7951 + 033ad4c commit cb99523

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

app/components/blacklight/document_component.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,24 @@ class DocumentComponent < Blacklight::Component
3434

3535
# The document title with some reasonable default behavior
3636
renders_one :title, (lambda do |component: nil, **kwargs|
37-
component ||= view_config.title_component || Blacklight::DocumentTitleComponent
37+
component ||= view_config.document_title_component
3838

39-
component.new(counter: @counter, presenter: @presenter, as: @title_component, actions: !@show, link_to_document: !@show, document_component: self, **kwargs)
39+
component&.new(counter: @counter, presenter: @presenter, as: @title_component, actions: !@show, link_to_document: !@show, document_component: self, **kwargs)
4040
end)
4141

4242
renders_one :embed, (lambda do |static_content = nil, component: nil, **kwargs|
4343
next static_content if static_content.present?
4444

45-
component ||= view_config.embed_component
46-
47-
next unless component
48-
49-
component.new(presenter: @presenter, document_counter: @document_counter, **kwargs)
45+
component ||= view_config.document_embed_component
46+
component&.new(presenter: @presenter, document_counter: @document_counter, **kwargs)
5047
end)
5148

5249
# The primary metadata section
5350
renders_one :metadata, (lambda do |static_content = nil, component: nil, fields: nil, **kwargs|
5451
next static_content if static_content.present?
5552

56-
component ||= view_config.metadata_component || Blacklight::DocumentMetadataComponent
57-
component.new(fields: fields || @presenter&.field_presenters || [], **kwargs)
53+
component ||= view_config.document_metadata_component
54+
component&.new(fields: fields || @presenter&.field_presenters || [], **kwargs)
5855
end)
5956

6057
# Additional metadata sections
@@ -63,9 +60,9 @@ class DocumentComponent < Blacklight::Component
6360
renders_one :thumbnail, (lambda do |image_options_or_static_content = {}, component: nil, **kwargs|
6461
next image_options_or_static_content if image_options_or_static_content.is_a? String
6562

66-
component ||= view_config.thumbnail_component || Blacklight::Document::ThumbnailComponent
63+
component ||= view_config.document_thumbnail_component
6764

68-
component.new(presenter: @presenter, counter: @counter, image_options: image_options_or_static_content, **kwargs)
65+
component&.new(presenter: @presenter, counter: @counter, image_options: image_options_or_static_content, **kwargs)
6966
end)
7067

7168
# A container for partials rendered using the view config partials configuration. Its use is discouraged, but necessary until
@@ -119,7 +116,7 @@ def classes
119116

120117
def before_render
121118
with_title unless title
122-
with_thumbnail unless thumbnail || show?
119+
with_thumbnail unless thumbnail
123120
with_metadata(fields: presenter.field_presenters, show: @show) unless metadata
124121
with_embed unless embed
125122

lib/blacklight/configuration.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def initialized_default_configuration?
152152
json_presenter_class: Blacklight::JsonPresenter,
153153
# component class used to render a document
154154
document_component: Blacklight::DocumentComponent,
155+
document_embed_component: nil,
156+
document_metadata_component: Blacklight::DocumentMetadataComponent,
157+
document_thumbnail_component: Blacklight::Document::ThumbnailComponent,
158+
document_title_component: Blacklight::DocumentTitleComponent,
155159
sidebar_component: Blacklight::Search::SidebarComponent,
156160
dropdown_component: Blacklight::System::DropdownComponent,
157161
# solr field to use to render a document title
@@ -189,6 +193,7 @@ def initialized_default_configuration?
189193
# document presenter class used by helpers and views
190194
document_presenter_class: nil,
191195
document_component: Blacklight::DocumentComponent,
196+
document_thumbnail_component: nil,
192197
show_tools_component: Blacklight::Document::ShowToolsComponent,
193198
show_header_tools_component: nil,
194199
document_header_component: Blacklight::Document::PageHeaderComponent,

lib/blacklight/configuration/view_config.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ class ViewConfig < Blacklight::OpenStructWithHashAccess
88
# @return [Class] document presenter class used by helpers and views
99
# @!attribute document_component
1010
# @return [Class] component class used to render a document; defaults to Blacklight::DocumentComponent
11+
# @!attribute document_title_component
12+
# @return [Class] component class used to render a document title
13+
# @!attribute document_metadata_component
14+
# @return [Class] component class used to render the document metadata
15+
# @!attribute document_thumbnail_component
16+
# @return [Class] component class used to render a document thumbnail
17+
# @!attribute document_embed_component
18+
# @return [Class] component class used to render a document embed
1119
# @!attribute title_field
1220
# @return [String, Symbol] solr field to use to render a document title
1321
# @!attribute display_type_field
@@ -46,6 +54,28 @@ def title_field=(value)
4654
end
4755
end
4856

57+
# Provide backwards compatibility with the configuration keys without the document_ prefix
58+
def title_component(*) = document_title_component(*)
59+
def metadata_component(*) = document_metadata_component(*)
60+
def thumbnail_component(*) = document_thumbnail_component(*)
61+
def embed_component(*) = document_embed_component(*)
62+
63+
def title_component=(value)
64+
self.document_title_component = value
65+
end
66+
67+
def metadata_component=(value)
68+
self.document_metadata_component = value
69+
end
70+
71+
def thumbnail_component=(value)
72+
self.document_thumbnail_component = value
73+
end
74+
75+
def embed_component=(value)
76+
self.document_embed_component = value
77+
end
78+
4979
class Show < ViewConfig
5080
# @!attribute route
5181
# @return [Hash] Default route parameters for 'show' requests.

0 commit comments

Comments
 (0)