Permalink
Browse files

added description flag for table

  • Loading branch information...
1 parent 19c0b39 commit 2e49b2fcfa836fbdcf58adc9ce3c32198de7f080 @cldwalker cldwalker committed Sep 17, 2009
Showing with 15 additions and 3 deletions.
  1. +3 −3 lib/hirb/helpers/table.rb
  2. +12 −0 test/table_test.rb
@@ -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}
@@ -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}
@@ -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
View
@@ -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 ***

0 comments on commit 2e49b2f

Please sign in to comment.