Class: Tableview::Output::HTML
- Inherits:
-
Object
- Object
- Tableview::Output::HTML
- Defined in:
- lib/tableview/output/html.rb
Instance Method Summary collapse
Instance Method Details
#process(tv) ⇒ 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 34 35 |
# File 'lib/tableview/output/html.rb', line 3 def process(tv) @table = "" @p = 0 tv.subtables.each do |sub| tag :h2, sub.title unless sub.title.blank? tag :table, sub. 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. do part.rows.each do |row| tag :tr, row. do row.cells.each do |cell| tag( header || cell.[:header] ? :th : :td, cell.) 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 |
#tag(tag, attributes = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/tableview/output/html.rb', line 37 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 |
#to_s ⇒ Object
46 47 48 |
# File 'lib/tableview/output/html.rb', line 46 def to_s @table.html_safe.to_s end |