Class: Tableview::Output::HTML

Inherits:
Object
  • Object
show all
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.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

#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_sObject



46
47
48
# File 'lib/tableview/output/html.rb', line 46

def to_s
  @table.html_safe.to_s
end