Sha256: d7eb2366f556f4ac522604ed7395ef9915ffb5de7a88acd3026eb55c1303fe1c

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module Blacklight
  module Document
    # Render a bookmark widget to bookmark / unbookmark a document
    class ActionComponent < Blacklight::Component
      with_collection_parameter :action

      # @param [Blacklight::Document] document
      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

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

        helpers.partial_from_blacklight?(@action.partial)
      end

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

      # 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)
      def url
        Deprecation.silence(Blacklight::ComponentHelperBehavior) do
          helpers.document_action_path(@action, @url_opts.merge(({ id: @document } if @document) || {}))
        end
      end

      def key
        @action.key
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
blacklight-7.33.1 app/components/blacklight/document/action_component.rb
blacklight-7.33.0 app/components/blacklight/document/action_component.rb
blacklight-7.32.0 app/components/blacklight/document/action_component.rb
blacklight-7.31.0 app/components/blacklight/document/action_component.rb
blacklight-7.30.0 app/components/blacklight/document/action_component.rb
blacklight-7.29.0 app/components/blacklight/document/action_component.rb
blacklight-7.28.0 app/components/blacklight/document/action_component.rb
blacklight-7.27.1 app/components/blacklight/document/action_component.rb
blacklight-7.27.0 app/components/blacklight/document/action_component.rb
blacklight-7.26.1 app/components/blacklight/document/action_component.rb
blacklight-7.26.0 app/components/blacklight/document/action_component.rb
blacklight-7.25.3 app/components/blacklight/document/action_component.rb
blacklight-7.25.2 app/components/blacklight/document/action_component.rb
blacklight-7.25.1 app/components/blacklight/document/action_component.rb
blacklight-7.25.0 app/components/blacklight/document/action_component.rb