Sha256: 4cb1cbf7927cffe3e8630015580d1f0c8dbdfa8cb5bc6cabeec8badcea97b150

Contents?: true

Size: 1.59 KB

Versions: 10

Compression:

Stored size: 1.59 KB

Contents

class ReportBuilder
  class Table
    class HtmlBuilder < ElementBuilder
      def generate()
        t=@element
        anchor=@builder.table_entry(t.name)
        out="<a name='#{anchor}'></a><table><caption>#{t.name}</caption>"
        @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"
        @builder.html(out)
      end
      def parse_row(t,row,tag="td")
        row_ary=[]
        real_i=0
        row.each_index do |i|
          extra=1 
          while !@rowspans[real_i].nil? and @rowspans[real_i]>0
            @rowspans[real_i]-=1
            row_ary << ""
            real_i+=1
          end
          
          if row[i].is_a? Table::Colspan
            row_ary.push(sprintf("<%s colspan=\"%d\">%s</%s>",tag, row[i].cols, row[i].data,tag))
          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[real_i]=row[i].rows-1
          else
            row_ary.push("<#{tag}>#{row[i]}</#{tag}>")
          end
          real_i+=extra
          
        end
        row_ary.join("")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
reportbuilder-1.4.2 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.4.1 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.4.0 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.3.0 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.2.5 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.2.4 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.2.3 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.2.2 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.2.1 lib/reportbuilder/table/htmlbuilder.rb
reportbuilder-1.2.0 lib/reportbuilder/table/htmlbuilder.rb