html-table 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +155 -149
- data/MANIFEST +59 -59
- data/README +132 -132
- data/certs/djberg96_pub.pem +15 -15
- data/doc/attributes.rdoc +143 -143
- data/doc/table.rdoc +158 -158
- data/doc/table_body.rdoc +9 -9
- data/doc/table_caption.rdoc +9 -9
- data/doc/table_colgroup.rdoc +8 -8
- data/doc/table_colgroup_col.rdoc +9 -9
- data/doc/table_content.rdoc +15 -15
- data/doc/table_foot.rdoc +8 -8
- data/doc/table_head.rdoc +11 -11
- data/doc/table_row.rdoc +105 -105
- data/doc/table_row_data.rdoc +92 -92
- data/doc/table_row_header.rdoc +7 -7
- 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 +28 -28
- data/lib/html-table.rb +1 -1
- data/lib/html/attribute_handler.rb +403 -403
- data/lib/html/body.rb +37 -37
- data/lib/html/caption.rb +49 -49
- 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 +69 -69
- 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 +323 -323
- data/lib/html/tablesection.rb +48 -48
- data/lib/html/tag_handler.rb +121 -121
- data/test/test_attribute_handler.rb +361 -361
- data/test/test_body.rb +87 -87
- data/test/test_caption.rb +80 -80
- data/test/test_col.rb +40 -40
- data/test/test_colgroup.rb +89 -89
- data/test/test_data.rb +77 -77
- data/test/test_foot.rb +111 -111
- data/test/test_head.rb +104 -104
- data/test/test_header.rb +77 -77
- data/test/test_html_handler.rb +37 -37
- data/test/test_row.rb +141 -141
- data/test/test_table.rb +158 -158
- data/test/test_tablesection.rb +42 -42
- data/test/test_tag_handler.rb +90 -90
- metadata +22 -22
- metadata.gz.sig +0 -0
data/lib/html/table.rb
CHANGED
@@ -1,323 +1,323 @@
|
|
1
|
-
require_relative 'attribute_handler'
|
2
|
-
require_relative 'html_handler'
|
3
|
-
require 'strongtyping'
|
4
|
-
require 'structured_warnings'
|
5
|
-
include StrongTyping
|
6
|
-
|
7
|
-
# Warning raised if a non-standard extension is used.
|
8
|
-
class NonStandardExtensionWarning <
|
9
|
-
|
10
|
-
# Please, think of the children before using the blink tag.
|
11
|
-
class BlinkWarning <
|
12
|
-
|
13
|
-
# The HTML module serves as a namespace only.
|
14
|
-
module HTML
|
15
|
-
|
16
|
-
# The Table class encapsulates methods associated with an html table
|
17
|
-
# element. It is the "outermost" class of the html-table classes.
|
18
|
-
class Table < Array
|
19
|
-
include AttributeHandler
|
20
|
-
include HtmlHandler
|
21
|
-
|
22
|
-
# The version of the html-table library
|
23
|
-
VERSION = '1.
|
24
|
-
|
25
|
-
# The indentation level for the <table> and </table> tags
|
26
|
-
@indent_level = 0
|
27
|
-
|
28
|
-
# The default character case used for printing output
|
29
|
-
@html_case = 'lower'
|
30
|
-
|
31
|
-
# Determines whether or not end tags will be included in printed output
|
32
|
-
@@global_end_tags = true
|
33
|
-
|
34
|
-
# Returns a new Table object. Optionally takes a block which is
|
35
|
-
# eval'd if provided. If an argument is provided it is interpreted as
|
36
|
-
# content. See the Table#content= method for how that data will be
|
37
|
-
# interpreted.
|
38
|
-
#
|
39
|
-
# Examples:
|
40
|
-
#
|
41
|
-
# # A single data item
|
42
|
-
# HTML::Table.new(1).html
|
43
|
-
#
|
44
|
-
# # Output
|
45
|
-
# <table>
|
46
|
-
# <tr>
|
47
|
-
# <td>1</td>
|
48
|
-
# </tr>
|
49
|
-
# </table>
|
50
|
-
#
|
51
|
-
# # One row per data item
|
52
|
-
# HTML::Table.new(['Matz', 'Larry', 'Guido']).html
|
53
|
-
#
|
54
|
-
# # Output
|
55
|
-
# <table>
|
56
|
-
# <tr>
|
57
|
-
# <td>Matz</td>
|
58
|
-
# </tr>
|
59
|
-
# <tr>
|
60
|
-
# <td>Larry</td>
|
61
|
-
# </tr>
|
62
|
-
# <tr>
|
63
|
-
# <td>Guido</td>
|
64
|
-
# </tr>
|
65
|
-
# </tr>
|
66
|
-
# </table>
|
67
|
-
#
|
68
|
-
# # Multiple data items per row
|
69
|
-
# Table.new{ |t|
|
70
|
-
# t.content = [['a','b'], [1,2], ['x','y']]
|
71
|
-
# }.html
|
72
|
-
#
|
73
|
-
# # Output
|
74
|
-
# <table>
|
75
|
-
# <tr>
|
76
|
-
# <td>a</td>
|
77
|
-
# <td>b</td>
|
78
|
-
# </tr>
|
79
|
-
# <tr>
|
80
|
-
# <td>1</td>
|
81
|
-
# <td>2</td>
|
82
|
-
# </tr>
|
83
|
-
# <tr>
|
84
|
-
# <td>x</td>
|
85
|
-
# <td>y</td>
|
86
|
-
# </tr>
|
87
|
-
# </table>
|
88
|
-
#
|
89
|
-
def initialize(arg = nil, html_options = {}, &block)
|
90
|
-
@html_begin = '<table'
|
91
|
-
@html_body = ''
|
92
|
-
@html_end = '</table>'
|
93
|
-
instance_eval(&block) if block
|
94
|
-
self.content = arg if arg
|
95
|
-
|
96
|
-
# Assume html_options are attributes
|
97
|
-
html_options.each{ |key, val|
|
98
|
-
self.send("#{key}=", val)
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
# Adds content to the table. How this method behaves depends on the
|
103
|
-
# type of argument being passed.
|
104
|
-
#
|
105
|
-
# The +arg+ may be a Table::Row object, an Array of Table::Row objects,
|
106
|
-
# an Array of Array's, an Array of Strings, or a single String. In the
|
107
|
-
# last two cases, a single Table::Row with a single Table::Row::Data
|
108
|
-
# object is created, with the string as the content.
|
109
|
-
#
|
110
|
-
def content=(arg)
|
111
|
-
if arg.kind_of?(Array)
|
112
|
-
arg.each{ |e| self << Table::Row.new(e) }
|
113
|
-
else
|
114
|
-
self << Table::Row.new(arg)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
alias data= content=
|
119
|
-
|
120
|
-
# A shortcut for creating Table::Row::Header objects in the constructor
|
121
|
-
# using the DSL style syntax.
|
122
|
-
#
|
123
|
-
def header(arg = nil)
|
124
|
-
self.header = arg if arg
|
125
|
-
end
|
126
|
-
|
127
|
-
# Adds a Table::Row::Header object (or an Array of them) to the Table
|
128
|
-
# object.
|
129
|
-
#
|
130
|
-
def header=(arg)
|
131
|
-
if arg.kind_of?(Array)
|
132
|
-
arg.each{ |h| self << Table::Row.new(h, true) }
|
133
|
-
else
|
134
|
-
self << Table::Row::Header.new(arg)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# Returns true or false, depending on whether or not end tags have been
|
139
|
-
# turned on or off, respectively.
|
140
|
-
#
|
141
|
-
def self.global_end_tags?
|
142
|
-
@@global_end_tags
|
143
|
-
end
|
144
|
-
|
145
|
-
# Sets the end tag class variable. This is used to set whether or not
|
146
|
-
# to include optional end tags in the final HTML output. The argument
|
147
|
-
# sent to this method must be true or false. The default value is true.
|
148
|
-
#
|
149
|
-
# Note that mandatory end tags are unaffected by this setting.
|
150
|
-
#
|
151
|
-
def self.global_end_tags=(bool)
|
152
|
-
expect(bool, [TrueClass, FalseClass])
|
153
|
-
@@global_end_tags = bool
|
154
|
-
end
|
155
|
-
|
156
|
-
# Returns either "lower" or "upper", indicating the case of all HTML
|
157
|
-
# tags in the final output.
|
158
|
-
#
|
159
|
-
def self.html_case
|
160
|
-
@html_case
|
161
|
-
end
|
162
|
-
|
163
|
-
# Sets the case of all HTML tags to either lower or upper. The only
|
164
|
-
# valid arguments to this method are 'upper' or 'lower'.
|
165
|
-
#
|
166
|
-
def self.html_case=(arg)
|
167
|
-
expect(arg, String)
|
168
|
-
arg.downcase!
|
169
|
-
unless arg == "upper" || arg == "lower"
|
170
|
-
msg = "Argument to html_case() must be 'upper' or 'lower'"
|
171
|
-
raise ArgumentError, msg
|
172
|
-
end
|
173
|
-
@html_case = arg
|
174
|
-
end
|
175
|
-
|
176
|
-
# Returns the number of spaces that tags for this class are indented.
|
177
|
-
# For the Table class, the indention level defaults to 0.
|
178
|
-
#
|
179
|
-
# Note that each class has its own default indentation level (a multiple
|
180
|
-
# of 3).
|
181
|
-
#
|
182
|
-
def self.indent_level
|
183
|
-
@indent_level
|
184
|
-
end
|
185
|
-
|
186
|
-
# Sets the number of spaces that tags for this class are indented.
|
187
|
-
#
|
188
|
-
def self.indent_level=(num)
|
189
|
-
expect(num, Integer)
|
190
|
-
raise ArgumentError,"indent level must be >= 0" if num < 0
|
191
|
-
@indent_level = num
|
192
|
-
end
|
193
|
-
|
194
|
-
# This method has been redefined to only allow certain subclasses to
|
195
|
-
# be assigned using a direct index notation. Specifically, only
|
196
|
-
# Caption, ColGroup, Body, Foot, Head and Row objects may be use
|
197
|
-
# assigned using direct index notation.
|
198
|
-
#
|
199
|
-
# In addition, a Caption can only be assigned to index 0. A Head can
|
200
|
-
# only be assigned to index 0, or index 1 if a Caption already exists.
|
201
|
-
# A Foot may only be assigned as the last element.
|
202
|
-
#
|
203
|
-
def []=(index,obj)
|
204
|
-
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row])
|
205
|
-
|
206
|
-
# Only allow Caption objects at index 0
|
207
|
-
if index != 0 && obj.kind_of?(HTML::Table::Caption)
|
208
|
-
msg = "CAPTION can only be added at index 0"
|
209
|
-
raise ArgumentError, msg
|
210
|
-
end
|
211
|
-
|
212
|
-
# Only allow Head objects at index 0 or 1
|
213
|
-
if obj.kind_of?(HTML::Table::Head)
|
214
|
-
if self[0].kind_of?(HTML::Table::Caption) && index != 1
|
215
|
-
msg = "THEAD must be at index 1 when Caption is included"
|
216
|
-
raise ArgumentError, msg
|
217
|
-
end
|
218
|
-
|
219
|
-
if !self[0].kind_of?(HTML::Table::Caption) && index != 0
|
220
|
-
msg = "THEAD must be at index 0 when no Caption is included"
|
221
|
-
raise ArgumentError, msg
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
if obj.kind_of?(HTML::Table::Foot) && index != -1
|
226
|
-
msg = "FOOT must be last element"
|
227
|
-
raise ArgumentError, msg
|
228
|
-
end
|
229
|
-
|
230
|
-
super
|
231
|
-
end
|
232
|
-
|
233
|
-
# This method has been redefined to only allow certain subclasses to
|
234
|
-
# be accepted as arguments. Specifically, only Caption, ColGroup,
|
235
|
-
# Body, Foot, Head, Row, Row::Data and Row::Header objects may be
|
236
|
-
# pushed onto a Table.
|
237
|
-
#
|
238
|
-
# Pushing a Data or Header object onto a Table object creates its own
|
239
|
-
# row for each. If a Caption object is pushed onto the Table, it will
|
240
|
-
# automatically be bumped to the first element. If a Head object is
|
241
|
-
# pushed onto the Table, it is automatically bumped to the first
|
242
|
-
# element, or the second element if a Caption already exists.
|
243
|
-
#
|
244
|
-
def push(*args)
|
245
|
-
args.each{ |obj|
|
246
|
-
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row, Row::Data, Row::Header])
|
247
|
-
|
248
|
-
case obj
|
249
|
-
when Table::Row::Data, Table::Row::Header
|
250
|
-
self.push(Table::Row.new(obj))
|
251
|
-
when Table::Caption
|
252
|
-
if self[0].kind_of?(Table::Caption)
|
253
|
-
self[0] = obj
|
254
|
-
else
|
255
|
-
self.unshift(obj)
|
256
|
-
end
|
257
|
-
when Table::Head
|
258
|
-
if self[0].kind_of?(Table::Caption)
|
259
|
-
self.unshift(obj)
|
260
|
-
self[0],self[1] = self[1],self[0]
|
261
|
-
else
|
262
|
-
self.unshift(obj)
|
263
|
-
end
|
264
|
-
else
|
265
|
-
super(obj)
|
266
|
-
end
|
267
|
-
}
|
268
|
-
end
|
269
|
-
|
270
|
-
# This method has been redefined to only allow certain subclasses to
|
271
|
-
# be accepted as arguments.
|
272
|
-
#
|
273
|
-
# The restrictions and behavior are identical to the push() method.
|
274
|
-
#
|
275
|
-
def <<(obj)
|
276
|
-
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row, Row::Data, Row::Header])
|
277
|
-
|
278
|
-
case obj
|
279
|
-
when Table::Row::Data, Table::Row::Header # Each get their own row
|
280
|
-
self << Table::Row.new(obj)
|
281
|
-
when Table::Caption # Always the first row
|
282
|
-
if self[0].kind_of?(Table::Caption)
|
283
|
-
self[0] = obj
|
284
|
-
else
|
285
|
-
self.unshift(obj)
|
286
|
-
end
|
287
|
-
when Table::Head # Always at row 0 or 1
|
288
|
-
if self[0].kind_of?(Table::Caption)
|
289
|
-
self.unshift(obj)
|
290
|
-
self[0], self[1] = self[1], self[0]
|
291
|
-
else
|
292
|
-
self.unshift(obj)
|
293
|
-
end
|
294
|
-
else
|
295
|
-
super(obj)
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
# This method has been redefined to only allow certain subclasses to
|
300
|
-
# be unshifted onto a Table object. Specifically, they are Caption,
|
301
|
-
# ColGroup, Body, Foot, Head and Row.
|
302
|
-
#
|
303
|
-
def unshift(obj)
|
304
|
-
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row])
|
305
|
-
super
|
306
|
-
end
|
307
|
-
|
308
|
-
alias to_s html
|
309
|
-
alias to_str html
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
require_relative 'content'
|
314
|
-
require_relative 'caption'
|
315
|
-
require_relative 'colgroup'
|
316
|
-
require_relative 'col'
|
317
|
-
require_relative 'row'
|
318
|
-
require_relative 'header'
|
319
|
-
require_relative 'data'
|
320
|
-
require_relative 'tablesection'
|
321
|
-
require_relative 'head'
|
322
|
-
require_relative 'foot'
|
323
|
-
require_relative 'body'
|
1
|
+
require_relative 'attribute_handler'
|
2
|
+
require_relative 'html_handler'
|
3
|
+
require 'strongtyping'
|
4
|
+
require 'structured_warnings'
|
5
|
+
include StrongTyping
|
6
|
+
|
7
|
+
# Warning raised if a non-standard extension is used.
|
8
|
+
class NonStandardExtensionWarning < StructuredWarnings::StandardWarning; end
|
9
|
+
|
10
|
+
# Please, think of the children before using the blink tag.
|
11
|
+
class BlinkWarning < StructuredWarnings::StandardWarning; end
|
12
|
+
|
13
|
+
# The HTML module serves as a namespace only.
|
14
|
+
module HTML
|
15
|
+
|
16
|
+
# The Table class encapsulates methods associated with an html table
|
17
|
+
# element. It is the "outermost" class of the html-table classes.
|
18
|
+
class Table < Array
|
19
|
+
include AttributeHandler
|
20
|
+
include HtmlHandler
|
21
|
+
|
22
|
+
# The version of the html-table library
|
23
|
+
VERSION = '1.5.0'.freeze
|
24
|
+
|
25
|
+
# The indentation level for the <table> and </table> tags
|
26
|
+
@indent_level = 0
|
27
|
+
|
28
|
+
# The default character case used for printing output
|
29
|
+
@html_case = 'lower'
|
30
|
+
|
31
|
+
# Determines whether or not end tags will be included in printed output
|
32
|
+
@@global_end_tags = true
|
33
|
+
|
34
|
+
# Returns a new Table object. Optionally takes a block which is
|
35
|
+
# eval'd if provided. If an argument is provided it is interpreted as
|
36
|
+
# content. See the Table#content= method for how that data will be
|
37
|
+
# interpreted.
|
38
|
+
#
|
39
|
+
# Examples:
|
40
|
+
#
|
41
|
+
# # A single data item
|
42
|
+
# HTML::Table.new(1).html
|
43
|
+
#
|
44
|
+
# # Output
|
45
|
+
# <table>
|
46
|
+
# <tr>
|
47
|
+
# <td>1</td>
|
48
|
+
# </tr>
|
49
|
+
# </table>
|
50
|
+
#
|
51
|
+
# # One row per data item
|
52
|
+
# HTML::Table.new(['Matz', 'Larry', 'Guido']).html
|
53
|
+
#
|
54
|
+
# # Output
|
55
|
+
# <table>
|
56
|
+
# <tr>
|
57
|
+
# <td>Matz</td>
|
58
|
+
# </tr>
|
59
|
+
# <tr>
|
60
|
+
# <td>Larry</td>
|
61
|
+
# </tr>
|
62
|
+
# <tr>
|
63
|
+
# <td>Guido</td>
|
64
|
+
# </tr>
|
65
|
+
# </tr>
|
66
|
+
# </table>
|
67
|
+
#
|
68
|
+
# # Multiple data items per row
|
69
|
+
# Table.new{ |t|
|
70
|
+
# t.content = [['a','b'], [1,2], ['x','y']]
|
71
|
+
# }.html
|
72
|
+
#
|
73
|
+
# # Output
|
74
|
+
# <table>
|
75
|
+
# <tr>
|
76
|
+
# <td>a</td>
|
77
|
+
# <td>b</td>
|
78
|
+
# </tr>
|
79
|
+
# <tr>
|
80
|
+
# <td>1</td>
|
81
|
+
# <td>2</td>
|
82
|
+
# </tr>
|
83
|
+
# <tr>
|
84
|
+
# <td>x</td>
|
85
|
+
# <td>y</td>
|
86
|
+
# </tr>
|
87
|
+
# </table>
|
88
|
+
#
|
89
|
+
def initialize(arg = nil, html_options = {}, &block)
|
90
|
+
@html_begin = '<table'
|
91
|
+
@html_body = ''
|
92
|
+
@html_end = '</table>'
|
93
|
+
instance_eval(&block) if block
|
94
|
+
self.content = arg if arg
|
95
|
+
|
96
|
+
# Assume html_options are attributes
|
97
|
+
html_options.each{ |key, val|
|
98
|
+
self.send("#{key}=", val)
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
# Adds content to the table. How this method behaves depends on the
|
103
|
+
# type of argument being passed.
|
104
|
+
#
|
105
|
+
# The +arg+ may be a Table::Row object, an Array of Table::Row objects,
|
106
|
+
# an Array of Array's, an Array of Strings, or a single String. In the
|
107
|
+
# last two cases, a single Table::Row with a single Table::Row::Data
|
108
|
+
# object is created, with the string as the content.
|
109
|
+
#
|
110
|
+
def content=(arg)
|
111
|
+
if arg.kind_of?(Array)
|
112
|
+
arg.each{ |e| self << Table::Row.new(e) }
|
113
|
+
else
|
114
|
+
self << Table::Row.new(arg)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
alias data= content=
|
119
|
+
|
120
|
+
# A shortcut for creating Table::Row::Header objects in the constructor
|
121
|
+
# using the DSL style syntax.
|
122
|
+
#
|
123
|
+
def header(arg = nil)
|
124
|
+
self.header = arg if arg
|
125
|
+
end
|
126
|
+
|
127
|
+
# Adds a Table::Row::Header object (or an Array of them) to the Table
|
128
|
+
# object.
|
129
|
+
#
|
130
|
+
def header=(arg)
|
131
|
+
if arg.kind_of?(Array)
|
132
|
+
arg.each{ |h| self << Table::Row.new(h, true) }
|
133
|
+
else
|
134
|
+
self << Table::Row::Header.new(arg)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Returns true or false, depending on whether or not end tags have been
|
139
|
+
# turned on or off, respectively.
|
140
|
+
#
|
141
|
+
def self.global_end_tags?
|
142
|
+
@@global_end_tags
|
143
|
+
end
|
144
|
+
|
145
|
+
# Sets the end tag class variable. This is used to set whether or not
|
146
|
+
# to include optional end tags in the final HTML output. The argument
|
147
|
+
# sent to this method must be true or false. The default value is true.
|
148
|
+
#
|
149
|
+
# Note that mandatory end tags are unaffected by this setting.
|
150
|
+
#
|
151
|
+
def self.global_end_tags=(bool)
|
152
|
+
expect(bool, [TrueClass, FalseClass])
|
153
|
+
@@global_end_tags = bool
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns either "lower" or "upper", indicating the case of all HTML
|
157
|
+
# tags in the final output.
|
158
|
+
#
|
159
|
+
def self.html_case
|
160
|
+
@html_case
|
161
|
+
end
|
162
|
+
|
163
|
+
# Sets the case of all HTML tags to either lower or upper. The only
|
164
|
+
# valid arguments to this method are 'upper' or 'lower'.
|
165
|
+
#
|
166
|
+
def self.html_case=(arg)
|
167
|
+
expect(arg, String)
|
168
|
+
arg.downcase!
|
169
|
+
unless arg == "upper" || arg == "lower"
|
170
|
+
msg = "Argument to html_case() must be 'upper' or 'lower'"
|
171
|
+
raise ArgumentError, msg
|
172
|
+
end
|
173
|
+
@html_case = arg
|
174
|
+
end
|
175
|
+
|
176
|
+
# Returns the number of spaces that tags for this class are indented.
|
177
|
+
# For the Table class, the indention level defaults to 0.
|
178
|
+
#
|
179
|
+
# Note that each class has its own default indentation level (a multiple
|
180
|
+
# of 3).
|
181
|
+
#
|
182
|
+
def self.indent_level
|
183
|
+
@indent_level
|
184
|
+
end
|
185
|
+
|
186
|
+
# Sets the number of spaces that tags for this class are indented.
|
187
|
+
#
|
188
|
+
def self.indent_level=(num)
|
189
|
+
expect(num, Integer)
|
190
|
+
raise ArgumentError, "indent level must be >= 0" if num < 0
|
191
|
+
@indent_level = num
|
192
|
+
end
|
193
|
+
|
194
|
+
# This method has been redefined to only allow certain subclasses to
|
195
|
+
# be assigned using a direct index notation. Specifically, only
|
196
|
+
# Caption, ColGroup, Body, Foot, Head and Row objects may be use
|
197
|
+
# assigned using direct index notation.
|
198
|
+
#
|
199
|
+
# In addition, a Caption can only be assigned to index 0. A Head can
|
200
|
+
# only be assigned to index 0, or index 1 if a Caption already exists.
|
201
|
+
# A Foot may only be assigned as the last element.
|
202
|
+
#
|
203
|
+
def []=(index,obj)
|
204
|
+
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row])
|
205
|
+
|
206
|
+
# Only allow Caption objects at index 0
|
207
|
+
if index != 0 && obj.kind_of?(HTML::Table::Caption)
|
208
|
+
msg = "CAPTION can only be added at index 0"
|
209
|
+
raise ArgumentError, msg
|
210
|
+
end
|
211
|
+
|
212
|
+
# Only allow Head objects at index 0 or 1
|
213
|
+
if obj.kind_of?(HTML::Table::Head)
|
214
|
+
if self[0].kind_of?(HTML::Table::Caption) && index != 1
|
215
|
+
msg = "THEAD must be at index 1 when Caption is included"
|
216
|
+
raise ArgumentError, msg
|
217
|
+
end
|
218
|
+
|
219
|
+
if !self[0].kind_of?(HTML::Table::Caption) && index != 0
|
220
|
+
msg = "THEAD must be at index 0 when no Caption is included"
|
221
|
+
raise ArgumentError, msg
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
if obj.kind_of?(HTML::Table::Foot) && index != -1
|
226
|
+
msg = "FOOT must be last element"
|
227
|
+
raise ArgumentError, msg
|
228
|
+
end
|
229
|
+
|
230
|
+
super
|
231
|
+
end
|
232
|
+
|
233
|
+
# This method has been redefined to only allow certain subclasses to
|
234
|
+
# be accepted as arguments. Specifically, only Caption, ColGroup,
|
235
|
+
# Body, Foot, Head, Row, Row::Data and Row::Header objects may be
|
236
|
+
# pushed onto a Table.
|
237
|
+
#
|
238
|
+
# Pushing a Data or Header object onto a Table object creates its own
|
239
|
+
# row for each. If a Caption object is pushed onto the Table, it will
|
240
|
+
# automatically be bumped to the first element. If a Head object is
|
241
|
+
# pushed onto the Table, it is automatically bumped to the first
|
242
|
+
# element, or the second element if a Caption already exists.
|
243
|
+
#
|
244
|
+
def push(*args)
|
245
|
+
args.each{ |obj|
|
246
|
+
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row, Row::Data, Row::Header])
|
247
|
+
|
248
|
+
case obj
|
249
|
+
when Table::Row::Data, Table::Row::Header
|
250
|
+
self.push(Table::Row.new(obj))
|
251
|
+
when Table::Caption
|
252
|
+
if self[0].kind_of?(Table::Caption)
|
253
|
+
self[0] = obj
|
254
|
+
else
|
255
|
+
self.unshift(obj)
|
256
|
+
end
|
257
|
+
when Table::Head
|
258
|
+
if self[0].kind_of?(Table::Caption)
|
259
|
+
self.unshift(obj)
|
260
|
+
self[0],self[1] = self[1],self[0]
|
261
|
+
else
|
262
|
+
self.unshift(obj)
|
263
|
+
end
|
264
|
+
else
|
265
|
+
super(obj)
|
266
|
+
end
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
270
|
+
# This method has been redefined to only allow certain subclasses to
|
271
|
+
# be accepted as arguments.
|
272
|
+
#
|
273
|
+
# The restrictions and behavior are identical to the push() method.
|
274
|
+
#
|
275
|
+
def <<(obj)
|
276
|
+
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row, Row::Data, Row::Header])
|
277
|
+
|
278
|
+
case obj
|
279
|
+
when Table::Row::Data, Table::Row::Header # Each get their own row
|
280
|
+
self << Table::Row.new(obj)
|
281
|
+
when Table::Caption # Always the first row
|
282
|
+
if self[0].kind_of?(Table::Caption)
|
283
|
+
self[0] = obj
|
284
|
+
else
|
285
|
+
self.unshift(obj)
|
286
|
+
end
|
287
|
+
when Table::Head # Always at row 0 or 1
|
288
|
+
if self[0].kind_of?(Table::Caption)
|
289
|
+
self.unshift(obj)
|
290
|
+
self[0], self[1] = self[1], self[0]
|
291
|
+
else
|
292
|
+
self.unshift(obj)
|
293
|
+
end
|
294
|
+
else
|
295
|
+
super(obj)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
# This method has been redefined to only allow certain subclasses to
|
300
|
+
# be unshifted onto a Table object. Specifically, they are Caption,
|
301
|
+
# ColGroup, Body, Foot, Head and Row.
|
302
|
+
#
|
303
|
+
def unshift(obj)
|
304
|
+
expect(obj, [Caption, ColGroup, Body, Foot, Head, Row])
|
305
|
+
super
|
306
|
+
end
|
307
|
+
|
308
|
+
alias to_s html
|
309
|
+
alias to_str html
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
require_relative 'content'
|
314
|
+
require_relative 'caption'
|
315
|
+
require_relative 'colgroup'
|
316
|
+
require_relative 'col'
|
317
|
+
require_relative 'row'
|
318
|
+
require_relative 'header'
|
319
|
+
require_relative 'data'
|
320
|
+
require_relative 'tablesection'
|
321
|
+
require_relative 'head'
|
322
|
+
require_relative 'foot'
|
323
|
+
require_relative 'body'
|