Class: ModsDisplay::FieldComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/mods_display/field_component.rb

Direct Known Subclasses

ListFieldComponent

Instance Method Summary collapse

Constructor Details

#initialize(field:, delimiter: nil, label_html_attributes: {}, value_html_attributes: {}, value_transformer: nil) ⇒ FieldComponent

Returns a new instance of FieldComponent.



7
8
9
10
11
12
13
14
15
# File 'app/components/mods_display/field_component.rb', line 7

def initialize(field:, delimiter: nil, label_html_attributes: {}, value_html_attributes: {}, value_transformer: nil)
  super

  @field = field
  @delimiter = delimiter
  @value_transformer = value_transformer
  @label_html_attributes = label_html_attributes
  @value_html_attributes = value_html_attributes
end

Instance Method Details

#format_value(value) ⇒ Object



21
22
23
24
25
26
27
# File 'app/components/mods_display/field_component.rb', line 21

def format_value(value)
  if @value_transformer
    @value_transformer.call(value)
  else
    helpers.format_mods_html(value, field: @field)
  end
end

#render?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/mods_display/field_component.rb', line 17

def render?
  @field.values.any?(&:present?)
end