Sha256: 103c740208a4bfcd53da6a2ce37ac0c31dc8408f89e220819b69503f697e44fe

Contents?: true

Size: 685 Bytes

Versions: 4

Compression:

Stored size: 685 Bytes

Contents

module ModsDisplay
  class FieldComponent < ViewComponent::Base
    with_collection_parameter :field

    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

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

    def format_value(value)
      if @value_transformer
        @value_transformer.call(value)
      else
        helpers.link_urls_and_email(value)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mods_display-1.0.0.alpha4 app/components/mods_display/field_component.rb
mods_display-1.0.0.alpha3 app/components/mods_display/field_component.rb
mods_display-1.0.0.alpha2 app/components/mods_display/field_component.rb
mods_display-1.0.0.alpha1 app/components/mods_display/field_component.rb