ReportBuilder::Table::HtmlBuilder

Public Instance Methods

generate() click to toggle source
    # File lib/reportbuilder/table/htmlbuilder.rb, line 4
 4:       def generate()
 5:         t=@element
 6:         anchor=@builder.table_entry(t.name)
 7:         out="<a name='#{anchor}'></a><table><caption>#{t.name}</caption>"
 8:         @rowspans=[]
 9:         if t.header.size>0
10:           out+="<thead>"+parse_row(t,t.header,"th")+"</thead>\n"
11:         end
12:         out+="<tbody>\n"
13:         next_class=""
14:         t.rows.each{|row|
15:           if row==:hr
16:             next_class="top"
17:           else
18:             class_tag=(next_class=="")?"":" class ='#{next_class}' "
19:             out+="<tr#{class_tag}>"+parse_row(t,row)+"</tr>\n"
20:             next_class=""
21:           end
22:         }
23:         out+="</tbody>\n</table>\n"
24:         @builder.html(out)
25:       end
parse_row(t,row,tag="td") click to toggle source
    # File lib/reportbuilder/table/htmlbuilder.rb, line 26
26:       def parse_row(t,row,tag="td")
27:         row_ary=[]
28:         real_i=0
29:         row.each_index do |i|
30:           extra=1 
31:           while !@rowspans[real_i].nil? and @rowspans[real_i]>0
32:             @rowspans[real_i]-=1
33:             row_ary << ""
34:             real_i+=1
35:           end
36:           
37:           if row[i].is_a? Table::Colspan
38:             row_ary.push(sprintf("<%s colspan=\"%d\">%s</%s>",tag, row[i].cols, row[i].data,tag))
39:           elsif row[i].nil?
40:             row_ary.push("<#{tag}></#{tag}>")
41:           elsif row[i].is_a? Table::Rowspan
42:             row_ary.push(sprintf("<%s rowspan=\"%d\">%s</%s>", tag, row[i].rows, row[i].data, tag))
43:             @rowspans[real_i]=row[i].rows-1
44:           else
45:             row_ary.push("<#{tag}>#{row[i]}</#{tag}>")
46:           end
47:           real_i+=extra
48:           
49:         end
50:         row_ary.join("")
51:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.