Skip to content

Commit

Permalink
Add icons to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Genia Kazymova committed Oct 9, 2024
1 parent 456f712 commit 9e9b6cf
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render_control %>
12 changes: 12 additions & 0 deletions app/components/trln_argon/document/action_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module TrlnArgon
module Document
class ActionComponent < Blacklight::Document::ActionComponent
# rubocop:disable Style/StringConcatenation
def label
(content_tag(:i, '', class: @action[:icon].to_s, 'aria-hidden' => true) + ' ' if @action.key?(:icon)).to_s +
t("blacklight.tools.#{@action.name}", default: @action.label || @action.name.to_s.humanize).html_safe
end
# rubocop:enable Style/StringConcatenation
end
end
end
13 changes: 13 additions & 0 deletions app/components/trln_argon/document/show_tools_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div id="document-tools" aria-labelledby="toolsLabel">
<h2 class="sr-only" id="toolsLabel">Tools</h2>
<%= render Blacklight::Document::ActionsComponent.new(
document: document,
tag: 'ul',
classes: "#{controller_name}Tools nav nav-pills",
wrapping_tag: 'li',
wrapping_classes: "#{config.name}",
actions: actions,
link_classes: "btn btn-outline-secondary",
url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h)
) %>
</div>
6 changes: 6 additions & 0 deletions app/components/trln_argon/document/show_tools_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module TrlnArgon
module Document
class ShowToolsComponent < Blacklight::Document::ShowToolsComponent
end
end
end
6 changes: 0 additions & 6 deletions app/views/catalog/_document_action.html.erb

This file was deleted.

15 changes: 2 additions & 13 deletions app/views/catalog/_show_tools.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,5 @@

-%>

<div id="document-tools" aria-labelledby="toolsLabel">
<h2 class="visually-hidden" id="toolsLabel">Tools</h2>
<%= render Blacklight::Document::ActionsComponent.new(
document: @document,
tag: 'ul',
classes: "#{controller_name}Tools nav nav-pills",
wrapping_tag: 'li',
wrapping_classes: "#{config.name}",
actions: document_actions(@document),
link_classes: "btn btn-outline-secondary",
url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h)
) %>
</div>
<% Blacklight.deprecation.warn('The partial _show_tools.html.erb will be removed in Blacklight 9.0. Configure blacklight_config.show.show_tools_component instead (default Blacklight::Document::ShowToolsComponent).') unless local_assigns[:silence_deprecation] %>
<%= render TrlnArgon::Document::ShowToolsComponent.new(document: @document) %>
2 changes: 1 addition & 1 deletion config/initializers/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# See configurations in lib/trln_argon/controller_override.rb
module Blacklight
class Configuration

extend ActiveSupport::Autoload

eager_autoload do
autoload :HomeFacetField
autoload :ShowSubHeaderField
Expand Down
18 changes: 12 additions & 6 deletions lib/trln_argon/controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,38 @@ module ControllerOverride
icon: 'fa fa-envelope',
callback: :email_action,
path: :email_path,
validator: :validate_email_params)
validator: :validate_email_params,
component: TrlnArgon::Document::ActionComponent)
config.add_show_tools_partial(:sms,
icon: 'fa fa-commenting',
if: :render_sms_action?,
callback: :sms_action,
path: :sms_path,
validator: :validate_sms_params)
validator: :validate_sms_params,
component: TrlnArgon::Document::ActionComponent)
config.add_show_tools_partial(:citation,
icon: 'fa fa-quote-left')
icon: 'fa fa-quote-left',
component: TrlnArgon::Document::ActionComponent)
config.add_show_tools_partial(:ris,
icon: 'fa fa-download',
if: :render_ris_action?,
modal: false,
path: :ris_path)
path: :ris_path,
component: TrlnArgon::Document::ActionComponent)
config.add_show_tools_partial(:refworks,
icon: 'fa fa-list',
if: :render_refworks_action?,
new_window: true,
modal: false,
path: :refworks_path)
path: :refworks_path,
component: TrlnArgon::Document::ActionComponent)
config.add_show_tools_partial(:share_bookmarks,
icon: 'fa fa-share',
if: :render_sharebookmarks_action?,
new_window: false,
modal: false,
path: :sharebookmarks_path)
path: :sharebookmarks_path,
component: TrlnArgon::Document::ActionComponent)
config.add_show_tools_partial(:bookmark,
partial: 'bookmark_control',
if: :render_bookmarks_control?)
Expand Down
9 changes: 0 additions & 9 deletions lib/trln_argon/view_helpers/trln_argon_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,6 @@ def show_configured_fields_and_values(config, document)
end.compact
end

def add_icon_to_action_label(document_action_config)
if document_action_config.key?(:icon)
content_tag(:i, '', class: (document_action_config[:icon]).to_s, 'aria-hidden' => 'true') + ' ' +
document_action_label(document_action_config.key, document_action_config).html_safe
else
document_action_label(document_action_config.key, document_action_config).html_safe
end
end

def join_with_comma_semicolon_fallback(options = {})
return options[:value].join('; ') if options[:value].any? { |v| v.include?(',') }

Expand Down
33 changes: 0 additions & 33 deletions spec/lib/trln_argon/view_helpers/trln_argon_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,6 @@
end
end

describe '#add_icon_to_action_label' do
let(:tool_with_label) do
Blacklight::Configuration::ToolConfig.new(
icon: 'fa fa-download',
if: :render_ris_action?,
modal: false,
path: :ris_path
)
end
let(:tool_without_label) do
Blacklight::Configuration::ToolConfig.new(
if: :render_ris_action?,
modal: false,
path: :ris_path
)
end

before { allow(helper).to receive(:document_action_label).and_return('<li>Action Label</li>') }

context 'the configuration provides an icon' do
it 'adds an icon to the document action label' do
expect(helper.add_icon_to_action_label(tool_with_label)).to eq(
'<i class="fa fa-download" aria-hidden="true"></i> <li>Action Label</li>'
)
end
end
context 'the configuration does not provide an icon' do
it 'does not add an icon to the document action label' do
expect(helper.add_icon_to_action_label(tool_without_label)).to eq('<li>Action Label</li>')
end
end
end

describe 'join_with_comma_semicolon_fallback' do
context 'when values do not already contain commas' do
let(:options) { { value: %w[Book Video] } }
Expand Down

0 comments on commit 9e9b6cf

Please sign in to comment.