tidy_table 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/tidy_table.rb +15 -3
- metadata +1 -1
data/History.txt
CHANGED
data/lib/tidy_table.rb
CHANGED
@@ -15,8 +15,18 @@
|
|
15
15
|
|
16
16
|
class TidyTable
|
17
17
|
|
18
|
-
VERSION = '0.0.
|
18
|
+
VERSION = '0.0.3'
|
19
19
|
|
20
|
+
##
|
21
|
+
# Make a new TidyTable with a data array and CSS options.
|
22
|
+
#
|
23
|
+
# * :table_class -- Defaults to 'tidytable'
|
24
|
+
# * :first_row_class -- Defaults to 'first_row'
|
25
|
+
# * :first_column_class -- Defaults to 'first_column'
|
26
|
+
# * :last_column_class -- Defaults to 'last_column'
|
27
|
+
#
|
28
|
+
# You also get 'even' and 'odd' for free (rows only).
|
29
|
+
|
20
30
|
def initialize(array, options={})
|
21
31
|
@rows = array
|
22
32
|
@options = {
|
@@ -41,7 +51,7 @@ class TidyTable
|
|
41
51
|
# First row
|
42
52
|
output << %(<tr class="#{@options[:first_row_class]}">)
|
43
53
|
fields.each_with_index do |field, index|
|
44
|
-
output << %(<th class="#{@options[:first_row_class]} #{ index
|
54
|
+
output << %(<th class="#{@options[:first_row_class]} #{column_classes(fields, index)}">#{field}</th>)
|
45
55
|
end
|
46
56
|
output << "</tr>"
|
47
57
|
|
@@ -50,7 +60,7 @@ class TidyTable
|
|
50
60
|
if block_given?
|
51
61
|
formatted_data = yield(row)
|
52
62
|
formatted_data.each_with_index do |data, index|
|
53
|
-
output << %(<td class="#{column_classes(
|
63
|
+
output << %(<td class="#{column_classes(formatted_data, index)}">#{data}</td>)
|
54
64
|
end
|
55
65
|
else
|
56
66
|
fields.each_with_index do |field, index|
|
@@ -62,6 +72,8 @@ class TidyTable
|
|
62
72
|
output << "</table>"
|
63
73
|
output.join
|
64
74
|
end
|
75
|
+
|
76
|
+
private
|
65
77
|
|
66
78
|
##
|
67
79
|
# Returns "first_column", "last_column", or both.
|
metadata
CHANGED