Skip to content

Commit e6189a1

Browse files
committed
Pull actions back to the DocumentComponent
1 parent eb33224 commit e6189a1

File tree

5 files changed

+39
-38
lines changed

5 files changed

+39
-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: 22 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.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, link_to_document: !@show, document_component: self, **kwargs)
4040
end)
4141

4242
renders_one :embed, (lambda do |static_content = nil, component: nil, **kwargs|
@@ -57,6 +57,8 @@ class DocumentComponent < Blacklight::Component
5757
# Additional metadata sections
5858
renders_many :metadata_sections
5959

60+
renders_one :actions
61+
6062
renders_one :thumbnail, (lambda do |image_options_or_static_content = {}, component: nil, **kwargs|
6163
next image_options_or_static_content if image_options_or_static_content.is_a? String
6264

@@ -69,9 +71,6 @@ class DocumentComponent < Blacklight::Component
6971
# the ecosystem fully adopts view components.
7072
renders_many :partials
7173

72-
# Backwards compatibility
73-
renders_one :actions
74-
7574
# rubocop:disable Metrics/ParameterLists
7675
# @param document [Blacklight::DocumentPresenter]
7776
# @param partials [Array, nil] view partial names that should be used to provide content for the `partials` slot
@@ -127,12 +126,31 @@ def before_render
127126
end
128127
end
129128

129+
# Content for the document actions area
130+
def actions
131+
return [] if hide_actions?
132+
133+
if block_given?
134+
return super
135+
end
136+
137+
if actions?
138+
return Array(super)
139+
end
140+
141+
Array(helpers.render_index_doc_actions(presenter.document, wrapping_class: 'index-document-functions col-sm-3 col-lg-2 mb-4 mb-sm-0'))
142+
end
143+
130144
private
131145

132146
delegate :view_config, to: :@presenter
133147

134148
attr_reader :document_counter, :counter, :document, :presenter, :view_partials
135149

150+
def hide_actions?
151+
show?
152+
end
153+
136154
def show?
137155
@show
138156
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(id: 'document', 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)