Sha256: b81dc8dd989da65be687abf27e22ebc6ae799459e163b891923aaaef0e17b8bb

Contents?: true

Size: 1.02 KB

Versions: 10

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Blacklight
  class DocumentMetadataComponent < Blacklight::Component
    renders_many :fields, (lambda do |component: nil, **kwargs|
      (component || Blacklight::MetadataFieldComponent).new(**kwargs)
    end)
    with_collection_parameter :fields

    # @param fields [Enumerable<Blacklight::FieldPresenter>] Document field presenters
    def initialize(fields: [], tag: 'dl', classes: %w[document-metadata dl-invert row], show: false, field_layout: nil, **component_args)
      @fields = fields
      @tag = tag
      @classes = classes
      @show = show
      @field_layout = field_layout
      @component_args = component_args
    end

    def before_render
      return unless fields

      @fields.each do |field|
        with_field(component: field_component(field), field: field, show: @show, layout: @field_layout)
      end
    end

    def render?
      fields.present?
    end

    def field_component(field)
      field&.component || Blacklight::MetadataFieldComponent
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
blacklight-7.40.0 app/components/blacklight/document_metadata_component.rb
blacklight-7.39.0 app/components/blacklight/document_metadata_component.rb
blacklight-7.38.0 app/components/blacklight/document_metadata_component.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/components/blacklight/document_metadata_component.rb
blacklight-7.37.0 app/components/blacklight/document_metadata_component.rb
blacklight-7.36.2 app/components/blacklight/document_metadata_component.rb
blacklight-7.36.1 app/components/blacklight/document_metadata_component.rb
blacklight-7.36.0 app/components/blacklight/document_metadata_component.rb
blacklight-7.35.0 app/components/blacklight/document_metadata_component.rb
blacklight-7.34.0 app/components/blacklight/document_metadata_component.rb