Module: Rack::App::FrontEnd::Helpers::Table::Builder
Instance Method Summary collapse
Instance Method Details
#from_array_of_hash(array_of_hash, attributes) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/app/front_end/helpers/table.rb', line 5 def from_array_of_hash(array_of_hash, attributes) headers = array_of_hash.each_with_object([]) do |hash, trs| trs.push(*hash.keys) trs.uniq! end o = Object.new o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl) table_html = o.__send__ :table_tag, attributes do tr_tag do headers.each do |header| td_tag String(header) end end array_of_hash.each do |hash| tr_tag do headers.each do |header| td_tag String(hash[header]) end end end end table_html end |
#from_hash(hash, attributes) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rack/app/front_end/helpers/table.rb', line 33 def from_hash(hash, attributes) o = Object.new o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl) table_html = o.__send__ :table_tag, attributes do hash.each do |key, value| tr_tag do td_tag String(key) td_tag String(value) end end end table_html end |