class Templet::Html::DefinitionList

Renders an HTML dl from a Hash

Public Instance Methods

call(controls, record=nil, html_class: nil) click to toggle source

controls [Hash]

The key is the field's title
The value is the field value || a Proc which calls the record's method
Calls superclass method Templet::Component::Partial#call
# File lib/templet/html/definition_list.rb, line 11
def call(controls, record=nil, html_class: nil)
  super() do
    dl(html_class || default_html_class) do
      controls.to_h.map do |title, data|
        title = title.to_s.capitalize.tr('_', ' ')

        if data.respond_to?(:call)
          data = data.(record)
        elsif Symbol === data
          data = if record and record.respond_to?(:[])
                   record[data]
                 else
                   data.to_s.capitalize.tr('_', ' ')
                 end
        end

        dt(title) + dd(data)
      end
    end
  end
end
default_html_class() click to toggle source
# File lib/templet/html/definition_list.rb, line 33
def default_html_class
end