Sha256: 36c6dcfeb2b4c7a67a5370bcc472369df4e7fb60a08dfe275df5fa749ade4e41

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Blacklight
  module Document
    # Render citations for the document
    class CitationComponent < ::ViewComponent::Base
      DEFAULT_FORMATS = {
        'blacklight.citation.mla': :export_as_mla_citation_txt,
        'blacklight.citation.apa': :export_as_apa_citation_txt,
        'blacklight.citation.chicago': :export_as_chicago_citation_txt
      }.freeze

      with_collection_parameter :document

      # @param [Blacklight::Document] document
      # @param [Hash<String => Symbol>] map of citation format names (suspiciously, i18n keys
      #   for them) to document methods that return the formatted citation.
      def initialize(document:, formats: DEFAULT_FORMATS)
        @document = document
        @formats = formats.select { |_k, v| @document.respond_to?(v) }
      end

      # @return [String]
      def title
        Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
          helpers.document_heading(@document)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blacklight-7.24.0 app/components/blacklight/document/citation_component.rb
blacklight-7.23.0.1 app/components/blacklight/document/citation_component.rb
blacklight-7.23.0 app/components/blacklight/document/citation_component.rb