html-table 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ == Description
2
+ A Table::Body object represents a single <TBODY></TBODY> instance for an
3
+ HTML Table.
4
+ == Notes
5
+ In virtually every respect the Table::Body class is identical to
6
+ the Table or Table::Row class. Unlike Table::Foot or Table::Head, there
7
+ can be more than one instance (i.e. it's not a singleton class).
8
+
9
+ A Table::Body contains Table::Row objects.
@@ -0,0 +1,9 @@
1
+ == Description
2
+ A Table::Caption object represents a single <CAPTION></CAPTION> instance
3
+ for an HTML Table.
4
+ == Notes
5
+ The Table::Caption class is virtually identical to the Table::Row::Data
6
+ class. There is one important behavioral difference, however. First,
7
+ there can only be one Table::Caption. If you attempt to add a second one,
8
+ it will merely overwrite the existing one. Second, a Table::Caption is
9
+ always bumped to index 0.
@@ -0,0 +1,8 @@
1
+ == Description
2
+ A Table::ColGroup object represents a single <COLGROUP></COLGROUP>
3
+ instance for an HTML Table.
4
+
5
+ == Notes
6
+ In virtually every respect the Table::ColGroup class is identical to the
7
+ Table::Row class. The only difference, beyond the begin and end tags, is
8
+ that a ColGroup may only contain instances of the Col class.
@@ -0,0 +1,9 @@
1
+ == Description
2
+ A Table::ColGroup::Col object represents a single <COL> instance for an
3
+ HTML Table.
4
+
5
+ == Notes
6
+ In virtually every respect the Table::ColGroup::Col class is identical to
7
+ the Table::Row::Data class. The only differences are that a
8
+ Table::ColGroup::Col instance does not contain any content, nor does it
9
+ include an end tag.
@@ -0,0 +1,8 @@
1
+ == Description
2
+ A Table::Foot object represents a single <TFOOT></TFOOT> instance for an
3
+ HTML Table.
4
+ == Notes
5
+ In virtually every respect the Table::Foot class is identical to
6
+ the Table or Table::Row class. There is one significant difference.
7
+ The Table::Foot class is a singleton. There can be only one
8
+ Table::Foot instance per table.
@@ -0,0 +1,11 @@
1
+ == Description
2
+ A Table::Head object represents a single <THEAD></THEAD> instance for an
3
+ HTML Table.
4
+
5
+ == Notes
6
+ In virtually every respect the Table::Head class is identical to
7
+ the Table or Table::Row class. There are two significant differences.
8
+ First, the Table::Head class is a singleton. There can be only one
9
+ Table::Head instance per table. Second, if an instance of Table::Head
10
+ is added to a table, it will be automatically be put at index 0 (or 1
11
+ if a Table::Caption exists).
@@ -0,0 +1,105 @@
1
+ = Description
2
+ A Table::Row object represents a single <TR></TR> instance for an HTML
3
+ Table. Although it is nested under Table, it is not a subclass of Table.
4
+ It is, however, a subclass of Array.
5
+
6
+ == Synopsis
7
+ require "html/table"
8
+ include HTML
9
+
10
+ table = HTML::Table.new
11
+
12
+ row1 = Table::Row.new{ |r|
13
+ r.align = "left"
14
+ r.bgcolor = "green"
15
+ r.content = ["foo","bar","baz"]
16
+ }
17
+
18
+ row2 = Table::Row.new{ |r|
19
+ r.align = "right"
20
+ r.bgcolor = "blue"
21
+ r.content = "hello world"
22
+ }
23
+
24
+ table.push row1, row2
25
+
26
+ row1.content = "foofoo"
27
+ row1.configure(3){ |d| d.bgcolor = "pink" }
28
+
29
+ row1.push Table::Row::Header.new{ |h|
30
+ h.colspan = 2
31
+ h.content = "This is a table header"
32
+ }
33
+
34
+ row2.push Table::Row::Header.new{ |h|
35
+ h.colspan = 2
36
+ h.content = "This is also a table header"
37
+ }
38
+
39
+ puts table.html
40
+
41
+ #### output ####
42
+ <table>
43
+ <tr align='left' bgcolor='green'>
44
+ <td>foo</td>
45
+ <td>bar</td>
46
+ <td>baz</td>
47
+ <td bgcolor='pink'>foofoo</td>
48
+ <th colspan=2>This is a table header</th>
49
+ </tr>
50
+ <tr align='right' bgcolor='blue'>
51
+ <td>hello world</td>
52
+ <th colspan=2>This is also a table header</th>
53
+ </tr>
54
+ </table>
55
+
56
+ See the 'examples' directory for more examples.
57
+
58
+ == Mixins
59
+ Table::Row is a subclass of Array and therefore mixes in Enumerable. It
60
+ also mixes in Attribute_Handler.
61
+
62
+ == Class Methods
63
+ Table::Row.new(arg=nil)
64
+ Table::Row.new(arg=nil){ |t| ... }
65
+ Creates a new table. You can set attributes for the TableRow by passing
66
+ a block.
67
+
68
+ If +arg+ is supplied, it is automatically interpreted to be content.
69
+ This is a shortcut for Table::Row.new{ |r| r.content = '...' }.
70
+
71
+ == Instance Methods
72
+ Table::Row#[]=(index,obj)
73
+ Assigns +obj+ to index. The +obj+ must be a Table::Row::Header or
74
+ Table::Row::Data object, or a TypeError is raised.
75
+
76
+ Table::Row#content
77
+ Returns the HTML content of the TableRow instance, i.e. the stuff between
78
+ the <TR> and </TR> tags.
79
+
80
+ Table::Row#content=(args)
81
+ Because a Table::Row doesn't store any of its own content, the arguments
82
+ to this method must be a Table::Row::Data object, a Table::Row::Header
83
+ object, or a String (or an array of any of these). In the latter case,
84
+ a single Table::Row::Data object is created for each string.
85
+
86
+ Table::Row#html
87
+ Returns the entire HTML content of the TableRow instance.
88
+
89
+ Table::Row#push(obj)
90
+ Pushes +obj+ onto the Table::Row. The +obj+ must be a
91
+ Table::Row::Data or Table::Row::Header object, or a TypeError is
92
+ raised.
93
+
94
+ Table::Row#unshift(obj)
95
+ Unshifts +obj+ onto the Table::Row. The same rules for push apply
96
+ to unshift as well.
97
+
98
+ == Notes
99
+ String attributes are quoted. Numeric attributes are not.
100
+
101
+ Some attributes have type checking. Some check for valid arguments. In
102
+ the latter case, it is case-insensitive.
103
+
104
+ Using a non-standard extension (e.g. "background") will send a warning to
105
+ STDERR in $VERBOSE (-w) mode.
@@ -0,0 +1,92 @@
1
+ == Description
2
+ A Table::Row::Data object represents a single <TD></TD> instance for an HTML
3
+ Table. For purposes of html-table, it also represents a "column"
4
+
5
+ == Synopsis
6
+ require "html/table"
7
+ require HTML
8
+
9
+ Table::Row.end_tags = false
10
+ Table::Row::Data.end_tags = false
11
+
12
+ table = Table.new{ |t| t.border = 1 }
13
+ row = Table::Row.new
14
+
15
+ col1 = Table::Row::Data.new{ |d|
16
+ d.abbr = "test"
17
+ d.align = "right"
18
+ d.content = "hello world"
19
+ }
20
+
21
+ col2 = Table::Row::Data.new{ |d|
22
+ d.align = "center"
23
+ d.content = "Matz rules!"
24
+ }
25
+
26
+ col3 = Table::Row::Data.new{ |d|
27
+ d.align = "left"
28
+ d.content = "Foo!"
29
+ }
30
+
31
+ row.push col1, col2, col3
32
+
33
+ puts table.html
34
+
35
+ #### output ####
36
+ <table border=1>
37
+ <tr>
38
+ <td abbr='test' align='right'>hello world
39
+ <td align='center'>Matz rules!
40
+ <td align='left'>Foo!
41
+ </table>
42
+
43
+ See the 'examples' directory under 'doc' for more examples.
44
+
45
+ == Mixins
46
+ Table::Row::Data mixes in Attribute_Handler.
47
+
48
+ == Class Methods
49
+ Table::Row::Data.new(arg=nil)
50
+ Table::Row::Data.new(arg=nil){ |t| ... }
51
+ Creates a new table. You can set attributes for the Table::Row::Data by
52
+ passing a block.
53
+
54
+ If +arg+ is supplied, it is automatically interpreted to be content.
55
+ This is a shortcut for Table::Row::Data.new{ |d| d.content = '...' }.
56
+
57
+ Table::Row::Data.end_tags
58
+ Returns true or false to indicate whether end tags are included or not.
59
+
60
+ Table::Row::Data.end_tags=(bool)
61
+ Sets whether or not end tags are included in the html.
62
+
63
+ Table::Row::Data.indent_level
64
+ Returns the current number of spaces that <TD> tags are indented. The
65
+ default is 6.
66
+
67
+ Table::Row::Data.indent_level=(num)
68
+ Sets the number of spaces that <TD> tags are indented.
69
+
70
+ == Instance Methods
71
+ TableData#content
72
+ Returns the content of the TableData object, i.e. the stuff between <TD>
73
+ and </TD>.
74
+
75
+ Table::Row::Data#content=(string)
76
+ Sets the content for the TableData object, i.e. the stuff between <TD>
77
+ and </TD>.
78
+
79
+ Table::Row::Data#html
80
+ Returns all html content for the TableData instance.
81
+
82
+ == Notes
83
+ The end tags for Table::Row::Data objects are are the same line as the
84
+ begin tags.
85
+
86
+ String attributes are quoted. Numeric attributes are not.
87
+
88
+ Some attributes have type checking. Some check for valid arguments. In
89
+ the latter case, it is case-insensitive.
90
+
91
+ Using a non-standard extension (e.g. "background") will send a warning to
92
+ STDERR in $VERBOSE (-w) mode.
@@ -0,0 +1,7 @@
1
+ == Description
2
+ A Table::Row::Header object represents a single <TH></TH> instance for
3
+ an HTML Table.
4
+
5
+ == Notes
6
+ The Table::Row::Header class is identical in every way to the
7
+ Table::Row::Data class, except for the begin and end tags.
@@ -0,0 +1,308 @@
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
+ module AttributeHandler
5
+ def abbr
6
+ @abbr
7
+ end
8
+
9
+ def abbr=(string)
10
+ @abbr = string
11
+ modify_html("abbr",string)
12
+ end
13
+
14
+ def align
15
+ @align
16
+ end
17
+
18
+ def align=(position)
19
+ valid = %w/top bottom left center right/
20
+ raise ArgumentError unless valid.include?(position.downcase)
21
+ @align = position
22
+ modify_html("align",position)
23
+ end
24
+
25
+ def axis
26
+ @axis
27
+ end
28
+
29
+ def axis=(string)
30
+ @axis = string
31
+ modify_html("axis",string)
32
+ end
33
+
34
+ def background
35
+ @background
36
+ end
37
+
38
+ def background=(url)
39
+ raise TypeError unless url.kind_of?(String)
40
+ if $VERBOSE
41
+ msg = "'background' is a non-standard extension"
42
+ STDERR.puts msg
43
+ end
44
+ @background = url
45
+ modify_html("background",url)
46
+ end
47
+
48
+ def bgcolor
49
+ @bgcolor
50
+ end
51
+
52
+ def bgcolor=(color)
53
+ @bgcolor = color
54
+ modify_html("bgcolor",color)
55
+ end
56
+
57
+ def border
58
+ @border
59
+ end
60
+
61
+ # Allow either true/false or an integer
62
+ def border=(num)
63
+ if num.kind_of?(TrueClass)
64
+ modify_html("border",true)
65
+ elsif num.kind_of?(FalseClass)
66
+ # Do nothing
67
+ else
68
+ @border = num.to_i
69
+ modify_html("border",num.to_i)
70
+ end
71
+ end
72
+
73
+ def bordercolor
74
+ @bordercolor
75
+ end
76
+
77
+ def bordercolor=(color)
78
+ @bordercolor = color
79
+ if $VERBOSE
80
+ msg = "'bordercolor' is a non-standard extension"
81
+ STDERR.puts msg
82
+ end
83
+ modify_html("bordercolor",color)
84
+ end
85
+
86
+ def bordercolordark
87
+ @bordercolordark
88
+ end
89
+
90
+ def bordercolordark=(color)
91
+ @bordercolordark = color
92
+ if $VERBOSE
93
+ msg = "'bordercolordark' is a non-standard extension"
94
+ STDERR.puts msg
95
+ end
96
+ modify_html("bordercolordark",color)
97
+ end
98
+
99
+ def bordercolorlight
100
+ @bordercolorlight
101
+ end
102
+
103
+ def bordercolorlight=(color)
104
+ @bordercolorlight = color
105
+ if $VERBOSE
106
+ msg = "'bordercolorlight' is a non-standard extension"
107
+ STDERR.puts msg
108
+ end
109
+ modify_html("bordercolorlight",@bordercolorlight)
110
+ end
111
+
112
+ def cellpadding
113
+ @cellpadding
114
+ end
115
+
116
+ def cellpadding=(num)
117
+ raise ArgumentError if num.to_i < 0
118
+ @cellpadding = num.to_i
119
+ modify_html("cellpadding",@cellpadding)
120
+ end
121
+
122
+ def cellspacing
123
+ @cellspacing
124
+ end
125
+
126
+ def cellspacing=(num)
127
+ raise ArgumentError if num.to_i < 0
128
+ @cellspacing = num.to_i
129
+ modify_html("cellspacing",@cellspacing)
130
+ end
131
+
132
+ def char
133
+ @char
134
+ end
135
+
136
+ def char=(character)
137
+ raise ArgumentError if character.to_s.length > 1
138
+ @char = character.to_s
139
+ modify_html("char",character.to_s)
140
+ end
141
+
142
+ def charoff
143
+ @charoff
144
+ end
145
+
146
+ def charoff=(offset)
147
+ raise ArgumentError if offset.to_i < 0
148
+ @charoff = offset
149
+ modify_html("charoff",offset)
150
+ end
151
+
152
+ def col
153
+ @col
154
+ end
155
+
156
+ def col=(num)
157
+ raise ArgumentError if num.to_i < 0
158
+ @col = num.to_i
159
+ modify_html("col",@col)
160
+ end
161
+
162
+ def colspan
163
+ @colspan
164
+ end
165
+
166
+ def colspan=(span)
167
+ raise ArgumentError if span.to_i < 0
168
+ @colspan = span.to_i
169
+ modify_html("colspan",@colspan)
170
+ end
171
+
172
+ # Allows you to configure various attributes by row or row + column.
173
+ def configure(row,col=nil,&block)
174
+ if col
175
+ begin
176
+ yield self[row][col]
177
+ rescue NameError
178
+ msg = "No column to configure in a " + self.class.to_s + " class"
179
+ raise ArgumentError, msg
180
+ end
181
+ else
182
+ yield self[row]
183
+ end
184
+ end
185
+
186
+ # Returns the HTML content (i.e. text)
187
+ def content
188
+ @html_body
189
+ end
190
+
191
+ def frame
192
+ @frame
193
+ end
194
+
195
+ def frame=(type)
196
+ valid = %w/border void above below hsides lhs rhs vsides box/
197
+ raise ArgumentError unless valid.include?(type.downcase)
198
+ @frame = type
199
+ modify_html("frame",@frame)
200
+ end
201
+
202
+ def height
203
+ @height
204
+ end
205
+
206
+ def height=(num)
207
+ raise ArgumentError if num.to_i < 0
208
+ @height = num.to_i
209
+ modify_html("height",@height)
210
+ end
211
+
212
+ def hspace
213
+ @hspace
214
+ end
215
+
216
+ def hspace=(num)
217
+ raise ArgumentError if num.to_i < 0
218
+ @hspace = num.to_i
219
+ modify_html("hspace",@hspace)
220
+ end
221
+
222
+ def nowrap
223
+ @nowrap
224
+ end
225
+
226
+ def nowrap=(bool)
227
+ unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
228
+ raise TypeError
229
+ end
230
+ @nowrap = bool
231
+ modify_html("nowrap",@nowrap)
232
+ end
233
+
234
+ def rowspan
235
+ @rowspan
236
+ end
237
+
238
+ def rowspan=(num)
239
+ raise ArgumentError if num.to_i < 0
240
+ @rowspan = num.to_i
241
+ modify_html("rowspan",@rowspan)
242
+ end
243
+
244
+ def rules
245
+ @rules
246
+ end
247
+
248
+ def rules=(edges)
249
+ valid = %w/all groups rows cols none/
250
+ raise ArgumentError unless valid.include?(edges.to_s.downcase)
251
+ @rules = edges
252
+ modify_html("rules",@rules)
253
+ end
254
+
255
+ def span
256
+ @span
257
+ end
258
+
259
+ def span=(num)
260
+ raise ArgumentError if num.to_i < 0
261
+ @span = num.to_i
262
+ modify_html("span",@span)
263
+ end
264
+
265
+ def summary
266
+ @summary
267
+ end
268
+
269
+ def summary=(string)
270
+ @summary = string.to_s
271
+ modify_html("summary",@summary)
272
+ end
273
+
274
+ def valign
275
+ @valign
276
+ end
277
+
278
+ def valign=(position)
279
+ valid = %w/top center bottom baseline/
280
+ raise ArgumentError unless valid.include?(position.to_s.downcase)
281
+ @valign = position
282
+ modify_html("valign",@valign)
283
+ end
284
+
285
+ def vspace=(num)
286
+ raise ArgumentError if num.to_i < 0
287
+ @vspace = num.to_i
288
+ modify_html("vspace",@vspace)
289
+ end
290
+
291
+ def vspace
292
+ @vspace
293
+ end
294
+
295
+ def width
296
+ @width
297
+ end
298
+
299
+ def width=(num)
300
+ if num =~ /%/
301
+ @width = num
302
+ else
303
+ raise ArgumentError if num.to_i < 0
304
+ @width = num.to_i
305
+ end
306
+ modify_html("width",@width)
307
+ end
308
+ end