tidy_table 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ == 0.0.2 / 2007-06-24
2
+
3
+ * Added automatic last_column_class and related options
4
+
1
5
  == 0.0.1 / 2007-06-20
2
6
 
3
7
  * Initial release
data/README.txt CHANGED
@@ -4,7 +4,9 @@ TidyTable
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Yet another library to convert an array of structs (such as an ActiveRecord object) into an HTML table. Simple, with a few options. Includes automatic tags for first_column, first_row, even, odd, etc.
7
+ Yet another library to convert an array of structs (such as an ActiveRecord
8
+ object) into an HTML table. Simple, with a few options. Includes automatic
9
+ tags for first_column, first_row, even, odd, etc.
8
10
 
9
11
  == FEATURES/PROBLEMS:
10
12
 
@@ -15,14 +15,15 @@
15
15
 
16
16
  class TidyTable
17
17
 
18
- VERSION = '0.0.1'
18
+ VERSION = '0.0.2'
19
19
 
20
20
  def initialize(array, options={})
21
21
  @rows = array
22
22
  @options = {
23
23
  :table_class => "tidytable",
24
24
  :first_row_class => "first_row",
25
- :first_column_class => "first_column"
25
+ :first_column_class => "first_column",
26
+ :last_column_class => "last_column"
26
27
  }.merge(options)
27
28
  end
28
29
 
@@ -49,11 +50,11 @@ class TidyTable
49
50
  if block_given?
50
51
  formatted_data = yield(row)
51
52
  formatted_data.each_with_index do |data, index|
52
- output << %(<td class="#{ index == 0 ? @options[:first_column_class] : ''}">#{data}</td>)
53
+ output << %(<td class="#{column_classes(fields, index)}">#{data}</td>)
53
54
  end
54
55
  else
55
56
  fields.each_with_index do |field, index|
56
- output << %(<td class="#{ index == 0 ? @options[:first_column_class] : ''}">#{row.send(field.to_sym)}</td>)
57
+ output << %(<td class="#{column_classes(fields, index)}">#{row.send(field.to_sym)}</td>)
57
58
  end
58
59
  end
59
60
  output << "</tr>"
@@ -61,5 +62,13 @@ class TidyTable
61
62
  output << "</table>"
62
63
  output.join
63
64
  end
64
-
65
+
66
+ ##
67
+ # Returns "first_column", "last_column", or both.
68
+
69
+ def column_classes(fields_array, index)
70
+ classes = (index == 0 ? @options[:first_column_class] : '')
71
+ classes += (index == fields_array.length - 1 ? @options[:last_column_class] : '')
72
+ end
73
+
65
74
  end
@@ -23,4 +23,16 @@ describe TidyTable do
23
23
  t.to_html([:title, :description]).should match(/cheese_table_class/)
24
24
  end
25
25
 
26
+ it "should tag with last_column CSS class" do
27
+ t = TidyTable.new(@records)
28
+ t.to_html([:title, :description]).should match(/last_column/)
29
+ end
30
+
31
+ it "should tag with custom last_column CSS class" do
32
+ t = TidyTable.new(@records, :last_column_class => "the_end_my_friend")
33
+ content = t.to_html([:title, :description])
34
+ content.should_not match(/last_column/)
35
+ content.should match(/the_end_my_friend/)
36
+ end
37
+
26
38
  end
metadata CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: tidy_table
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-06-20 00:00:00 -07:00
6
+ version: 0.0.2
7
+ date: 2007-06-24 00:00:00 -07:00
8
8
  summary: Yet another library for converting a struct into an HTML table.
9
9
  require_paths:
10
10
  - lib
11
11
  email: boss AT topfunky.com
12
12
  homepage: http://rubyforge.org/projects/seattlerb
13
13
  rubyforge_project: seattlerb
14
- description: "TidyTable by Geoffrey Grosenbach http://topfunky.com == DESCRIPTION: Yet another library to convert an array of structs (such as an ActiveRecord object) into an HTML table. Simple, with a few options. Includes automatic tags for first_column, first_row, even, odd, etc."
14
+ description: "TidyTable by Geoffrey Grosenbach http://topfunky.com == DESCRIPTION: Yet another library to convert an array of structs (such as an ActiveRecord object) into an HTML table. Simple, with a few options. Includes automatic tags for first_column, first_row, even, odd, etc."
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin