Method: RequestLogAnalyzer::Output::HTML#table

Defined in:
lib/request_log_analyzer/output/html.rb

#table(*columns) {|rows| ... } ⇒ Object

Generate a report table in HTML and push it into the output object. *colums<tt> Columns hash <tt>&block: A block yeilding the rows.

Yields:

  • (rows)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/request_log_analyzer/output/html.rb', line 44

def table(*columns, &block)
  rows = Array.new
  yield(rows)

  @io << tag(:table, {:id => 'mytable', :cellspacing => 0}) do |content|
    if table_has_header?(columns)
      content << tag(:tr) do
        columns.map { |col| tag(:th, col[:title]) }.join("\n")
      end
    end

    odd = false
    rows.each do |row|
      odd = !odd
      content << tag(:tr) do
        if odd
          row.map { |cell| tag(:td, cell, :class => 'alt') }.join("\n")
        else
          row.map { |cell| tag(:td, cell) }.join("\n")
        end
      end
    end
  end

end