Sha256: fbc0e04e44de7cc9c1c96ef51d0a28238ba9b82f207278794dbb63f150ebf001

Contents?: true

Size: 728 Bytes

Versions: 14

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

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.format_mods_html(value, field: @field)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mods_display-1.6.3 app/components/mods_display/field_component.rb
mods_display-1.6.2 app/components/mods_display/field_component.rb
mods_display-1.6.1 app/components/mods_display/field_component.rb
mods_display-1.6.0 app/components/mods_display/field_component.rb
mods_display-1.5.0 app/components/mods_display/field_component.rb
mods_display-1.4.0 app/components/mods_display/field_component.rb
mods_display-1.3.5 app/components/mods_display/field_component.rb
mods_display-1.3.4 app/components/mods_display/field_component.rb
mods_display-1.3.3 app/components/mods_display/field_component.rb
mods_display-1.3.2 app/components/mods_display/field_component.rb
mods_display-1.3.1 app/components/mods_display/field_component.rb
mods_display-1.3.0 app/components/mods_display/field_component.rb
mods_display-1.2.1 app/components/mods_display/field_component.rb
mods_display-1.2.0 app/components/mods_display/field_component.rb