Class: Blacklight::Document::ActionComponent

Inherits:
ViewComponent::Base
  • 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

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

#keyObject



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

def key
  @action.key
end

#labelObject



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

def label
  Deprecation.silence(Blacklight::ComponentHelperBehavior) do
    helpers.document_action_label(@action.name, @action)
  end
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)



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

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)


19
20
21
22
23
24
# File 'app/components/blacklight/document/action_component.rb', line 19

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

  helpers.partial_from_blacklight?(@action.partial)
end