Class: Blacklight::MetadataFieldComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/metadata_field_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(field:, layout: nil, show: false, view_type: nil) ⇒ MetadataFieldComponent

Returns a new instance of MetadataFieldComponent.

Parameters:



10
11
12
13
14
15
# File 'app/components/blacklight/metadata_field_component.rb', line 10

def initialize(field:, layout: nil, show: false, view_type: nil)
  @field = field
  @layout = layout || Blacklight::MetadataFieldLayoutComponent
  @view_type = view_type
  @show = show
end

Instance Method Details

#index_field_label(label) ⇒ String

Render the index field label for a document

Translations for index field labels should go under blacklight.search.fields They are picked up from there by a value “%#label” in blacklight.search.index.label

Returns:

  • (String)


40
41
42
# File 'app/components/blacklight/metadata_field_component.rb', line 40

def index_field_label label
  html_escape t(:"blacklight.search.index.#{@view_type}.label", default: :'blacklight.search.index.label', label: label)
end

#labelObject



17
18
19
20
21
22
23
# File 'app/components/blacklight/metadata_field_component.rb', line 17

def label
  if @show
    show_field_label @field.label('show')
  else
    index_field_label @field.label
  end
end

#render?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/components/blacklight/metadata_field_component.rb', line 25

def render?
  @field.render_field?
end

#render_fieldObject

Override this method in a subclass to change the way this value is rendered



30
31
32
# File 'app/components/blacklight/metadata_field_component.rb', line 30

def render_field
  @field.render
end

#show_field_label(label) ⇒ String

Render the show field label for a document

Returns:

  • (String)


48
49
50
# File 'app/components/blacklight/metadata_field_component.rb', line 48

def show_field_label label
  t(:'blacklight.search.show.label', label: label)
end