class Templet::Html::Table
Renders an HTML table from a Hash
Public Instance Methods
call(controls, records, opaque_heading: nil, opaque_row: nil, html_class: nil, footer: '')
click to toggle source
controls
[Hash]
The key is a Proc || a field name (if it begins with _ it's not shown) The value is a Proc || an index || nil (for a single column table)
Calls superclass method
Templet::Component::Partial#call
# File lib/templet/html/table.rb, line 11 def call(controls, records, opaque_heading: nil, opaque_row: nil, html_class: nil, footer: '') controls = controls.to_h super() do _table(html_class || default_html_class) do [ thead do tr do controls.keys.map do |title| if title.respond_to?(:call) th title.(self, opaque_heading, opaque_row) else th heading(title.to_s) end end end end, tbody do records.map do |record| tr do controls.values.map.with_index do |value, index| if value.respond_to?(:call) td value.(self, record, opaque_row) elsif value td record[value] else Array === record ? record[index] : record end end end end end, tfoot do tr do td(colspan: controls.size) { footer } end end ] end end end
default_html_class()
click to toggle source
# File lib/templet/html/table.rb, line 55 def default_html_class end
heading(title)
click to toggle source
# File lib/templet/html/table.rb, line 58 def heading(title) title[0] == '_' ? '' : title.capitalize.tr('_', ' ') end