Sha256: 145abdfcb7571b150e638a6fa5288ae15a264c9c1303a8b81b6579141a76f618
Contents?: true
Size: 1.3 KB
Versions: 5
Compression:
Stored size: 1.3 KB
Contents
module Tableview::Output class HTML def process(tv) @table = "" @p = 0 tv.subtables.each do |sub| tag :h2, sub.title unless sub.title.blank? tag :table, sub.options do sub.parts.each do |part| tag (case part.class.to_s when "Tableview::ViewHandler::Header" header = true :thead when "Tableview::ViewHandler::Footer" :tfoot when "Tableview::ViewHandler::Body" :tbody end), part.options do part.rows.each do |row| tag :tr, row.options do row.cells.each do |cell| tag( header || cell.options[:header] ? :th : :td, cell.options) do @table += ERB::Util::html_escape(cell.contents.to_s) end #td / #th end end #tr end end #t{part} end end #table end end def tag(tag, attributes = {}) atrs = attributes.map {|k,v| " #{k}=\"#{v}\"" }.join @table += "\n#{" "*@p}<#{tag}#{atrs}>" @p += 2 yield @p -= 2 @table += "\n#{" " * @p}</#{tag}>" end def to_s @table.html_safe.to_s end end end
Version data entries
5 entries across 5 versions & 1 rubygems