Module: Rack::App::FrontEnd::Helpers::Table

Defined in:
lib/rack/app/front_end/helpers/table.rb

Instance Method Summary collapse

Instance Method Details

#table_by(array_of_hash) ⇒ Object



3
4
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
32
33
# File 'lib/rack/app/front_end/helpers/table.rb', line 3

def table_by(array_of_hash)

  headers = array_of_hash.reduce([]) do |trs, hash|
    trs.push(*hash.keys)
    trs.uniq!
    trs
  end

  o = Object.new
  o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl)

  table_html = o.__send__ :table_tag 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