tidy_table 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 0.0.5 / 2007-11-14
2
+
3
+ * Added :title option in initializer. Emits header row spanning all columns.
4
+
1
5
  == 0.0.4 / 2007-06-27
2
6
 
3
7
  * Changed default table class name to 'tidy_table' for consistency.
@@ -1,7 +1,18 @@
1
1
  ##
2
- # Yet another library to convert an ActiveRecord array (or any struct) and output a simple HTML table.
2
+ # This is yet another library to convert an ActiveRecord array (or any struct)
3
+ # to an HTML table.
3
4
  #
4
- # Can also send the fields back to a block for special formatting.
5
+ # You get a table with a bunch of CSS classes automatically applied (or
6
+ # customize it with your own classes and ids). For example, first_row (is also
7
+ # a th tag), first_column, last_column, even & odd (for rows).
8
+ #
9
+ # Other tags like thead and tbody may be added in the future.
10
+ #
11
+ # Simple example with an ActiveRecord object:
12
+ #
13
+ # <%= TidyTable.new(@records).to_html(%w(title description created_at)) %>
14
+ #
15
+ # You also format the row values with a block:
5
16
  #
6
17
  # <%= TidyTable.new(@records, :table_class => "revenue_report").to_html(%w(resource visits min max)) do |row|
7
18
  # [
@@ -12,10 +23,14 @@
12
23
  # ]
13
24
  # end %>
14
25
  #
26
+ # Or in HAML:
27
+ #
28
+ # = TidyTable.new(@records, :table_class => "revenue_report").to_html(%w(resource visits min max)) do |row|
29
+ # - [ row.resource, number_with_delimiter(row.visit_count), row.min, row.max ]
15
30
 
16
31
  class TidyTable
17
32
 
18
- VERSION = '0.0.4'
33
+ VERSION = '0.0.5'
19
34
 
20
35
  ##
21
36
  # Make a new TidyTable with a data array and CSS options.
@@ -24,6 +39,9 @@ class TidyTable
24
39
  # * :first_row_class -- Defaults to 'first_row'
25
40
  # * :first_column_class -- Defaults to 'first_column'
26
41
  # * :last_column_class -- Defaults to 'last_column'
42
+ # * :title -- Title for this table. Emits an extra header row
43
+ # spanning all columns.
44
+ # * :title_class -- CSS class for the title th. Default: 'title'
27
45
  #
28
46
  # You also get 'even' and 'odd' for free (rows only).
29
47
 
@@ -33,7 +51,8 @@ class TidyTable
33
51
  :table_class => "tidy_table",
34
52
  :first_row_class => "first_row",
35
53
  :first_column_class => "first_column",
36
- :last_column_class => "last_column"
54
+ :last_column_class => "last_column",
55
+ :title_class => "title"
37
56
  }.merge(options)
38
57
  end
39
58
 
@@ -55,6 +74,13 @@ class TidyTable
55
74
  output = []
56
75
  output << %(<table class="#{@options[:table_class]}">)
57
76
 
77
+ # Title
78
+ if @options.has_key?(:title)
79
+ output << %(<tr class="#{@options[:first_row_class]}">)
80
+ output << %(<th class="#{@options[:title_class]} #{@options[:first_row_class]} #{@options[:first_column_class]}" colspan="#{fields.length}">#{@options[:title]}</th>)
81
+ output << %(</tr>)
82
+ end
83
+
58
84
  # First row (header)
59
85
  output << %(<tr class="#{@options[:first_row_class]}">)
60
86
  fields.each_with_index do |field, index|
@@ -58,4 +58,10 @@ describe TidyTable do
58
58
  }.should raise_error(ArgumentError)
59
59
  end
60
60
 
61
+ it "should show title" do
62
+ t = TidyTable.new(@records, :title => "Report of Doom")
63
+ output = t.to_html([:title, :description])
64
+ output.should match(/Report of Doom/)
65
+ end
66
+
61
67
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: tidy_table
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
7
- date: 2007-06-27 00:00:00 -07:00
6
+ version: 0.0.5
7
+ date: 2007-11-14 00:00:00 -08:00
8
8
  summary: Yet another library for converting a struct into an HTML table.
9
9
  require_paths:
10
10
  - lib
@@ -59,5 +59,5 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.2.1
62
+ version: 1.3.0
63
63
  version: