Sha256: 758527e234ae65b83222a44bf00109b8d003f1ee019e0054c0ed6d33568bd95c

Contents?: true

Size: 1.5 KB

Versions: 16

Compression:

Stored size: 1.5 KB

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

    def controller_namespace
      Effective::Resource.new(template.controller.controller_path).namespace
    end

    # Intended for override
    def content
      value
    end

    def tr_class
      "row-#{name}" # This matches datatables which is "col-#{name}"
    end

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

    def label_content
      hint = self.hint
      (hint.present? ? "#{label}#{hint}" : label).html_safe
    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

    def hint
      text = options[:hint]
      return if text.blank?

      content_tag(:div) do
        content_tag(:small, text.html_safe, class: 'text-muted')
      end
    end

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

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
effective_bootstrap-1.17.2 app/models/effective/table_row.rb
effective_bootstrap-1.17.1 app/models/effective/table_row.rb
effective_bootstrap-1.17.0 app/models/effective/table_row.rb
effective_bootstrap-1.16.4 app/models/effective/table_row.rb
effective_bootstrap-1.16.3 app/models/effective/table_row.rb
effective_bootstrap-1.16.2 app/models/effective/table_row.rb
effective_bootstrap-1.16.1 app/models/effective/table_row.rb
effective_bootstrap-1.16.0 app/models/effective/table_row.rb
effective_bootstrap-1.15.6 app/models/effective/table_row.rb
effective_bootstrap-1.15.5 app/models/effective/table_row.rb
effective_bootstrap-1.15.4 app/models/effective/table_row.rb
effective_bootstrap-1.15.3 app/models/effective/table_row.rb
effective_bootstrap-1.15.2 app/models/effective/table_row.rb
effective_bootstrap-1.15.1 app/models/effective/table_row.rb
effective_bootstrap-1.15.0 app/models/effective/table_row.rb
effective_bootstrap-1.14.17 app/models/effective/table_row.rb