module Rack::App::FrontEnd::Helpers::Table::Builder

Public Instance Methods

from_array_of_hash(array_of_hash, attributes) click to toggle source
# 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) click to toggle source
# 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