Class: ReportEngine::Html::Table
- Defined in:
- lib/report_engine/html/table.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#render ⇒ Object
renders an html table.
-
#render_cells(line) ⇒ Object
renders cells within a line in a html table.
-
#render_headers ⇒ Object
renders the header of an html table.
-
#render_line(line, html_class = nil) ⇒ Object
renders a line in an html table.
-
#render_lines ⇒ Object
renders all the lines in the html table.
-
#swap_odd ⇒ Object
Alternates between ‘odd’ and ‘even’.
Methods inherited from Table
#add_headers, #add_y_headers, #data, #initialize
Constructor Details
This class inherits a constructor from ReportEngine::Table
Instance Method Details
#render ⇒ Object
renders an html table
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/report_engine/html/table.rb', line 7 def render if !@x_label.nil? && !@y_label.nil? @canvas.add_content( "<h2 class='axes'>#{@axis_title}</h2> <ul class='axes_list'> <li class='x_axis'>#{@x_label}</li> <li class='y_axis'>#{@y_label}</li> </ul>" ) end @canvas.add_content("<table>") @canvas.add_content(render_headers) if @data.first.is_a? Hash @data.each.map{|sub_table| @canvas.add_content(ReportEngine::Html::SubTable.new(@canvas, sub_table).render) } else @canvas.add_content("<tbody>#{ render_lines }</tbody>") end @canvas.add_content("</table>") if !@legends.nil? @canvas.add_content("<ul class='legends'> #{@legends.map{|l| "<li>#{l}</li>"}} </ul>") end end |
#render_cells(line) ⇒ Object
renders cells within a line in a html table
71 72 73 |
# File 'lib/report_engine/html/table.rb', line 71 def render_cells(line) line.map{|cell| "<td>#{cell}</td>" } end |
#render_headers ⇒ Object
renders the header of an html table
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/report_engine/html/table.rb', line 32 def render_headers if @y_headers && !@data.first.is_a?(ReportEngine::SubTable) add_y_headers end if @x_headers "<thead> <tr> #{@x_headers.map{|header| "<th>#{header}</th>" }} </tr> </thead>" else "" end end |
#render_line(line, html_class = nil) ⇒ Object
renders a line in an html table
65 66 67 |
# File 'lib/report_engine/html/table.rb', line 65 def render_line(line, html_class = nil) "<tr #{ "class='#{html_class}'" if html_class}>#{render_cells(line)}</tr>" end |
#render_lines ⇒ Object
renders all the lines in the html table
59 60 61 |
# File 'lib/report_engine/html/table.rb', line 59 def render_lines @data.map{|line| render_line(line, swap_odd) }.join(' ') end |
#swap_odd ⇒ Object
Alternates between ‘odd’ and ‘even’
49 50 51 52 53 54 55 |
# File 'lib/report_engine/html/table.rb', line 49 def swap_odd if @odd == "odd" @odd = "even" else @odd = "odd" end end |