Sha256: 1a7886c88b45260088e2b88debd2c24616e4b6c8a5293a737dce7c23244a5a22

Contents?: true

Size: 1010 Bytes

Versions: 3

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

module Effective
  class TableRow
    attr_accessor :name, :options, :builder, :template

    delegate :object, to: :builder
    delegate :capture, :content_tag, :image_tag, :link_to, :mail_to, :icon, to: :@template

    # So this takes in the options for an entire form group.
    def initialize(name, options, builder:)
      @builder = builder
      @template = builder.template

      @name = name
      @options = options
    end

    # Intended for override
    def content
      value
    end

    # Render method
    def to_html(&block)
      content_tag(:tr) do
        content_tag(:td, label) + content_tag(:td, content.presence || '-')
      end
    end

    # Humanized label or the label from form
    def label
      text = options[:label] || builder.human_attribute_name(name)
      prefix = builder.options[:prefix]

      [*prefix, text].join(': ')
    end

    # Value from resource
    def value
      options[:value] || builder.value(name)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
effective_bootstrap-0.13.5 app/models/effective/table_row.rb
effective_bootstrap-0.13.4 app/models/effective/table_row.rb
effective_bootstrap-0.13.3 app/models/effective/table_row.rb