Class: Blacklight::DocumentMetadataComponent

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

Constant Summary

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(fields: [], tag: 'dl', classes: %w[document-metadata dl-invert row], show: false, field_layout: nil, **component_args) ⇒ DocumentMetadataComponent

Returns a new instance of DocumentMetadataComponent.

Parameters:



11
12
13
14
15
16
17
18
# File 'app/components/blacklight/document_metadata_component.rb', line 11

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

Instance Method Details

#before_renderObject



20
21
22
23
24
25
26
# File 'app/components/blacklight/document_metadata_component.rb', line 20

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

#field_component(field) ⇒ Object



32
33
34
# File 'app/components/blacklight/document_metadata_component.rb', line 32

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

#render?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/components/blacklight/document_metadata_component.rb', line 28

def render?
  fields.present?
end