Class: ModsDisplay::FieldComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- ModsDisplay::FieldComponent
- Defined in:
- app/components/mods_display/field_component.rb
Direct Known Subclasses
Instance Method Summary collapse
- #format_value(value) ⇒ Object
-
#initialize(field:, delimiter: nil, label_html_attributes: {}, value_html_attributes: {}, value_transformer: nil) ⇒ FieldComponent
constructor
A new instance of FieldComponent.
- #render? ⇒ Boolean
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
17 18 19 |
# File 'app/components/mods_display/field_component.rb', line 17 def render? @field.values.any?(&:present?) end |