Changeset 973
- Timestamp:
- 05/12/07 21:16:05 (2 years ago)
- Files:
-
- ruport/trunk/lib/ruport/formatter/html.rb (modified) (4 diffs)
- ruport/trunk/test/html_formatter_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ruport/trunk/lib/ruport/formatter/html.rb
r873 r973 22 22 # <tt>:show_group_headers</tt> True by default 23 23 # 24 # <tt>:style</tt> Used for grouping (:inline, :justified) 25 # 24 26 class Formatter::HTML < Formatter 25 27 … … 27 29 Renderer::Group, Renderer::Grouping ] 28 30 29 opt_reader :show_table_headers, :show_group_headers 31 opt_reader :show_table_headers, :show_group_headers, :style 30 32 31 33 # Generates table headers based on the column names of your Data::Table. … … 81 83 # 82 84 def build_grouping_body 83 render_inline_grouping(options) 85 case style 86 when :inline 87 render_inline_grouping(options) 88 when :justified 89 render_justified_grouping 90 end 84 91 end 85 92 … … 107 114 raise RuntimeError, "You need RedCloth!\n gem install RedCloth -v 3.0.3" 108 115 end 116 117 private 118 119 def render_justified_grouping 120 output << "\t<table>\n\t\t<tr>\n\t\t\t<th>" + 121 "#{data.grouped_by}</th>\n\t\t\t<th>" + 122 grouping_columns.join("</th>\n\t\t\t<th>") + 123 "</th>\n\t\t</tr>\n" 124 data.each do |name, group| 125 group.each_with_index do |row, i| 126 output << "\t\t<tr>\n\t\t\t" 127 if i == 0 128 output << "<td class=\"groupName\">#{name}</td>\n\t\t\t<td>" 129 else 130 output << "<td> </td>\n\t\t\t<td>" 131 end 132 output << row.to_a.join("</td>\n\t\t\t<td>") + 133 "</td>\n\t\t</tr>\n" 134 end 135 end 136 output << "\t</table>" 137 end 138 139 def grouping_columns 140 data.data.to_a[0][1].column_names 141 end 109 142 110 143 end ruport/trunk/test/html_formatter_test.rb
r894 r973 102 102 "\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>\n", actual 103 103 end 104 105 def test_render_justified_html_grouping 106 table = Table(%w[a b c]) << [1,2,3] << [1,1,3] << [2,7,9] 107 g = Grouping(table,:by => "a") 108 actual = Ruport::Renderer::Grouping.render(:html, :data => g, 109 :style => :justified) 110 111 assert_equal "\t<table>\n\t\t<tr>\n\t\t\t<th>a</th>\n\t\t\t<th>b</th>\n"+ 112 "\t\t\t<th>c</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+ 113 "<td class=\"groupName\">1</td>\n\t\t\t<td>"+ 114 "2</td>\n\t\t\t<td>3</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+ 115 "<td> </td>\n\t\t\t<td>1</td>\n\t\t\t<td>3</td>"+ 116 "\n\t\t</tr>\n\t\t<tr>\n\t\t\t"+ 117 "<td class=\"groupName\">2</td>\n\t\t\t<td>7</td>\n"+ 118 "\t\t\t<td>9</td>\n\t\t</tr>\n\t</table>", actual 119 end 104 120 end 105 121
