Spreadsheet-HTML 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/Changes +3 -0
- data/README +92 -15
- data/lib/Spreadsheet/HTML.rb +3 -3
- data/lib/Spreadsheet/HTML/version.rb +1 -1
- data/t/07-attrs.rb +373 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69280b7ae0534329c562340c5d86a9bc3753ca49
|
4
|
+
data.tar.gz: 86a46dc59fb742b0115aaf5d1f3feeb72d476934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa64fa4375b280792b55d1a517598f9218be78ada368e1bef986dc1fbe42a6eb18c512341cdf9d456de727b6b0ab4e4da829f888217ea978f3fed58c48f84af
|
7
|
+
data.tar.gz: 67f8dc2ad38cd2544597471c28812e3ede9b21acd6e075e4f57b46470a9bf98966000685443f1da139160be298ef6f8f865883ebae837897e50b6a46eefd2751
|
data/Changes
CHANGED
data/README
CHANGED
@@ -38,19 +38,25 @@ new( params )
|
|
38
38
|
may be overriden in a subsequent call to a generator method (which are listed next).
|
39
39
|
|
40
40
|
generate( params )
|
41
|
+
Generates an HTML table with headings positioned at the top.
|
42
|
+
|
41
43
|
portrait( params )
|
44
|
+
Generates an HTML table with headings positioned at the top.
|
45
|
+
|
42
46
|
north( params )
|
43
|
-
|
47
|
+
Generates an HTML table with headings positioned at the top.
|
44
48
|
|
45
49
|
landscape( params )
|
50
|
+
Generates an HTML table with headings positioned at the left.
|
51
|
+
|
46
52
|
west( params )
|
47
|
-
|
53
|
+
Generates an HTML table with headings positioned at the left.
|
48
54
|
|
49
55
|
south( params )
|
50
|
-
|
56
|
+
Generates an HTML table with headings positioned at the bottom.
|
51
57
|
|
52
58
|
east( params )
|
53
|
-
|
59
|
+
Generates an HTML table with headings positioned at the right.
|
54
60
|
|
55
61
|
== Literal Parameters
|
56
62
|
Literal Parameters provides the means to modify the macro aspects of the table,
|
@@ -59,100 +65,171 @@ east( params )
|
|
59
65
|
data
|
60
66
|
The data to be rendered as an HTML table. Array of Arrays.
|
61
67
|
|
68
|
+
'data' = > [ [ 1, 2, 3 ], [ 4, 5, 6 ], [7, 8, 9 ] ]
|
69
|
+
|
62
70
|
tgroups
|
63
71
|
Integer (0, 1 or 2). Group table rows into <thead>, <tbody> and <tfoot> sections.
|
64
72
|
When tgroups is set to 1, the <tfoot> section is omitted. The last row of the data
|
65
73
|
is found at the end of the <tbody> section instead. (loose) When tgroups is set to 2,
|
66
74
|
the <tfoot> section is found in between the <thead> and <tbody> sections. (strict)
|
67
75
|
|
76
|
+
'tgroups' => 1
|
77
|
+
'tgroups' => 2
|
78
|
+
|
68
79
|
indent
|
69
80
|
The string to indent each row by. Defaults to undefined which produces no indentation.
|
70
81
|
Automatically adds newlines when set to any defined value.
|
71
82
|
|
83
|
+
'indent' => ' '
|
84
|
+
'indent' => "\t"
|
85
|
+
|
72
86
|
level
|
73
87
|
Positive integer. The level to start indentation at. This is useful for matching the nesting styles of
|
74
88
|
original HTML text that you may wish in insert into. (A value of 4 says "apply the repitition operator
|
75
89
|
to the value of indent 4 times.)
|
76
90
|
|
91
|
+
'level' => 3
|
92
|
+
|
77
93
|
empty
|
78
94
|
String. Render any empty cells with this value. Defaults to &nbps;
|
79
95
|
|
96
|
+
'empty' => ''
|
97
|
+
|
80
98
|
encode
|
81
99
|
Boolean. Whether or not to Encode entities.
|
82
100
|
|
101
|
+
'encode' => 1
|
102
|
+
|
83
103
|
encodes
|
84
104
|
String. Encode these HTML entities. Pass string with chars you want encoded
|
85
105
|
or leave blank for default control and high bit chars and <>!'"
|
86
106
|
|
107
|
+
'encodes' => '<>'
|
108
|
+
|
87
109
|
matrix
|
88
110
|
Boolean. Render the headings row with only <td> tags, no <th> tags.
|
89
111
|
|
112
|
+
'matrix' => 1
|
113
|
+
|
90
114
|
headless
|
91
115
|
Boolean. Render the table without the headings row at all.
|
92
116
|
|
117
|
+
'headless' => 1
|
118
|
+
|
93
119
|
theta
|
94
120
|
Rotates table clockwise for positive values and counter-clockwise for negative values.
|
95
121
|
Default is 0: headings at top. 90 yields headings at right, 180 yields headings at bottom.
|
96
|
-
270 yields headings at left. To achieve landscape, use -270.
|
122
|
+
270 yields headings at left. To achieve landscape, use -270 (or use the landscape() method).
|
123
|
+
|
124
|
+
'theta' => -270
|
97
125
|
|
98
126
|
flip
|
99
127
|
Flips the table horizontally from the perspective of the headings "row" by
|
100
128
|
negating the value of theta.
|
101
129
|
|
130
|
+
'flip' => 1
|
131
|
+
|
102
132
|
pinhead
|
103
133
|
Works in conjunction with theta to ensure reporting readability. Without it, south() and east()
|
104
134
|
would have data cells arranged in reverse order.
|
105
135
|
|
136
|
+
'pinhead' => 1
|
137
|
+
|
106
138
|
fill
|
107
139
|
Can be used instead of data to create a "blank" table or with data to pad rows and cells.
|
108
140
|
|
109
|
-
fill => '8x12' # 8 rows, 12 columns
|
141
|
+
'fill' => '8x12' # 8 rows, 12 columns
|
110
142
|
|
111
143
|
== Dynamic Parameters
|
112
144
|
Dynamic parameters provide a means to control the micro elements of the table,
|
113
145
|
such as modifying headings by their name and rows and columns by their indices.
|
114
146
|
They contain leading underscores to seperate them from literal and tag parameters.
|
147
|
+
They accepts Hashes for use as tag attributes, Procs or lambdas for altering the
|
148
|
+
CDATA of the cell, or Arrays that contain either (just like the 'td' and 'th' Tag
|
149
|
+
Parameters described below).
|
115
150
|
|
116
151
|
_rX
|
117
|
-
|
152
|
+
Apply these attributes to row X (zero index based).
|
153
|
+
|
154
|
+
'_r2' => { 'class' => 'third-row' }
|
155
|
+
'_r2' => lambda { |c| c.upcase }
|
156
|
+
'_r2' => [ lambda { |c| c.upcase }, { 'class' => 'third-row' } ]
|
118
157
|
|
119
158
|
_cX
|
120
|
-
|
159
|
+
Apply these attributes to colum X (zero index based). You can also alias any
|
121
160
|
column by the value of the heading name in that column prepended with underscore (_)
|
122
161
|
|
123
|
-
|
162
|
+
'_c4' => { 'class' => 'fifth-column' }
|
163
|
+
'_c4' => lambda { |c| c.upcase }
|
164
|
+
'_c4' => [ lambda { |c| c.upcase }, { 'class' => 'fifth-column' } ]
|
124
165
|
|
125
|
-
|
166
|
+
'_occupation' => { 'class' => 'foo' }
|
167
|
+
'_salary' => lambda { |c| c.capitalize }
|
126
168
|
|
127
169
|
_rXcY
|
128
|
-
|
170
|
+
Apply these attributes to colum Y in row X (zero index based).
|
171
|
+
|
172
|
+
'_r2c4' => { 'class' => 'third-row-fifth-column' }
|
173
|
+
'_r2c4' => lambda { |c| c.upcase }
|
174
|
+
'_r2c4' => [ lambda { |c| c.upcase }, { 'class' => 'third-row-fifth-column' } ]
|
129
175
|
|
130
176
|
== Tag Parameters
|
131
177
|
Tag Parameters provide a means to control the attributes of the table's tags, and in
|
132
|
-
the case of <th> and <td> the contents via callback subroutines
|
178
|
+
the case of <th> and <td> the contents via callback subroutines. Although
|
133
179
|
similar in form, they are differentiated from litertal parameters because they share
|
134
180
|
the names of the actual HTML table tags.
|
135
181
|
|
136
182
|
table
|
183
|
+
Hash. Apply these attributes.
|
184
|
+
|
185
|
+
'table' => { 'class' => 'spreadsheet' }
|
186
|
+
|
137
187
|
thead
|
188
|
+
Hash. Apply these attributes.
|
189
|
+
|
190
|
+
'thead' => { 'class' => 'headings' }
|
191
|
+
|
138
192
|
tfoot
|
193
|
+
Hash. Apply these attributes.
|
194
|
+
|
195
|
+
'tfoot' => { 'class' => 'footings' }
|
196
|
+
|
139
197
|
tbody
|
198
|
+
Hash. Apply these attributes.
|
199
|
+
|
200
|
+
'tbody' => { 'class' => 'bodyings' }
|
201
|
+
|
140
202
|
tr
|
141
|
-
Hash. Apply these attributes
|
203
|
+
Hash. Apply these attributes.
|
204
|
+
|
205
|
+
'tr => { 'class' => %w{ odd even } }
|
142
206
|
|
143
207
|
th
|
208
|
+
<th> and <td> are the only Tag Parameters that also accept callback methods.
|
209
|
+
|
210
|
+
'th' => { 'style' => { 'color' => %w{ red green blue } } }
|
211
|
+
'th' => lambda { |c| c.upcase }
|
212
|
+
'th' => [ { 'style' => { 'color' => %w{ red green blue } }, lambda { |c| c.upcase } ]
|
213
|
+
|
144
214
|
td
|
145
|
-
<th> and <td>
|
146
|
-
|
215
|
+
<th> and <td> are the only Tag Parameters that also accept callback methods.
|
216
|
+
|
217
|
+
'td' => { 'style' => { 'color' => %w{ red green blue } } }
|
218
|
+
'td' => lambda { |c| c.upcase }
|
219
|
+
'td' => [ { 'style' => { 'color' => %w{ red green blue } }, lambda { |c| c.upcase } ]
|
147
220
|
|
148
221
|
thead.tr
|
149
222
|
When tgroups is 1 or 2, this tag parameter is available to control the attributes of
|
150
223
|
the <tr> tag within the <thead> group.
|
151
224
|
|
225
|
+
'thead.tr' => { 'class' => 'body-cell' }
|
226
|
+
|
152
227
|
tfoot.tr
|
153
228
|
When tgroups is 2, this tag parameter is available to control the attributes of
|
154
229
|
the <tr> tag within the <tfoot> group.
|
155
230
|
|
231
|
+
'tbody.tr' => { 'class' => 'body-cell' }
|
232
|
+
|
156
233
|
== License
|
157
234
|
MIT
|
158
235
|
|
data/lib/Spreadsheet/HTML.rb
CHANGED
@@ -248,13 +248,13 @@ module Spreadsheet
|
|
248
248
|
thingy.each do |t|
|
249
249
|
if t.kind_of?(Hash)
|
250
250
|
new_attr = t
|
251
|
-
|
252
|
-
|
251
|
+
elsif t.kind_of?(Proc)
|
252
|
+
cdata = t.call( cdata )
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
256
256
|
attr = {}
|
257
|
-
orig_attr.each { |key,val| attr[key] = val }
|
257
|
+
orig_attr.each { |key,val| attr[key] = val } if orig_attr.kind_of?(Hash)
|
258
258
|
new_attr.each { |key,val| attr[key] = val }
|
259
259
|
|
260
260
|
return [ cdata, attr ]
|
data/t/07-attrs.rb
CHANGED
@@ -92,6 +92,7 @@ class Test_Attributes < Test::Unit::TestCase
|
|
92
92
|
)
|
93
93
|
|
94
94
|
end
|
95
|
+
|
95
96
|
def test_th
|
96
97
|
|
97
98
|
data = Array[
|
@@ -122,6 +123,126 @@ class Test_Attributes < Test::Unit::TestCase
|
|
122
123
|
|
123
124
|
end
|
124
125
|
|
126
|
+
def test_th_rotate
|
127
|
+
|
128
|
+
data = Array[
|
129
|
+
%w(header1 header2 header3 header4),
|
130
|
+
%w(foo1 bar1 baz1 qux1),
|
131
|
+
%w(foo2 bar2 baz2 qux2),
|
132
|
+
%w(foo3 bar3 baz3 qux3),
|
133
|
+
%w(foo4 bar4 baz4 qux4)
|
134
|
+
]
|
135
|
+
|
136
|
+
html = '<table><tr><th class="h1">header1</th><th class="h2">header2</th><th class="h3">header3</th><th class="h4">header4</th></tr><tr><td>foo1</td><td>bar1</td><td>baz1</td><td>qux1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td><td>qux2</td></tr><tr><td>foo3</td><td>bar3</td><td>baz3</td><td>qux3</td></tr><tr><td>foo4</td><td>bar4</td><td>baz4</td><td>qux4</td></tr></table>'
|
137
|
+
|
138
|
+
assert_equal(
|
139
|
+
html,
|
140
|
+
Spreadsheet::HTML.new( 'data' => data, 'th' => { 'class' => %w{ h1 h2 h3 h4 } } ).generate(),
|
141
|
+
"via constructor only"
|
142
|
+
)
|
143
|
+
assert_equal(
|
144
|
+
html,
|
145
|
+
Spreadsheet::HTML.new().generate( 'data' => data, 'th' => { 'class' => %w{ h1 h2 h3 h4 } } ),
|
146
|
+
"via method only"
|
147
|
+
)
|
148
|
+
assert_equal(
|
149
|
+
html,
|
150
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( 'th' => { 'class' => %w{ h1 h2 h3 h4 } } ),
|
151
|
+
"via constructor and method"
|
152
|
+
)
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_th_lambda
|
157
|
+
|
158
|
+
data = Array[
|
159
|
+
%w(header1 header2 header3 header4),
|
160
|
+
%w(foo1 bar1 baz1 qux1),
|
161
|
+
%w(foo2 bar2 baz2 qux2),
|
162
|
+
%w(foo3 bar3 baz3 qux3),
|
163
|
+
%w(foo4 bar4 baz4 qux4)
|
164
|
+
]
|
165
|
+
|
166
|
+
html = '<table><tr><th>HEADER1</th><th>HEADER2</th><th>HEADER3</th><th>HEADER4</th></tr><tr><td>foo1</td><td>bar1</td><td>baz1</td><td>qux1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td><td>qux2</td></tr><tr><td>foo3</td><td>bar3</td><td>baz3</td><td>qux3</td></tr><tr><td>foo4</td><td>bar4</td><td>baz4</td><td>qux4</td></tr></table>'
|
167
|
+
|
168
|
+
assert_equal(
|
169
|
+
html,
|
170
|
+
Spreadsheet::HTML.new( 'data' => data, 'th' => lambda { |c| c.upcase } ).generate(),
|
171
|
+
"via constructor only"
|
172
|
+
)
|
173
|
+
assert_equal(
|
174
|
+
html,
|
175
|
+
Spreadsheet::HTML.new().generate( 'data' => data, 'th' => lambda { |c| c.upcase } ),
|
176
|
+
"via method only"
|
177
|
+
)
|
178
|
+
assert_equal(
|
179
|
+
html,
|
180
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( 'th' => lambda { |c| c.upcase } ),
|
181
|
+
"via constructor and method"
|
182
|
+
)
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_th_proc
|
187
|
+
|
188
|
+
data = Array[
|
189
|
+
%w(header1 header2 header3 header4),
|
190
|
+
%w(foo1 bar1 baz1 qux1),
|
191
|
+
%w(foo2 bar2 baz2 qux2),
|
192
|
+
%w(foo3 bar3 baz3 qux3),
|
193
|
+
%w(foo4 bar4 baz4 qux4)
|
194
|
+
]
|
195
|
+
|
196
|
+
html = '<table><tr><th>HEADER1</th><th>HEADER2</th><th>HEADER3</th><th>HEADER4</th></tr><tr><td>foo1</td><td>bar1</td><td>baz1</td><td>qux1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td><td>qux2</td></tr><tr><td>foo3</td><td>bar3</td><td>baz3</td><td>qux3</td></tr><tr><td>foo4</td><td>bar4</td><td>baz4</td><td>qux4</td></tr></table>'
|
197
|
+
|
198
|
+
assert_equal(
|
199
|
+
html,
|
200
|
+
Spreadsheet::HTML.new( 'data' => data, 'th' => Proc.new { |c| c.upcase } ).generate(),
|
201
|
+
"via constructor only"
|
202
|
+
)
|
203
|
+
assert_equal(
|
204
|
+
html,
|
205
|
+
Spreadsheet::HTML.new().generate( 'data' => data, 'th' => Proc.new { |c| c.upcase } ),
|
206
|
+
"via method only"
|
207
|
+
)
|
208
|
+
assert_equal(
|
209
|
+
html,
|
210
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( 'th' => Proc.new { |c| c.upcase } ),
|
211
|
+
"via constructor and method"
|
212
|
+
)
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_th_attr_and_lambda
|
217
|
+
|
218
|
+
data = Array[
|
219
|
+
%w(header1 header2 header3 header4),
|
220
|
+
%w(foo1 bar1 baz1 qux1),
|
221
|
+
%w(foo2 bar2 baz2 qux2),
|
222
|
+
%w(foo3 bar3 baz3 qux3),
|
223
|
+
%w(foo4 bar4 baz4 qux4)
|
224
|
+
]
|
225
|
+
|
226
|
+
html = '<table><tr><th style="color: red;">HEADER1</th><th style="color: green;">HEADER2</th><th style="color: blue;">HEADER3</th><th style="color: red;">HEADER4</th></tr><tr><td>foo1</td><td>bar1</td><td>baz1</td><td>qux1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td><td>qux2</td></tr><tr><td>foo3</td><td>bar3</td><td>baz3</td><td>qux3</td></tr><tr><td>foo4</td><td>bar4</td><td>baz4</td><td>qux4</td></tr></table>'
|
227
|
+
|
228
|
+
assert_equal(
|
229
|
+
html,
|
230
|
+
Spreadsheet::HTML.new( 'data' => data, 'th' => [ lambda { |c| c.upcase }, { 'style' => { 'color' => %w{ red green blue } } } ] ).generate(),
|
231
|
+
"via constructor only"
|
232
|
+
)
|
233
|
+
assert_equal(
|
234
|
+
html,
|
235
|
+
Spreadsheet::HTML.new().generate( 'data' => data, 'th' => [ lambda { |c| c.upcase }, { 'style' => { 'color' => %w{ red green blue } } } ] ),
|
236
|
+
"via method only"
|
237
|
+
)
|
238
|
+
assert_equal(
|
239
|
+
html,
|
240
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( 'th' => [ lambda { |c| c.upcase }, { 'style' => { 'color' => %w{ red green blue } } } ] ),
|
241
|
+
"via constructor and method"
|
242
|
+
)
|
243
|
+
|
244
|
+
end
|
245
|
+
|
125
246
|
def test_td
|
126
247
|
|
127
248
|
data = Array[
|
@@ -182,6 +303,66 @@ class Test_Attributes < Test::Unit::TestCase
|
|
182
303
|
|
183
304
|
end
|
184
305
|
|
306
|
+
def test_td_lambda
|
307
|
+
|
308
|
+
data = Array[
|
309
|
+
%w(header1 header2 header3 header4),
|
310
|
+
%w(foo1 bar1 baz1 qux1),
|
311
|
+
%w(foo2 bar2 baz2 qux2),
|
312
|
+
%w(foo3 bar3 baz3 qux3),
|
313
|
+
%w(foo4 bar4 baz4 qux4)
|
314
|
+
]
|
315
|
+
|
316
|
+
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th><th>header4</th></tr><tr><td>FOO1</td><td>BAR1</td><td>BAZ1</td><td>QUX1</td></tr><tr><td>FOO2</td><td>BAR2</td><td>BAZ2</td><td>QUX2</td></tr><tr><td>FOO3</td><td>BAR3</td><td>BAZ3</td><td>QUX3</td></tr><tr><td>FOO4</td><td>BAR4</td><td>BAZ4</td><td>QUX4</td></tr></table>'
|
317
|
+
|
318
|
+
assert_equal(
|
319
|
+
html,
|
320
|
+
Spreadsheet::HTML.new( 'data' => data, 'td' => lambda { |c| c.upcase } ).generate(),
|
321
|
+
"via constructor only"
|
322
|
+
)
|
323
|
+
assert_equal(
|
324
|
+
html,
|
325
|
+
Spreadsheet::HTML.new().generate( 'data' => data, 'td' => lambda { |c| c.upcase } ),
|
326
|
+
"via method only"
|
327
|
+
)
|
328
|
+
assert_equal(
|
329
|
+
html,
|
330
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( 'td' => lambda { |c| c.upcase } ),
|
331
|
+
"via constructor and method"
|
332
|
+
)
|
333
|
+
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_td_attr_and_lambda
|
337
|
+
|
338
|
+
data = Array[
|
339
|
+
%w(header1 header2 header3 header4),
|
340
|
+
%w(foo1 bar1 baz1 qux1),
|
341
|
+
%w(foo2 bar2 baz2 qux2),
|
342
|
+
%w(foo3 bar3 baz3 qux3),
|
343
|
+
%w(foo4 bar4 baz4 qux4)
|
344
|
+
]
|
345
|
+
|
346
|
+
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th><th>header4</th></tr><tr><td style="color: red;">FOO1</td><td style="color: green;">BAR1</td><td style="color: blue;">BAZ1</td><td style="color: red;">QUX1</td></tr><tr><td style="color: green;">FOO2</td><td style="color: blue;">BAR2</td><td style="color: red;">BAZ2</td><td style="color: green;">QUX2</td></tr><tr><td style="color: blue;">FOO3</td><td style="color: red;">BAR3</td><td style="color: green;">BAZ3</td><td style="color: blue;">QUX3</td></tr><tr><td style="color: red;">FOO4</td><td style="color: green;">BAR4</td><td style="color: blue;">BAZ4</td><td style="color: red;">QUX4</td></tr></table>'
|
347
|
+
|
348
|
+
assert_equal(
|
349
|
+
html,
|
350
|
+
Spreadsheet::HTML.new( 'data' => data, 'td' => [ lambda { |c| c.upcase }, { 'style' => { 'color' => %w{ red green blue } } } ] ).generate(),
|
351
|
+
"via constructor only"
|
352
|
+
)
|
353
|
+
assert_equal(
|
354
|
+
html,
|
355
|
+
Spreadsheet::HTML.new().generate( 'data' => data, 'td' => [ lambda { |c| c.upcase }, { 'style' => { 'color' => %w{ red green blue } } } ] ),
|
356
|
+
"via method only"
|
357
|
+
)
|
358
|
+
assert_equal(
|
359
|
+
html,
|
360
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( 'td' => [ lambda { |c| c.upcase }, { 'style' => { 'color' => %w{ red green blue } } } ] ),
|
361
|
+
"via constructor and method"
|
362
|
+
)
|
363
|
+
|
364
|
+
end
|
365
|
+
|
185
366
|
def test_headings
|
186
367
|
|
187
368
|
data = Array[
|
@@ -230,7 +411,7 @@ class Test_Attributes < Test::Unit::TestCase
|
|
230
411
|
|
231
412
|
end
|
232
413
|
|
233
|
-
def
|
414
|
+
def test_cX_attr
|
234
415
|
|
235
416
|
data = Array[
|
236
417
|
%w(header1 header2 header3),
|
@@ -243,19 +424,85 @@ class Test_Attributes < Test::Unit::TestCase
|
|
243
424
|
assert_equal(
|
244
425
|
html,
|
245
426
|
Spreadsheet::HTML.new( 'data' => data, '_c1' => { 'style' => { 'color' => %w{ red green blue } } } ).generate(),
|
246
|
-
"_c1 via constructor only"
|
427
|
+
"_c1 attr via constructor only"
|
247
428
|
)
|
248
429
|
assert_equal(
|
249
430
|
html,
|
250
431
|
Spreadsheet::HTML.new().generate( 'data' => data, '_c1' => { 'style' => { 'color' => %w{ red green blue } } } ),
|
251
|
-
"_c1 via method only"
|
432
|
+
"_c1 attr via method only"
|
252
433
|
)
|
253
434
|
assert_equal(
|
254
435
|
html,
|
255
436
|
Spreadsheet::HTML.new( 'data' => data ).generate( '_c1' => { 'style' => { 'color' => %w{ red green blue } } } ),
|
256
|
-
"_c1 via constructor and method"
|
437
|
+
"_c1 attr via constructor and method"
|
438
|
+
)
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
def test_cX_lambda
|
443
|
+
|
444
|
+
data = Array[
|
445
|
+
%w(header1 header2 header3),
|
446
|
+
%w(foo1 bar1 baz1),
|
447
|
+
%w(foo2 bar2 baz2),
|
448
|
+
]
|
449
|
+
|
450
|
+
html = '<table><tr><th>header1</th><th>HEADER2</th><th>header3</th></tr><tr><td>foo1</td><td>BAR1</td><td>baz1</td></tr><tr><td>foo2</td><td>BAR2</td><td>baz2</td></tr></table>';
|
451
|
+
|
452
|
+
assert_equal(
|
453
|
+
html,
|
454
|
+
Spreadsheet::HTML.new( 'data' => data, '_c1' => lambda { |c| c.upcase } ).generate(),
|
455
|
+
"_c1 attr via constructor only"
|
456
|
+
)
|
457
|
+
assert_equal(
|
458
|
+
html,
|
459
|
+
Spreadsheet::HTML.new().generate( 'data' => data, '_c1' => lambda { |c| c.upcase } ),
|
460
|
+
"_c1 attr via method only"
|
461
|
+
)
|
462
|
+
assert_equal(
|
463
|
+
html,
|
464
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( '_c1' => lambda { |c| c.upcase } ),
|
465
|
+
"_c1 attr via constructor and method"
|
466
|
+
)
|
467
|
+
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_cX_attr_and_lambda
|
471
|
+
|
472
|
+
data = Array[
|
473
|
+
%w(header1 header2 header3),
|
474
|
+
%w(foo1 bar1 baz1),
|
475
|
+
%w(foo2 bar2 baz2),
|
476
|
+
]
|
477
|
+
|
478
|
+
html = '<table><tr><th>header1</th><th style="color: red;">HEADER2</th><th>header3</th></tr><tr><td>foo1</td><td style="color: green;">BAR1</td><td>baz1</td></tr><tr><td>foo2</td><td style="color: blue;">BAR2</td><td>baz2</td></tr></table>';
|
479
|
+
|
480
|
+
assert_equal(
|
481
|
+
html,
|
482
|
+
Spreadsheet::HTML.new( 'data' => data, '_c1' => [ { 'style' => { 'color' => %w{ red green blue } } }, lambda { |c| c.upcase } ] ).generate(),
|
483
|
+
"_c1 attr via constructor only"
|
484
|
+
)
|
485
|
+
assert_equal(
|
486
|
+
html,
|
487
|
+
Spreadsheet::HTML.new().generate( 'data' => data, '_c1' => [ { 'style' => { 'color' => %w{ red green blue } } }, lambda { |c| c.upcase } ] ),
|
488
|
+
"_c1 attr via method only"
|
489
|
+
)
|
490
|
+
assert_equal(
|
491
|
+
html,
|
492
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( '_c1' => [ { 'style' => { 'color' => %w{ red green blue } } }, lambda { |c| c.upcase } ] ),
|
493
|
+
"_c1 attr via constructor and method"
|
257
494
|
)
|
258
495
|
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_rX_attr
|
499
|
+
|
500
|
+
data = Array[
|
501
|
+
%w(header1 header2 header3),
|
502
|
+
%w(foo1 bar1 baz1),
|
503
|
+
%w(foo2 bar2 baz2),
|
504
|
+
]
|
505
|
+
|
259
506
|
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td style="color: red;">foo1</td><td style="color: green;">bar1</td><td style="color: blue;">baz1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td></tr></table>';
|
260
507
|
|
261
508
|
assert_equal(
|
@@ -274,6 +521,72 @@ class Test_Attributes < Test::Unit::TestCase
|
|
274
521
|
"_r1 via constructor and method"
|
275
522
|
)
|
276
523
|
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_rX_lambda
|
527
|
+
|
528
|
+
data = Array[
|
529
|
+
%w(header1 header2 header3),
|
530
|
+
%w(foo1 bar1 baz1),
|
531
|
+
%w(foo2 bar2 baz2),
|
532
|
+
]
|
533
|
+
|
534
|
+
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td>FOO1</td><td>BAR1</td><td>BAZ1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td></tr></table>';
|
535
|
+
|
536
|
+
assert_equal(
|
537
|
+
html,
|
538
|
+
Spreadsheet::HTML.new( 'data' => data, '_r1' => lambda { |c| c.upcase } ).generate(),
|
539
|
+
"_r1 attr via constructor only"
|
540
|
+
)
|
541
|
+
assert_equal(
|
542
|
+
html,
|
543
|
+
Spreadsheet::HTML.new().generate( 'data' => data, '_r1' => lambda { |c| c.upcase } ),
|
544
|
+
"_r1 attr via method only"
|
545
|
+
)
|
546
|
+
assert_equal(
|
547
|
+
html,
|
548
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( '_r1' => lambda { |c| c.upcase } ),
|
549
|
+
"_r1 attr via constructor and method"
|
550
|
+
)
|
551
|
+
|
552
|
+
end
|
553
|
+
|
554
|
+
def test_rX_attr_and_lambda
|
555
|
+
|
556
|
+
data = Array[
|
557
|
+
%w(header1 header2 header3),
|
558
|
+
%w(foo1 bar1 baz1),
|
559
|
+
%w(foo2 bar2 baz2),
|
560
|
+
]
|
561
|
+
|
562
|
+
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td style="color: red;">FOO1</td><td style="color: green;">BAR1</td><td style="color: blue;">BAZ1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td></tr></table>';
|
563
|
+
|
564
|
+
assert_equal(
|
565
|
+
html,
|
566
|
+
Spreadsheet::HTML.new( 'data' => data, '_r1' => [ { 'style' => { 'color' => %w{ red green blue } } }, lambda { |c| c.upcase } ] ).generate(),
|
567
|
+
"_r1 attr via constructor only"
|
568
|
+
)
|
569
|
+
assert_equal(
|
570
|
+
html,
|
571
|
+
Spreadsheet::HTML.new().generate( 'data' => data, '_r1' => [ { 'style' => { 'color' => %w{ red green blue } } }, lambda { |c| c.upcase } ] ),
|
572
|
+
"_r1 attr via method only"
|
573
|
+
)
|
574
|
+
assert_equal(
|
575
|
+
html,
|
576
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( '_r1' => [ { 'style' => { 'color' => %w{ red green blue } } }, lambda { |c| c.upcase } ] ),
|
577
|
+
"_r1 attr via constructor and method"
|
578
|
+
)
|
579
|
+
|
580
|
+
end
|
581
|
+
|
582
|
+
def test_rXcX_attr
|
583
|
+
|
584
|
+
data = Array[
|
585
|
+
%w(header1 header2 header3),
|
586
|
+
%w(foo1 bar1 baz1),
|
587
|
+
%w(foo2 bar2 baz2),
|
588
|
+
]
|
589
|
+
|
277
590
|
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td>foo1</td><td>bar1</td><td style="color: red;">baz1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td></tr></table>';
|
278
591
|
|
279
592
|
assert_equal(
|
@@ -294,4 +607,60 @@ class Test_Attributes < Test::Unit::TestCase
|
|
294
607
|
|
295
608
|
end
|
296
609
|
|
610
|
+
def test_rXcX_lambda
|
611
|
+
|
612
|
+
data = Array[
|
613
|
+
%w(header1 header2 header3),
|
614
|
+
%w(foo1 bar1 baz1),
|
615
|
+
%w(foo2 bar2 baz2),
|
616
|
+
]
|
617
|
+
|
618
|
+
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td>foo1</td><td>bar1</td><td>BAZ1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td></tr></table>';
|
619
|
+
|
620
|
+
assert_equal(
|
621
|
+
html,
|
622
|
+
Spreadsheet::HTML.new( 'data' => data, '_r1c2' => lambda { |c| c.upcase } ).generate(),
|
623
|
+
"_r1c2 attr via constructor only"
|
624
|
+
)
|
625
|
+
assert_equal(
|
626
|
+
html,
|
627
|
+
Spreadsheet::HTML.new().generate( 'data' => data, '_r1c2' => lambda { |c| c.upcase } ),
|
628
|
+
"_r1c2 attr via method only"
|
629
|
+
)
|
630
|
+
assert_equal(
|
631
|
+
html,
|
632
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( '_r1c2' => lambda { |c| c.upcase } ),
|
633
|
+
"_r1c2 attr via constructor and method"
|
634
|
+
)
|
635
|
+
|
636
|
+
end
|
637
|
+
|
638
|
+
def test_rXcX_attr_and_lambda
|
639
|
+
|
640
|
+
data = Array[
|
641
|
+
%w(header1 header2 header3),
|
642
|
+
%w(foo1 bar1 baz1),
|
643
|
+
%w(foo2 bar2 baz2),
|
644
|
+
]
|
645
|
+
|
646
|
+
html = '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td>foo1</td><td>bar1</td><td class="foo">BAZ1</td></tr><tr><td>foo2</td><td>bar2</td><td>baz2</td></tr></table>';
|
647
|
+
|
648
|
+
assert_equal(
|
649
|
+
html,
|
650
|
+
Spreadsheet::HTML.new( 'data' => data, '_r1c2' => [ { 'class' => 'foo' }, lambda { |c| c.upcase } ] ).generate(),
|
651
|
+
"_r1c2 attr via constructor only"
|
652
|
+
)
|
653
|
+
assert_equal(
|
654
|
+
html,
|
655
|
+
Spreadsheet::HTML.new().generate( 'data' => data, '_r1c2' => [ { 'class' => 'foo' }, lambda { |c| c.upcase } ] ),
|
656
|
+
"_r1c2 attr via method only"
|
657
|
+
)
|
658
|
+
assert_equal(
|
659
|
+
html,
|
660
|
+
Spreadsheet::HTML.new( 'data' => data ).generate( '_r1c2' => [ { 'class' => 'foo' }, lambda { |c| c.upcase } ] ),
|
661
|
+
"_r1c2 attr via constructor and method"
|
662
|
+
)
|
663
|
+
|
664
|
+
end
|
665
|
+
|
297
666
|
end
|