Skip to content

Commit

Permalink
added description flag for table
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Sep 17, 2009
1 parent 19c0b39 commit 2e49b2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/hirb/helpers/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class << self
# a given proc or an array containing a method and optional arguments to it.
# [:vertical] When set to true, renders a vertical table using Hirb::Helpers::VerticalTable. Default is false.
# [:all_fields] When set to true, renders fields in all rows. Valid only in rows that are hashes. Default is false.
# [:description] When set to true, renders row count description at bottom. Default is true.
# Examples:
# Hirb::Helpers::Table.render [[1,2], [2,3]]
# Hirb::Helpers::Table.render [[1,2], [2,3]], :field_lengths=>{0=>10}
Expand All @@ -63,8 +64,7 @@ def render(rows, options={})

#:stopdoc:
def initialize(rows, options={})
@options = options
@options[:filters] ||= {}
@options = {:description=>true, :filters=>{}}.merge(options)
@fields = set_fields(rows)
@rows = setup_rows(rows)
@headers = @fields.inject({}) {|h,e| h[e] = e.to_s; h}
Expand Down Expand Up @@ -113,7 +113,7 @@ def render
body += render_rows
body += render_footer
end
body << render_table_description
body << render_table_description if @options[:description]
body.join("\n")
end

Expand Down
12 changes: 12 additions & 0 deletions test/table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ def table(*args)
table([['a','b'], ['c', 'd']], :number=>true).should == expected_table
end

test "description option false renders" do
expected_table = <<-TABLE.unindent
+---+---+
| 0 | 1 |
+---+---+
| a | b |
| c | d |
+---+---+
TABLE
table([['a','b'], ['c', 'd']], :description=>false).should == expected_table
end

test "vertical option renders vertical table" do
expected_table = <<-TABLE.unindent
*** 1. row ***
Expand Down

0 comments on commit 2e49b2f

Please sign in to comment.