Sha256: f840962d37da7c902bfe8a26ec9b4619b284e3cb5ef90f02d06a3d23c480fae1
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
class ReportBuilder class Table class HtmlGenerator < ElementGenerator def generate() t=@element anchor=@generator.add_table_entry(t.name) out="<a name='#{anchor}'></a><table>" @rowspans=[] if t.header.size>0 out+="<thead>"+parse_row(t,t.header,"th")+"</thead>\n" end out+="<tbody>\n" next_class="" t.rows.each{|row| if row==:hr next_class="top" else class_tag=(next_class=="")?"":" class ='#{next_class}' " out+="<tr#{class_tag}>"+parse_row(t,row)+"</tr>\n" next_class="" end } out+="</tbody>\n</table>\n" @generator.add_raw(out) end def parse_row(t,row,tag="td") row_ary=[] colspan_i=0 row.each_index do |i| if !@rowspans[i].nil? and @rowspans[i]>0 @rowspans[i]-=1 elsif colspan_i>0 colspan_i-=1 elsif row[i].is_a? Table::Colspan row_ary.push(sprintf("<%s colspan=\"%d\">%s</%s>",tag, row[i].cols, row[i].data,tag)) colspan_i=row[i].cols-1 elsif row[i].nil? row_ary.push("<#{tag}></#{tag}>") elsif row[i].is_a? Table::Rowspan row_ary.push(sprintf("<%s rowspan=\"%d\">%s</%s>", tag, row[i].rows, row[i].data, tag)) @rowspans[i]=row[i].rows-1 else row_ary.push("<#{tag}>#{row[i]}</#{tag}>") end end row_ary.join("") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
reportbuilder-0.1.0 | lib/reportbuilder/table/htmlgenerator.rb |