Class: Blacklight::Document::ActionComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/document/action_component.rb

Overview

Render a bookmark widget to bookmark / unbookmark a document

Instance Method Summary collapse

Methods inherited from Component

reset_compiler!, sidecar_files, upstream_sidecar_files

Constructor Details

#initialize(document:, action:, options: {}, url_opts: {}, id: nil, link_classes: 'nav-link') ⇒ ActionComponent

Returns a new instance of ActionComponent.

Parameters:



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 = options
  @url_opts = url_opts
  @id = id || @action.fetch(:id, "#{@action.name}Link")
  @link_classes = link_classes
end

Instance Method Details

#labelObject



44
45
46
47
48
# File 'app/components/blacklight/document/action_component.rb', line 44

def label
  Deprecation.silence(Blacklight::ComponentHelperBehavior) do
    helpers.document_action_label(@action.name, @action)
  end
end


32
33
34
35
36
37
38
# File 'app/components/blacklight/document/action_component.rb', line 32

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_controlObject



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_partialObject



40
41
42
# File 'app/components/blacklight/document/action_component.rb', line 40

def render_partial
  helpers.render(partial: @action.partial || @action.name.to_s, locals: { document: @document, document_action_config: @action }.merge(@options))
end

#urlObject

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)



57
58
59
60
61
# File 'app/components/blacklight/document/action_component.rb', line 57

def url
  Deprecation.silence(Blacklight::ComponentHelperBehavior) do
    helpers.document_action_path(@action, @url_opts.merge(({ id: @document } if @document) || {}))
  end
end

#using_default_document_action?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'app/components/blacklight/document/action_component.rb', line 25

def using_default_document_action?
  return true if @action.component
  return false unless @action.partial == 'document_action'

  helpers.partial_from_blacklight?(@action.partial)
end