Skip to content

Commit 9a1cd21

Browse files
committed
Pull actions back to the DocumentComponent
1 parent a5c7951 commit 9a1cd21

File tree

5 files changed

+37
-38
lines changed

5 files changed

+37
-38
lines changed

app/components/blacklight/document_component.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
<%= body %>
1313
<% else %>
1414
<div class="document-main-section">
15-
<%= title %>
15+
<header class="documentHeader row">
16+
<%= title %>
17+
<% actions.each do |action| %>
18+
<%= action %>
19+
<% end %>
20+
</header>
21+
1622
<%= embed %>
1723
<%= content %>
1824
<%= metadata %>

app/components/blacklight/document_component.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DocumentComponent < Blacklight::Component
3636
renders_one :title, (lambda do |component: nil, **kwargs|
3737
component ||= view_config.title_component || Blacklight::DocumentTitleComponent
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, link_to_document: !@show, document_component: self, **kwargs)
4040
end)
4141

4242
renders_one :embed, (lambda do |static_content = nil, component: nil, **kwargs|
@@ -60,6 +60,8 @@ class DocumentComponent < Blacklight::Component
6060
# Additional metadata sections
6161
renders_many :metadata_sections
6262

63+
renders_one :actions
64+
6365
renders_one :thumbnail, (lambda do |image_options_or_static_content = {}, component: nil, **kwargs|
6466
next image_options_or_static_content if image_options_or_static_content.is_a? String
6567

@@ -72,9 +74,6 @@ class DocumentComponent < Blacklight::Component
7274
# the ecosystem fully adopts view components.
7375
renders_many :partials
7476

75-
# Backwards compatibility
76-
renders_one :actions
77-
7877
# rubocop:disable Metrics/ParameterLists
7978
# @param document [Blacklight::DocumentPresenter]
8079
# @param partials [Array, nil] view partial names that should be used to provide content for the `partials` slot
@@ -130,12 +129,29 @@ def before_render
130129
end
131130
end
132131

132+
# Content for the document actions area
133+
def actions
134+
return [] if hide_actions?
135+
136+
if block_given?
137+
@has_actions_slot = true
138+
return super
139+
end
140+
141+
(@has_actions_slot && get_slot(:actions)) ||
142+
[helpers.render_index_doc_actions(presenter.document, wrapping_class: 'index-document-functions col-sm-3 col-lg-2 mb-4 mb-sm-0')]
143+
end
144+
133145
private
134146

135147
delegate :view_config, to: :@presenter
136148

137149
attr_reader :document_counter, :counter, :document, :presenter, :view_partials
138150

151+
def hide_actions?
152+
show?
153+
end
154+
139155
def show?
140156
@show
141157
end
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
<header class="documentHeader row">
2-
<%= content_tag @as, class: @classes do %>
3-
<% before_titles.each do |t| %>
4-
<%= t %>
5-
<% end %>
6-
7-
<%= counter -%><%= title -%>
8-
9-
<% after_titles.each do |t| %>
10-
<%= t %>
11-
<% end %>
1+
<%= content_tag @as, class: @classes do %>
2+
<% before_titles.each do |t| %>
3+
<%= t %>
124
<% end %>
135

14-
<% actions.each do |action| %>
15-
<%= action %>
6+
<%= counter -%><%= title -%>
7+
8+
<% after_titles.each do |t| %>
9+
<%= t %>
1610
<% end %>
17-
</header>
11+
<% end %>

app/components/blacklight/document_title_component.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ module Blacklight
44
class DocumentTitleComponent < Blacklight::Component
55
renders_many :before_titles
66
renders_many :after_titles
7-
renders_many :actions
87

98
# rubocop:disable Metrics/ParameterLists
10-
def initialize(title = nil, presenter:, as: :h3, counter: nil, classes: 'index_title document-title-heading col h5', link_to_document: true, document_component: nil,
11-
actions: true)
9+
def initialize(title = nil, presenter:, as: :h3, counter: nil, classes: 'index_title document-title-heading col h5', link_to_document: true, document_component: nil)
1210
@title = title
1311
@presenter = presenter
1412
@as = as || :h3
1513
@counter = counter
1614
@classes = classes
1715
@link_to_document = link_to_document
1816
@document_component = document_component
19-
@actions = actions
2017
@document = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(@presenter.document,
2118
"Don't use the @document instance variable. Instead use @presenter",
2219
ActiveSupport::Deprecation.new)
@@ -34,20 +31,6 @@ def title
3431
end
3532
end
3633

37-
# Content for the document actions area
38-
def actions
39-
return [] unless @actions
40-
41-
if block_given?
42-
@has_actions_slot = true
43-
return super
44-
end
45-
46-
(@has_actions_slot && get_slot(:actions)) ||
47-
([@document_component&.actions] if @document_component&.actions.present?) ||
48-
[helpers.render_index_doc_actions(presenter.document, wrapping_class: 'index-document-functions col-sm-3 col-lg-2 mb-4 mb-sm-0')]
49-
end
50-
5134
def counter
5235
return unless @counter
5336

app/views/catalog/_show_main_content.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<% document_component = blacklight_config.view_config(:show).document_component -%>
66
<%= render document_component.new(document: document_presenter(@document), component: :div, show: true, partials: blacklight_config.view_config(:show).partials) do |component| %>
7-
<% component.with_title(as: 'h1', classes: '', link_to_document: false, actions: false) %>
7+
<% component.with_title(as: 'h1', classes: '', link_to_document: false) %>
88
<% component.with_footer do %>
99
<% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
1010
<!-- COinS, for Zotero among others. -->

0 commit comments

Comments
 (0)