html-table 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +1 -3
- data/Rakefile +145 -142
- data/doc/table_content.rdoc +15 -15
- data/examples/advanced.rb +128 -128
- data/examples/intermediate1.rb +72 -72
- data/examples/intermediate2.rb +62 -62
- data/examples/intermediate3.rb +46 -46
- data/examples/simple1.rb +39 -39
- data/examples/simple2.rb +47 -47
- data/examples/simple3.rb +41 -41
- data/html-table.gemspec +21 -20
- data/lib/html/attribute_handler.rb +403 -403
- data/lib/html/body.rb +38 -38
- data/lib/html/caption.rb +48 -48
- data/lib/html/col.rb +41 -41
- data/lib/html/colgroup.rb +113 -113
- data/lib/html/content.rb +18 -18
- data/lib/html/data.rb +68 -68
- data/lib/html/foot.rb +49 -49
- data/lib/html/head.rb +49 -49
- data/lib/html/header.rb +65 -65
- data/lib/html/html_handler.rb +120 -120
- data/lib/html/row.rb +188 -188
- data/lib/html/table.rb +320 -318
- data/lib/html/tablesection.rb +48 -48
- data/lib/html/tag_handler.rb +121 -121
- data/test/test_attribute_handler.rb +364 -364
- data/test/test_body.rb +90 -90
- data/test/test_caption.rb +83 -83
- data/test/test_col.rb +43 -43
- data/test/test_colgroup.rb +92 -92
- data/test/test_data.rb +80 -80
- data/test/test_foot.rb +114 -114
- data/test/test_head.rb +107 -107
- data/test/test_header.rb +80 -80
- data/test/test_html_handler.rb +40 -40
- data/test/test_row.rb +144 -144
- data/test/test_table.rb +157 -157
- data/test/test_tablesection.rb +45 -45
- data/test/test_tag_handler.rb +93 -93
- metadata +30 -34
data/examples/simple3.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# simple3.rb
|
3
|
-
#
|
4
|
-
# Very plain HTML Table with rows and data implicitly created. This
|
5
|
-
# script passes an argument to the constructor, which is automatically
|
6
|
-
# interpreted as content.
|
7
|
-
#
|
8
|
-
# You can run this script via the "example:simple3" rake task.
|
9
|
-
#######################################################################
|
10
|
-
require 'html/table'
|
11
|
-
include HTML
|
12
|
-
|
13
|
-
m = [
|
14
|
-
['foo', 'bar', 'baz'],
|
15
|
-
[1, 2, 3],
|
16
|
-
['hello', 'world']
|
17
|
-
]
|
18
|
-
|
19
|
-
table = Table.new(m)
|
20
|
-
|
21
|
-
puts table.html
|
22
|
-
|
23
|
-
=begin
|
24
|
-
### OUTPUT ###
|
25
|
-
<table>
|
26
|
-
<tr>
|
27
|
-
<td>foo</td>
|
28
|
-
<td>bar</td>
|
29
|
-
<td>baz</td>
|
30
|
-
</tr>
|
31
|
-
<tr>
|
32
|
-
<td>1</td>
|
33
|
-
<td>2</td>
|
34
|
-
<td>3</td>
|
35
|
-
</tr>
|
36
|
-
<tr>
|
37
|
-
<td>hello</td>
|
38
|
-
<td>world</td>
|
39
|
-
</tr>
|
40
|
-
</table>
|
41
|
-
=end
|
1
|
+
#######################################################################
|
2
|
+
# simple3.rb
|
3
|
+
#
|
4
|
+
# Very plain HTML Table with rows and data implicitly created. This
|
5
|
+
# script passes an argument to the constructor, which is automatically
|
6
|
+
# interpreted as content.
|
7
|
+
#
|
8
|
+
# You can run this script via the "example:simple3" rake task.
|
9
|
+
#######################################################################
|
10
|
+
require 'html/table'
|
11
|
+
include HTML
|
12
|
+
|
13
|
+
m = [
|
14
|
+
['foo', 'bar', 'baz'],
|
15
|
+
[1, 2, 3],
|
16
|
+
['hello', 'world']
|
17
|
+
]
|
18
|
+
|
19
|
+
table = Table.new(m)
|
20
|
+
|
21
|
+
puts table.html
|
22
|
+
|
23
|
+
=begin
|
24
|
+
### OUTPUT ###
|
25
|
+
<table>
|
26
|
+
<tr>
|
27
|
+
<td>foo</td>
|
28
|
+
<td>bar</td>
|
29
|
+
<td>baz</td>
|
30
|
+
</tr>
|
31
|
+
<tr>
|
32
|
+
<td>1</td>
|
33
|
+
<td>2</td>
|
34
|
+
<td>3</td>
|
35
|
+
</tr>
|
36
|
+
<tr>
|
37
|
+
<td>hello</td>
|
38
|
+
<td>world</td>
|
39
|
+
</tr>
|
40
|
+
</table>
|
41
|
+
=end
|
data/html-table.gemspec
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
|
4
|
-
gem.name
|
5
|
-
gem.version
|
6
|
-
gem.author
|
7
|
-
gem.
|
8
|
-
gem.
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'html-table'
|
5
|
+
gem.version = '1.3.4'
|
6
|
+
gem.author = 'Daniel J. Berger'
|
7
|
+
gem.license = 'Artistic 2.0'
|
8
|
+
gem.email = 'djberg96@gmail.com'
|
9
|
+
gem.homepage = 'http://shards.rubyforge.org'
|
10
|
+
gem.summary = 'A Ruby interface for generating HTML tables'
|
11
|
+
gem.test_files = Dir['test/*.rb']
|
12
|
+
gem.has_rdoc = true
|
13
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
14
|
+
|
9
15
|
gem.rubyforge_project = 'shards'
|
10
|
-
gem.
|
11
|
-
|
12
|
-
gem.description = 'A Ruby interface for generating HTML tables'
|
13
|
-
gem.test_files = Dir['test/*.rb']
|
14
|
-
gem.has_rdoc = true
|
15
|
-
gem.files = Dir['lib/html/*'] + Dir['[A-Z]*'] + Dir['examples/*.rb'] + Dir['test/*'] + Dir['doc/*']
|
16
|
-
gem.files.reject! { |fn| fn.include? 'CVS' }
|
17
|
-
gem.extra_rdoc_files = ['README', 'CHANGES'] + Dir['doc/*.rdoc']
|
18
|
-
gem.require_path = 'lib'
|
16
|
+
gem.extra_rdoc_files = ['README', 'CHANGES'] + Dir['doc/*.rdoc']
|
17
|
+
|
19
18
|
gem.add_dependency('strongtyping')
|
20
|
-
gem.add_dependency('test-unit')
|
21
19
|
gem.add_dependency('structured_warnings')
|
22
|
-
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
gem.add_development_dependency('test-unit')
|
22
|
+
|
23
|
+
gem.description = <<-EOF
|
24
|
+
The html-table library provides an interface for generating HTML tables
|
25
|
+
in a syntax comfortable to Ruby programmers, but with some enforcement
|
26
|
+
of where certain elements can be placed.
|
27
|
+
EOF
|
27
28
|
end
|
@@ -1,403 +1,403 @@
|
|
1
|
-
# This module creates methods for each of the various attributes associated
|
2
|
-
# with HTML tables. In some cases validation is done on the setters.
|
3
|
-
#--
|
4
|
-
# The seemingly redundant writer methods were left here for backwards
|
5
|
-
# compatibility and for those who may not prefer the DSI.
|
6
|
-
#
|
7
|
-
module AttributeHandler
|
8
|
-
def abbr(string = nil)
|
9
|
-
@abbr ||= nil
|
10
|
-
self.abbr = string if string
|
11
|
-
@abbr
|
12
|
-
end
|
13
|
-
|
14
|
-
def abbr=(string)
|
15
|
-
@abbr = string
|
16
|
-
modify_html("abbr", string)
|
17
|
-
end
|
18
|
-
|
19
|
-
def align(position = nil)
|
20
|
-
@align ||= nil
|
21
|
-
self.align = position if position
|
22
|
-
@align
|
23
|
-
end
|
24
|
-
|
25
|
-
def align=(position)
|
26
|
-
valid = %w/top bottom left center right/
|
27
|
-
raise ArgumentError unless valid.include?(position.downcase)
|
28
|
-
@align = position
|
29
|
-
modify_html("align", position)
|
30
|
-
end
|
31
|
-
|
32
|
-
def axis(string = nil)
|
33
|
-
@axis ||= nil
|
34
|
-
self.axis = string if string
|
35
|
-
@axis
|
36
|
-
end
|
37
|
-
|
38
|
-
def axis=(string)
|
39
|
-
@axis = string
|
40
|
-
modify_html("axis", string)
|
41
|
-
end
|
42
|
-
|
43
|
-
def background(url = nil)
|
44
|
-
@background ||= nil
|
45
|
-
self.background = url if url
|
46
|
-
@background
|
47
|
-
end
|
48
|
-
|
49
|
-
def background=(url)
|
50
|
-
raise TypeError unless url.kind_of?(String)
|
51
|
-
msg = "'background' is a non-standard extension"
|
52
|
-
warn NonStandardExtensionWarning, msg
|
53
|
-
@background = url
|
54
|
-
modify_html("background", url)
|
55
|
-
end
|
56
|
-
|
57
|
-
def bgcolor(color = nil)
|
58
|
-
@bgcolor ||= nil
|
59
|
-
self.bgcolor = color if color
|
60
|
-
@bgcolor
|
61
|
-
end
|
62
|
-
|
63
|
-
def bgcolor=(color)
|
64
|
-
@bgcolor = color
|
65
|
-
modify_html("bgcolor", color)
|
66
|
-
end
|
67
|
-
|
68
|
-
def border(num = nil)
|
69
|
-
@border ||= nil
|
70
|
-
self.border = num if num
|
71
|
-
@border
|
72
|
-
end
|
73
|
-
|
74
|
-
# Allow either true/false or an integer
|
75
|
-
def border=(num)
|
76
|
-
if num.kind_of?(TrueClass)
|
77
|
-
modify_html("border", true)
|
78
|
-
elsif num.kind_of?(FalseClass)
|
79
|
-
# Do nothing
|
80
|
-
else
|
81
|
-
@border = num.to_i
|
82
|
-
modify_html("border", num.to_i)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def bordercolor(color = nil)
|
87
|
-
@bordercolor ||= nil
|
88
|
-
self.bordercolor = color if color
|
89
|
-
@bordercolor
|
90
|
-
end
|
91
|
-
|
92
|
-
def bordercolor=(color)
|
93
|
-
@bordercolor = color
|
94
|
-
msg = "'bordercolor' is a non-standard extension"
|
95
|
-
warn NonStandardExtensionWarning, msg
|
96
|
-
modify_html("bordercolor", color)
|
97
|
-
end
|
98
|
-
|
99
|
-
def bordercolordark(color = nil)
|
100
|
-
@bordercolordark ||= nil
|
101
|
-
self.bordercolordark = color if color
|
102
|
-
@bordercolordark
|
103
|
-
end
|
104
|
-
|
105
|
-
def bordercolordark=(color)
|
106
|
-
@bordercolordark = color
|
107
|
-
msg = "'bordercolordark' is a non-standard extension"
|
108
|
-
warn NonStandardExtensionWarning, msg
|
109
|
-
modify_html("bordercolordark", color)
|
110
|
-
end
|
111
|
-
|
112
|
-
def bordercolorlight(color = nil)
|
113
|
-
@bordercolorlight ||= nil
|
114
|
-
self.bordercolorlight = color if color
|
115
|
-
@bordercolorlight
|
116
|
-
end
|
117
|
-
|
118
|
-
def bordercolorlight=(color)
|
119
|
-
@bordercolorlight = color
|
120
|
-
msg = "'bordercolorlight' is a non-standard extension"
|
121
|
-
warn NonStandardExtensionWarning, msg
|
122
|
-
modify_html("bordercolorlight", @bordercolorlight)
|
123
|
-
end
|
124
|
-
|
125
|
-
def cellpadding(num = nil)
|
126
|
-
@cellpadding ||= nil
|
127
|
-
self.cellpadding = num if num
|
128
|
-
@cellpadding
|
129
|
-
end
|
130
|
-
|
131
|
-
def cellpadding=(num)
|
132
|
-
raise ArgumentError if num.to_i < 0
|
133
|
-
@cellpadding = num.to_i
|
134
|
-
modify_html("cellpadding", @cellpadding)
|
135
|
-
end
|
136
|
-
|
137
|
-
def cellspacing(num = nil)
|
138
|
-
@cellspacing ||= nil
|
139
|
-
self.cellspacing = num if num
|
140
|
-
@cellspacing
|
141
|
-
end
|
142
|
-
|
143
|
-
def cellspacing=(num)
|
144
|
-
raise ArgumentError if num.to_i < 0
|
145
|
-
@cellspacing = num.to_i
|
146
|
-
modify_html("cellspacing", @cellspacing)
|
147
|
-
end
|
148
|
-
|
149
|
-
def char(character = nil)
|
150
|
-
@char ||= nil
|
151
|
-
self.char = character if character
|
152
|
-
@char
|
153
|
-
end
|
154
|
-
|
155
|
-
def char=(character)
|
156
|
-
raise ArgumentError if character.to_s.length > 1
|
157
|
-
@char = character.to_s
|
158
|
-
modify_html("char", character.to_s)
|
159
|
-
end
|
160
|
-
|
161
|
-
def charoff(offset = nil)
|
162
|
-
@charoff ||= nil
|
163
|
-
self.charoff = offset if offset
|
164
|
-
@charoff
|
165
|
-
end
|
166
|
-
|
167
|
-
def charoff=(offset)
|
168
|
-
raise ArgumentError if offset.to_i < 0
|
169
|
-
@charoff = offset
|
170
|
-
modify_html("charoff", offset)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Returns the CSS class. The trailing underscore is necessary in order
|
174
|
-
# to avoid conflict with the 'class' keyword.
|
175
|
-
#
|
176
|
-
def class_(klass = nil)
|
177
|
-
@class ||= nil
|
178
|
-
self.class_ = klass if klass
|
179
|
-
@class
|
180
|
-
end
|
181
|
-
|
182
|
-
# Returns the CSS class. The trailing underscore is necessary in order
|
183
|
-
# to avoid conflict with the 'class' keyword.
|
184
|
-
#
|
185
|
-
def class_=(klass)
|
186
|
-
modify_html('class', klass)
|
187
|
-
@class = klass
|
188
|
-
end
|
189
|
-
|
190
|
-
def col(num = nil)
|
191
|
-
@col ||= nil
|
192
|
-
self.col = num if num
|
193
|
-
@col
|
194
|
-
end
|
195
|
-
|
196
|
-
def col=(num)
|
197
|
-
raise ArgumentError if num.to_i < 0
|
198
|
-
@col = num.to_i
|
199
|
-
modify_html("col", @col)
|
200
|
-
end
|
201
|
-
|
202
|
-
def colspan(span = nil)
|
203
|
-
@colspan ||= nil
|
204
|
-
self.colspan = span if span
|
205
|
-
@colspan
|
206
|
-
end
|
207
|
-
|
208
|
-
def colspan=(span)
|
209
|
-
raise ArgumentError if span.to_i < 0
|
210
|
-
@colspan = span.to_i
|
211
|
-
modify_html("colspan", @colspan)
|
212
|
-
end
|
213
|
-
|
214
|
-
# Allows you to configure various attributes by row or row + column.
|
215
|
-
#
|
216
|
-
def configure(row, col=nil, &block)
|
217
|
-
if col
|
218
|
-
begin
|
219
|
-
yield self[row][col]
|
220
|
-
rescue NameError
|
221
|
-
msg = "No column to configure in a " + self.class.to_s + " class"
|
222
|
-
raise ArgumentError, msg
|
223
|
-
end
|
224
|
-
else
|
225
|
-
yield self[row]
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
# Returns the HTML content (i.e. text).
|
230
|
-
#
|
231
|
-
def content(arg = nil, &block)
|
232
|
-
case arg
|
233
|
-
when String
|
234
|
-
self.content = Table::Content.new(arg, &block)
|
235
|
-
when Array
|
236
|
-
arg.each{ |e|
|
237
|
-
if e.kind_of?(Array)
|
238
|
-
row = Table::Row.new
|
239
|
-
e.each{ |element| row.push(Table::Content.new(element, &block)) }
|
240
|
-
self.push(row)
|
241
|
-
else
|
242
|
-
self.content = Table::Content.new(e, &block)
|
243
|
-
end
|
244
|
-
}
|
245
|
-
else
|
246
|
-
self.content = arg if arg
|
247
|
-
end
|
248
|
-
@html_body
|
249
|
-
end
|
250
|
-
|
251
|
-
alias data content
|
252
|
-
|
253
|
-
def frame(type = nil)
|
254
|
-
@frame ||= nil
|
255
|
-
self.frame = type if type
|
256
|
-
@frame
|
257
|
-
end
|
258
|
-
|
259
|
-
def frame=(type)
|
260
|
-
valid = %w/border void above below hsides lhs rhs vsides box/
|
261
|
-
raise ArgumentError unless valid.include?(type.downcase)
|
262
|
-
@frame = type
|
263
|
-
modify_html("frame", @frame)
|
264
|
-
end
|
265
|
-
|
266
|
-
def height(num = nil)
|
267
|
-
@height ||= nil
|
268
|
-
self.height = num if num
|
269
|
-
@height
|
270
|
-
end
|
271
|
-
|
272
|
-
def height=(num)
|
273
|
-
raise ArgumentError if num.to_i < 0
|
274
|
-
@height = num.to_i
|
275
|
-
modify_html("height", @height)
|
276
|
-
end
|
277
|
-
|
278
|
-
def hspace(num = nil)
|
279
|
-
@hspace ||= nil
|
280
|
-
self.hspace = num if num
|
281
|
-
@hspace
|
282
|
-
end
|
283
|
-
|
284
|
-
def hspace=(num)
|
285
|
-
raise ArgumentError if num.to_i < 0
|
286
|
-
@hspace = num.to_i
|
287
|
-
modify_html("hspace", @hspace)
|
288
|
-
end
|
289
|
-
|
290
|
-
def nowrap(bool = nil)
|
291
|
-
@nowrap ||= nil
|
292
|
-
self.nowrap = bool if bool
|
293
|
-
@nowrap
|
294
|
-
end
|
295
|
-
|
296
|
-
def nowrap=(bool)
|
297
|
-
unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
|
298
|
-
raise TypeError
|
299
|
-
end
|
300
|
-
@nowrap = bool
|
301
|
-
modify_html("nowrap", @nowrap)
|
302
|
-
end
|
303
|
-
|
304
|
-
def rowspan(num = nil)
|
305
|
-
@rowspan ||= nil
|
306
|
-
self.rowspan = num if num
|
307
|
-
@rowspan
|
308
|
-
end
|
309
|
-
|
310
|
-
def rowspan=(num)
|
311
|
-
raise ArgumentError if num.to_i < 0
|
312
|
-
@rowspan = num.to_i
|
313
|
-
modify_html("rowspan", @rowspan)
|
314
|
-
end
|
315
|
-
|
316
|
-
def rules(edges = nil)
|
317
|
-
@rules ||= nil
|
318
|
-
self.rules = edges if edges
|
319
|
-
@rules
|
320
|
-
end
|
321
|
-
|
322
|
-
def rules=(edges)
|
323
|
-
valid = %w/all groups rows cols none/
|
324
|
-
raise ArgumentError unless valid.include?(edges.to_s.downcase)
|
325
|
-
@rules = edges
|
326
|
-
modify_html("rules", @rules)
|
327
|
-
end
|
328
|
-
|
329
|
-
def span(num = nil)
|
330
|
-
@span ||= nil
|
331
|
-
self.span = num if num
|
332
|
-
@span
|
333
|
-
end
|
334
|
-
|
335
|
-
def span=(num)
|
336
|
-
raise ArgumentError if num.to_i < 0
|
337
|
-
@span = num.to_i
|
338
|
-
modify_html("span", @span)
|
339
|
-
end
|
340
|
-
|
341
|
-
def style(string = nil)
|
342
|
-
@style ||= nil
|
343
|
-
self.style = string if string
|
344
|
-
@style
|
345
|
-
end
|
346
|
-
|
347
|
-
def style=(string)
|
348
|
-
@style = string.to_s
|
349
|
-
modify_html("style", @style)
|
350
|
-
end
|
351
|
-
|
352
|
-
def summary(string = nil)
|
353
|
-
@summary ||= nil
|
354
|
-
self.summary = string if string
|
355
|
-
@summary
|
356
|
-
end
|
357
|
-
|
358
|
-
def summary=(string)
|
359
|
-
@summary = string.to_s
|
360
|
-
modify_html("summary", @summary)
|
361
|
-
end
|
362
|
-
|
363
|
-
def valign(position = nil)
|
364
|
-
@valign ||= nil
|
365
|
-
self.valign = position if position
|
366
|
-
@valign
|
367
|
-
end
|
368
|
-
|
369
|
-
def valign=(position)
|
370
|
-
valid = %w/top center bottom baseline/
|
371
|
-
raise ArgumentError unless valid.include?(position.to_s.downcase)
|
372
|
-
@valign = position
|
373
|
-
modify_html("valign", @valign)
|
374
|
-
end
|
375
|
-
|
376
|
-
def vspace(num = nil)
|
377
|
-
@vspace ||= nil
|
378
|
-
self.vspace = num if num
|
379
|
-
@vspace
|
380
|
-
end
|
381
|
-
|
382
|
-
def vspace=(num)
|
383
|
-
raise ArgumentError if num.to_i < 0
|
384
|
-
@vspace = num.to_i
|
385
|
-
modify_html("vspace", @vspace)
|
386
|
-
end
|
387
|
-
|
388
|
-
def width(num = nil)
|
389
|
-
@width ||= nil
|
390
|
-
self.width = num if num
|
391
|
-
@width
|
392
|
-
end
|
393
|
-
|
394
|
-
def width=(num)
|
395
|
-
if num =~ /%/
|
396
|
-
@width = num
|
397
|
-
else
|
398
|
-
raise ArgumentError if num.to_i < 0
|
399
|
-
@width = num.to_i
|
400
|
-
end
|
401
|
-
modify_html("width", @width)
|
402
|
-
end
|
403
|
-
end
|
1
|
+
# This module creates methods for each of the various attributes associated
|
2
|
+
# with HTML tables. In some cases validation is done on the setters.
|
3
|
+
#--
|
4
|
+
# The seemingly redundant writer methods were left here for backwards
|
5
|
+
# compatibility and for those who may not prefer the DSI.
|
6
|
+
#
|
7
|
+
module AttributeHandler
|
8
|
+
def abbr(string = nil)
|
9
|
+
@abbr ||= nil
|
10
|
+
self.abbr = string if string
|
11
|
+
@abbr
|
12
|
+
end
|
13
|
+
|
14
|
+
def abbr=(string)
|
15
|
+
@abbr = string
|
16
|
+
modify_html("abbr", string)
|
17
|
+
end
|
18
|
+
|
19
|
+
def align(position = nil)
|
20
|
+
@align ||= nil
|
21
|
+
self.align = position if position
|
22
|
+
@align
|
23
|
+
end
|
24
|
+
|
25
|
+
def align=(position)
|
26
|
+
valid = %w/top bottom left center right/
|
27
|
+
raise ArgumentError unless valid.include?(position.downcase)
|
28
|
+
@align = position
|
29
|
+
modify_html("align", position)
|
30
|
+
end
|
31
|
+
|
32
|
+
def axis(string = nil)
|
33
|
+
@axis ||= nil
|
34
|
+
self.axis = string if string
|
35
|
+
@axis
|
36
|
+
end
|
37
|
+
|
38
|
+
def axis=(string)
|
39
|
+
@axis = string
|
40
|
+
modify_html("axis", string)
|
41
|
+
end
|
42
|
+
|
43
|
+
def background(url = nil)
|
44
|
+
@background ||= nil
|
45
|
+
self.background = url if url
|
46
|
+
@background
|
47
|
+
end
|
48
|
+
|
49
|
+
def background=(url)
|
50
|
+
raise TypeError unless url.kind_of?(String)
|
51
|
+
msg = "'background' is a non-standard extension"
|
52
|
+
warn NonStandardExtensionWarning, msg
|
53
|
+
@background = url
|
54
|
+
modify_html("background", url)
|
55
|
+
end
|
56
|
+
|
57
|
+
def bgcolor(color = nil)
|
58
|
+
@bgcolor ||= nil
|
59
|
+
self.bgcolor = color if color
|
60
|
+
@bgcolor
|
61
|
+
end
|
62
|
+
|
63
|
+
def bgcolor=(color)
|
64
|
+
@bgcolor = color
|
65
|
+
modify_html("bgcolor", color)
|
66
|
+
end
|
67
|
+
|
68
|
+
def border(num = nil)
|
69
|
+
@border ||= nil
|
70
|
+
self.border = num if num
|
71
|
+
@border
|
72
|
+
end
|
73
|
+
|
74
|
+
# Allow either true/false or an integer
|
75
|
+
def border=(num)
|
76
|
+
if num.kind_of?(TrueClass)
|
77
|
+
modify_html("border", true)
|
78
|
+
elsif num.kind_of?(FalseClass)
|
79
|
+
# Do nothing
|
80
|
+
else
|
81
|
+
@border = num.to_i
|
82
|
+
modify_html("border", num.to_i)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def bordercolor(color = nil)
|
87
|
+
@bordercolor ||= nil
|
88
|
+
self.bordercolor = color if color
|
89
|
+
@bordercolor
|
90
|
+
end
|
91
|
+
|
92
|
+
def bordercolor=(color)
|
93
|
+
@bordercolor = color
|
94
|
+
msg = "'bordercolor' is a non-standard extension"
|
95
|
+
warn NonStandardExtensionWarning, msg
|
96
|
+
modify_html("bordercolor", color)
|
97
|
+
end
|
98
|
+
|
99
|
+
def bordercolordark(color = nil)
|
100
|
+
@bordercolordark ||= nil
|
101
|
+
self.bordercolordark = color if color
|
102
|
+
@bordercolordark
|
103
|
+
end
|
104
|
+
|
105
|
+
def bordercolordark=(color)
|
106
|
+
@bordercolordark = color
|
107
|
+
msg = "'bordercolordark' is a non-standard extension"
|
108
|
+
warn NonStandardExtensionWarning, msg
|
109
|
+
modify_html("bordercolordark", color)
|
110
|
+
end
|
111
|
+
|
112
|
+
def bordercolorlight(color = nil)
|
113
|
+
@bordercolorlight ||= nil
|
114
|
+
self.bordercolorlight = color if color
|
115
|
+
@bordercolorlight
|
116
|
+
end
|
117
|
+
|
118
|
+
def bordercolorlight=(color)
|
119
|
+
@bordercolorlight = color
|
120
|
+
msg = "'bordercolorlight' is a non-standard extension"
|
121
|
+
warn NonStandardExtensionWarning, msg
|
122
|
+
modify_html("bordercolorlight", @bordercolorlight)
|
123
|
+
end
|
124
|
+
|
125
|
+
def cellpadding(num = nil)
|
126
|
+
@cellpadding ||= nil
|
127
|
+
self.cellpadding = num if num
|
128
|
+
@cellpadding
|
129
|
+
end
|
130
|
+
|
131
|
+
def cellpadding=(num)
|
132
|
+
raise ArgumentError if num.to_i < 0
|
133
|
+
@cellpadding = num.to_i
|
134
|
+
modify_html("cellpadding", @cellpadding)
|
135
|
+
end
|
136
|
+
|
137
|
+
def cellspacing(num = nil)
|
138
|
+
@cellspacing ||= nil
|
139
|
+
self.cellspacing = num if num
|
140
|
+
@cellspacing
|
141
|
+
end
|
142
|
+
|
143
|
+
def cellspacing=(num)
|
144
|
+
raise ArgumentError if num.to_i < 0
|
145
|
+
@cellspacing = num.to_i
|
146
|
+
modify_html("cellspacing", @cellspacing)
|
147
|
+
end
|
148
|
+
|
149
|
+
def char(character = nil)
|
150
|
+
@char ||= nil
|
151
|
+
self.char = character if character
|
152
|
+
@char
|
153
|
+
end
|
154
|
+
|
155
|
+
def char=(character)
|
156
|
+
raise ArgumentError if character.to_s.length > 1
|
157
|
+
@char = character.to_s
|
158
|
+
modify_html("char", character.to_s)
|
159
|
+
end
|
160
|
+
|
161
|
+
def charoff(offset = nil)
|
162
|
+
@charoff ||= nil
|
163
|
+
self.charoff = offset if offset
|
164
|
+
@charoff
|
165
|
+
end
|
166
|
+
|
167
|
+
def charoff=(offset)
|
168
|
+
raise ArgumentError if offset.to_i < 0
|
169
|
+
@charoff = offset
|
170
|
+
modify_html("charoff", offset)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Returns the CSS class. The trailing underscore is necessary in order
|
174
|
+
# to avoid conflict with the 'class' keyword.
|
175
|
+
#
|
176
|
+
def class_(klass = nil)
|
177
|
+
@class ||= nil
|
178
|
+
self.class_ = klass if klass
|
179
|
+
@class
|
180
|
+
end
|
181
|
+
|
182
|
+
# Returns the CSS class. The trailing underscore is necessary in order
|
183
|
+
# to avoid conflict with the 'class' keyword.
|
184
|
+
#
|
185
|
+
def class_=(klass)
|
186
|
+
modify_html('class', klass)
|
187
|
+
@class = klass
|
188
|
+
end
|
189
|
+
|
190
|
+
def col(num = nil)
|
191
|
+
@col ||= nil
|
192
|
+
self.col = num if num
|
193
|
+
@col
|
194
|
+
end
|
195
|
+
|
196
|
+
def col=(num)
|
197
|
+
raise ArgumentError if num.to_i < 0
|
198
|
+
@col = num.to_i
|
199
|
+
modify_html("col", @col)
|
200
|
+
end
|
201
|
+
|
202
|
+
def colspan(span = nil)
|
203
|
+
@colspan ||= nil
|
204
|
+
self.colspan = span if span
|
205
|
+
@colspan
|
206
|
+
end
|
207
|
+
|
208
|
+
def colspan=(span)
|
209
|
+
raise ArgumentError if span.to_i < 0
|
210
|
+
@colspan = span.to_i
|
211
|
+
modify_html("colspan", @colspan)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Allows you to configure various attributes by row or row + column.
|
215
|
+
#
|
216
|
+
def configure(row, col=nil, &block)
|
217
|
+
if col
|
218
|
+
begin
|
219
|
+
yield self[row][col]
|
220
|
+
rescue NameError
|
221
|
+
msg = "No column to configure in a " + self.class.to_s + " class"
|
222
|
+
raise ArgumentError, msg
|
223
|
+
end
|
224
|
+
else
|
225
|
+
yield self[row]
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Returns the HTML content (i.e. text).
|
230
|
+
#
|
231
|
+
def content(arg = nil, &block)
|
232
|
+
case arg
|
233
|
+
when String
|
234
|
+
self.content = Table::Content.new(arg, &block)
|
235
|
+
when Array
|
236
|
+
arg.each{ |e|
|
237
|
+
if e.kind_of?(Array)
|
238
|
+
row = Table::Row.new
|
239
|
+
e.each{ |element| row.push(Table::Content.new(element, &block)) }
|
240
|
+
self.push(row)
|
241
|
+
else
|
242
|
+
self.content = Table::Content.new(e, &block)
|
243
|
+
end
|
244
|
+
}
|
245
|
+
else
|
246
|
+
self.content = arg if arg
|
247
|
+
end
|
248
|
+
@html_body
|
249
|
+
end
|
250
|
+
|
251
|
+
alias data content
|
252
|
+
|
253
|
+
def frame(type = nil)
|
254
|
+
@frame ||= nil
|
255
|
+
self.frame = type if type
|
256
|
+
@frame
|
257
|
+
end
|
258
|
+
|
259
|
+
def frame=(type)
|
260
|
+
valid = %w/border void above below hsides lhs rhs vsides box/
|
261
|
+
raise ArgumentError unless valid.include?(type.downcase)
|
262
|
+
@frame = type
|
263
|
+
modify_html("frame", @frame)
|
264
|
+
end
|
265
|
+
|
266
|
+
def height(num = nil)
|
267
|
+
@height ||= nil
|
268
|
+
self.height = num if num
|
269
|
+
@height
|
270
|
+
end
|
271
|
+
|
272
|
+
def height=(num)
|
273
|
+
raise ArgumentError if num.to_i < 0
|
274
|
+
@height = num.to_i
|
275
|
+
modify_html("height", @height)
|
276
|
+
end
|
277
|
+
|
278
|
+
def hspace(num = nil)
|
279
|
+
@hspace ||= nil
|
280
|
+
self.hspace = num if num
|
281
|
+
@hspace
|
282
|
+
end
|
283
|
+
|
284
|
+
def hspace=(num)
|
285
|
+
raise ArgumentError if num.to_i < 0
|
286
|
+
@hspace = num.to_i
|
287
|
+
modify_html("hspace", @hspace)
|
288
|
+
end
|
289
|
+
|
290
|
+
def nowrap(bool = nil)
|
291
|
+
@nowrap ||= nil
|
292
|
+
self.nowrap = bool if bool
|
293
|
+
@nowrap
|
294
|
+
end
|
295
|
+
|
296
|
+
def nowrap=(bool)
|
297
|
+
unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
|
298
|
+
raise TypeError
|
299
|
+
end
|
300
|
+
@nowrap = bool
|
301
|
+
modify_html("nowrap", @nowrap)
|
302
|
+
end
|
303
|
+
|
304
|
+
def rowspan(num = nil)
|
305
|
+
@rowspan ||= nil
|
306
|
+
self.rowspan = num if num
|
307
|
+
@rowspan
|
308
|
+
end
|
309
|
+
|
310
|
+
def rowspan=(num)
|
311
|
+
raise ArgumentError if num.to_i < 0
|
312
|
+
@rowspan = num.to_i
|
313
|
+
modify_html("rowspan", @rowspan)
|
314
|
+
end
|
315
|
+
|
316
|
+
def rules(edges = nil)
|
317
|
+
@rules ||= nil
|
318
|
+
self.rules = edges if edges
|
319
|
+
@rules
|
320
|
+
end
|
321
|
+
|
322
|
+
def rules=(edges)
|
323
|
+
valid = %w/all groups rows cols none/
|
324
|
+
raise ArgumentError unless valid.include?(edges.to_s.downcase)
|
325
|
+
@rules = edges
|
326
|
+
modify_html("rules", @rules)
|
327
|
+
end
|
328
|
+
|
329
|
+
def span(num = nil)
|
330
|
+
@span ||= nil
|
331
|
+
self.span = num if num
|
332
|
+
@span
|
333
|
+
end
|
334
|
+
|
335
|
+
def span=(num)
|
336
|
+
raise ArgumentError if num.to_i < 0
|
337
|
+
@span = num.to_i
|
338
|
+
modify_html("span", @span)
|
339
|
+
end
|
340
|
+
|
341
|
+
def style(string = nil)
|
342
|
+
@style ||= nil
|
343
|
+
self.style = string if string
|
344
|
+
@style
|
345
|
+
end
|
346
|
+
|
347
|
+
def style=(string)
|
348
|
+
@style = string.to_s
|
349
|
+
modify_html("style", @style)
|
350
|
+
end
|
351
|
+
|
352
|
+
def summary(string = nil)
|
353
|
+
@summary ||= nil
|
354
|
+
self.summary = string if string
|
355
|
+
@summary
|
356
|
+
end
|
357
|
+
|
358
|
+
def summary=(string)
|
359
|
+
@summary = string.to_s
|
360
|
+
modify_html("summary", @summary)
|
361
|
+
end
|
362
|
+
|
363
|
+
def valign(position = nil)
|
364
|
+
@valign ||= nil
|
365
|
+
self.valign = position if position
|
366
|
+
@valign
|
367
|
+
end
|
368
|
+
|
369
|
+
def valign=(position)
|
370
|
+
valid = %w/top center bottom baseline/
|
371
|
+
raise ArgumentError unless valid.include?(position.to_s.downcase)
|
372
|
+
@valign = position
|
373
|
+
modify_html("valign", @valign)
|
374
|
+
end
|
375
|
+
|
376
|
+
def vspace(num = nil)
|
377
|
+
@vspace ||= nil
|
378
|
+
self.vspace = num if num
|
379
|
+
@vspace
|
380
|
+
end
|
381
|
+
|
382
|
+
def vspace=(num)
|
383
|
+
raise ArgumentError if num.to_i < 0
|
384
|
+
@vspace = num.to_i
|
385
|
+
modify_html("vspace", @vspace)
|
386
|
+
end
|
387
|
+
|
388
|
+
def width(num = nil)
|
389
|
+
@width ||= nil
|
390
|
+
self.width = num if num
|
391
|
+
@width
|
392
|
+
end
|
393
|
+
|
394
|
+
def width=(num)
|
395
|
+
if num =~ /%/
|
396
|
+
@width = num
|
397
|
+
else
|
398
|
+
raise ArgumentError if num.to_i < 0
|
399
|
+
@width = num.to_i
|
400
|
+
end
|
401
|
+
modify_html("width", @width)
|
402
|
+
end
|
403
|
+
end
|