Class: Blacklight::Document::ActionComponent
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Blacklight::Document::ActionComponent
- Defined in:
- app/components/blacklight/document/action_component.rb
Overview
Render a bookmark widget to bookmark / unbookmark a document
Direct Known Subclasses
Constant Summary
Constants inherited from Component
Instance Method Summary collapse
-
#initialize(document:, action:, options: {}, url_opts: {}, id: nil, link_classes: 'nav-link') ⇒ ActionComponent
constructor
A new instance of ActionComponent.
- #key ⇒ Object
- #label ⇒ Object
- #link_to_modal_control ⇒ Object
- #render_control ⇒ Object
- #render_partial ⇒ Object
-
#url ⇒ Object
Action buttons get their URLs in one of three ways: - the action configuration explicitly specifies a helper method to call - a url route is inferred for ActiveModel-compliant objects (the default; note that, although Rails routing is available here, we still call out to helpers regardless, because that’s where applications might have overridden the default Rails routing behavior) - calling out to an implicit helper method with a conventional name (unlikely).
- #using_default_document_action? ⇒ Boolean
Methods inherited from Component
Constructor Details
#initialize(document:, action:, options: {}, url_opts: {}, id: nil, link_classes: 'nav-link') ⇒ ActionComponent
Returns a new instance of ActionComponent.
10 11 12 13 14 15 16 17 |
# File 'app/components/blacklight/document/action_component.rb', line 10 def initialize(document:, action:, options: {}, url_opts: {}, id: nil, link_classes: 'nav-link') @document = document @action = action @options = @url_opts = url_opts @id = id || @action.fetch(:id, "#{@action.name}Link") @link_classes = link_classes end |
Instance Method Details
#key ⇒ Object
64 65 66 |
# File 'app/components/blacklight/document/action_component.rb', line 64 def key @action.key end |
#label ⇒ Object
42 43 44 |
# File 'app/components/blacklight/document/action_component.rb', line 42 def label t("blacklight.tools.#{@action.name}", default: @action.label || @action.name.to_s.humanize) end |
#link_to_modal_control ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/components/blacklight/document/action_component.rb', line 29 def link_to_modal_control link_to label, url, id: @id, class: @link_classes, data: {}.merge(({ blacklight_modal: "trigger", turbo: false } if @action.modal != false) || {}) end |
#render_control ⇒ Object
19 20 21 22 23 |
# File 'app/components/blacklight/document/action_component.rb', line 19 def render_control return link_to_modal_control if using_default_document_action? render_partial end |
#render_partial ⇒ Object
37 38 39 40 |
# File 'app/components/blacklight/document/action_component.rb', line 37 def render_partial render(partial: @action.partial || @action.name.to_s, locals: { document: @document, document_action_config: @action }.merge(@options)) end |
#url ⇒ Object
Action buttons get their URLs in one of three ways:
-
the action configuration explicitly specifies a helper method to call
-
a url route is inferred for ActiveModel-compliant objects (the default;
note that, although Rails routing is available here, we still call out to helpers regardless, because that's where applications might have overridden the default Rails routing behavior)
-
calling out to an implicit helper method with a conventional name (unlikely)
53 54 55 56 57 58 59 60 61 62 |
# File 'app/components/blacklight/document/action_component.rb', line 53 def url url_opts = @url_opts.merge(({ id: @document } if @document) || {}) if @action.path helpers.public_send(@action.path, url_opts) elsif url_opts[:id].class.respond_to?(:model_name) helpers.url_for([@action.key.to_sym, url_opts[:id]]) else helpers.public_send("#{@action.key}_#{helpers.controller_name}_path", url_opts) end end |
#using_default_document_action? ⇒ Boolean
25 26 27 |
# File 'app/components/blacklight/document/action_component.rb', line 25 def using_default_document_action? @action.component || @action.partial == 'document_action' end |