Skip to content

Commit

Permalink
fix group headers
Browse files Browse the repository at this point in the history
- added thead for group headers
- fixed test to properly count thead headers
- merged header html code
- show_table_headers works for groupings too
  • Loading branch information
kbrock authored and Odaeus committed Jul 25, 2015
1 parent 01eb177 commit 4cfd764
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions lib/ruport/formatter/html.rb
Expand Up @@ -40,12 +40,7 @@ def apply_template
# This method does not do anything if options.show_table_headers is false
# or the Data::Table has no column names.
def build_table_header
output << "\t<table>\n"
unless data.column_names.empty? || !options.show_table_headers
output << "\t\t<thead>\n\t\t<tr>\n\t\t\t<th>" +
data.column_names.join("</th>\n\t\t\t<th>") +
"</th>\n\t\t</tr>\n\t\t</thead>\n"
end
output << build_header(options.show_table_headers ? data.column_names : nil)
end

# Uses the Row controller to build up the table body.
Expand Down Expand Up @@ -119,12 +114,19 @@ def textile(s)
end

private


def build_header(columns)
if !columns || columns.empty?
"\t<table>\n"
else
"\t<table>\n\t\t<thead>\n\t\t<tr>\n\t\t\t<th>" +
columns.join("</th>\n\t\t\t<th>") +
"</th>\n\t\t</tr>\n\t\t</thead>\n"
end
end

def render_justified_grouping
output << "\t<table>\n\t\t<tr>\n\t\t\t<th>" +
"#{data.grouped_by}</th>\n\t\t\t<th>" +
grouping_columns.join("</th>\n\t\t\t<th>") +
"</th>\n\t\t</tr>\n"
output << build_header(options.show_group_headers ? ([data.grouped_by] + grouping_columns) : nil)
data.each do |name, group|
group.each_with_index do |row, i|
output << "\t\t<tr>\n\t\t\t"
Expand Down
3 changes: 2 additions & 1 deletion test/grouping_test.rb
Expand Up @@ -91,7 +91,8 @@ def test_group_as
assert_equal(7, @group.to_text.split("\n").size)
assert_equal(5, @group.as(:text,
:show_table_headers => false).split("\n").size)
assert_equal(13, @group.to_html.split("\n").size)
assert_equal(15, @group.to_html.split("\n").size)
assert_equal(8, @group.to_html(:show_table_headers => false).split("\n").size)
end

def test_as_throws_proper_errors
Expand Down

0 comments on commit 4cfd764

Please sign in to comment.