html-table 1.7.0 → 1.7.1

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/{CHANGES.rdoc → CHANGES.md} +73 -69
  4. data/Gemfile +2 -7
  5. data/{MANIFEST.rdoc → MANIFEST.md} +15 -15
  6. data/{README.rdoc → README.md} +80 -71
  7. data/Rakefile +7 -2
  8. data/doc/attributes.md +160 -0
  9. data/doc/table.md +173 -0
  10. data/doc/table_body.md +9 -0
  11. data/doc/table_caption.md +10 -0
  12. data/doc/table_colgroup.md +8 -0
  13. data/doc/table_colgroup_col.md +7 -0
  14. data/doc/table_content.md +17 -0
  15. data/doc/table_foot.md +8 -0
  16. data/doc/table_head.md +10 -0
  17. data/doc/table_row.md +114 -0
  18. data/doc/table_row_data.md +100 -0
  19. data/doc/table_row_header.md +6 -0
  20. data/examples/simple1.rb +7 -5
  21. data/html-table.gemspec +13 -8
  22. data/lib/html/body.rb +9 -7
  23. data/lib/html/caption.rb +4 -2
  24. data/lib/html/col.rb +37 -34
  25. data/lib/html/colgroup.rb +90 -97
  26. data/lib/html/content.rb +3 -6
  27. data/lib/html/data.rb +3 -1
  28. data/lib/html/foot.rb +53 -45
  29. data/lib/html/head.rb +54 -47
  30. data/lib/html/header.rb +5 -3
  31. data/lib/html/mixin/attribute_handler.rb +57 -53
  32. data/lib/html/mixin/html_handler.rb +33 -35
  33. data/lib/html/mixin/strongtyping.rb +6 -6
  34. data/lib/html/mixin/tag_handler.rb +6 -2
  35. data/lib/html/row.rb +156 -183
  36. data/lib/html/table.rb +45 -45
  37. data/lib/html/tablesection.rb +51 -46
  38. data/spec/attribute_handler_spec.rb +94 -80
  39. data/spec/body_spec.rb +54 -37
  40. data/spec/caption_spec.rb +41 -32
  41. data/spec/colgroup_col_spec.rb +7 -7
  42. data/spec/colgroup_spec.rb +50 -36
  43. data/spec/data_spec.rb +39 -23
  44. data/spec/foot_spec.rb +58 -46
  45. data/spec/head_spec.rb +62 -47
  46. data/spec/header_spec.rb +35 -22
  47. data/spec/html_handler_spec.rb +15 -12
  48. data/spec/row_spec.rb +95 -68
  49. data/spec/table_spec.rb +65 -31
  50. data/spec/tablesection_spec.rb +13 -13
  51. data/spec/tag_handler_spec.rb +13 -13
  52. data.tar.gz.sig +0 -0
  53. metadata +103 -78
  54. metadata.gz.sig +0 -0
  55. data/doc/attributes.rdoc +0 -143
  56. data/doc/table.rdoc +0 -156
  57. data/doc/table_body.rdoc +0 -9
  58. data/doc/table_caption.rdoc +0 -9
  59. data/doc/table_colgroup.rdoc +0 -8
  60. data/doc/table_colgroup_col.rdoc +0 -9
  61. data/doc/table_content.rdoc +0 -15
  62. data/doc/table_foot.rdoc +0 -8
  63. data/doc/table_head.rdoc +0 -11
  64. data/doc/table_row.rdoc +0 -105
  65. data/doc/table_row_data.rdoc +0 -92
  66. data/doc/table_row_header.rdoc +0 -7
data/lib/html/row.rb CHANGED
@@ -1,188 +1,161 @@
1
+ # The HTML module is a namespace only.
1
2
  module HTML
2
- class Table::Row < Array
3
- include HTML::Mixin::AttributeHandler
4
- include HTML::Mixin::HtmlHandler
5
-
6
- @indent_level = 3
7
- @end_tags = true
8
-
9
- # Returns a new Table::Row object. Optionally takes a block. If +arg+
10
- # is provided it is treated as content. If +header+ is false, that
11
- # content is transformed into a Row::Data object. Otherwise, it is
12
- # converted into a Row::Header object.
13
- #
14
- # See the # Table::Row#content= method for more information.
15
- #--
16
- # Note that, despite the name, Row is a subclass of Array, not Table.
17
- #
18
- def initialize(arg = nil, header = false, &block)
19
- @html_begin = '<tr'
20
- @html_end = '</tr>'
21
-
22
- @header = header
23
-
24
- instance_eval(&block) if block_given?
25
- self.content = arg if arg
3
+ # The Table::Row class is a subclass of array that encapsulates an
4
+ # html table row, i.e. <tr> element.
5
+ class Table::Row < Array
6
+ include HTML::Mixin::AttributeHandler
7
+ include HTML::Mixin::HtmlHandler
8
+ include HTML::Mixin::StrongTyping
9
+ extend HTML::Mixin::StrongTyping
10
+
11
+ @indent_level = 3
12
+ @end_tags = true
13
+
14
+ # Gets and sets whether or not content is converted into a Row::Header
15
+ # object or a Row::Data object.
16
+ attr_accessor :header
17
+
18
+ # Returns a new Table::Row object. Optionally takes a block. If +arg+
19
+ # is provided it is treated as content. If +header+ is false, that
20
+ # content is transformed into a Row::Data object. Otherwise, it is
21
+ # converted into a Row::Header object.
22
+ #
23
+ # See the # Table::Row#content= method for more information.
24
+ #--
25
+ # Note that, despite the name, Row is a subclass of Array, not Table.
26
+ #
27
+ def initialize(arg = nil, header = false, &block)
28
+ @html_begin = '<tr'
29
+ @html_end = '</tr>'
30
+ @header = header
31
+ instance_eval(&block) if block_given?
32
+ self.content = arg if arg
33
+ end
34
+
35
+ # Returns whether or not content is converted into a Row::Header object
36
+ # (as opposed to a Row::Data object).
37
+ #
38
+ def header?
39
+ @header
40
+ end
41
+
42
+ # Adds content to the Row object.
43
+ #
44
+ # Because a Row object doesn't store any of its own content, the
45
+ # arguments to this method must be a Row::Data object, a Row::Header
46
+ # object, or a String (or an array of any of these). In the latter case,
47
+ # a single Row::Data object is created for each string.
48
+ #
49
+ # Examples (with whitespace and newlines removed):
50
+ #
51
+ # row = Table::Row.new
52
+ #
53
+ # # Same as Table::Row.new('foo')
54
+ # row.content = 'foo'
55
+ # row.html => <tr><td>foo</td></tr>
56
+ #
57
+ # row.content = [['foo,'bar']]
58
+ # row.html => <tr><td>foo</td><td>bar</td></tr>
59
+ #
60
+ # row.content = Table::Row::Data.new('foo')
61
+ # row.html => <tr><td>foo</td></tr>
62
+ #
63
+ # row.content = Table::Row::Header.new('foo')
64
+ # row.html => <tr><th>foo</th></tr>
65
+ #
66
+ def content=(arg)
67
+ Array(arg).each do |e|
68
+ push_content(e)
26
69
  end
27
-
28
- # Returns whether or not content is converted into a Row::Header object
29
- # (as opposed to a Row::Data object).
30
- #
31
- def header?
32
- @header
33
- end
34
-
35
- # Sets whether or not content is converted into a Row::Header object
36
- # or a Row::Data object.
37
- #
38
- def header=(bool)
39
- @header = bool
70
+ end
71
+
72
+ # Returns the number of spaces that tags for this class are indented.
73
+ # For the Row class, the indention level defaults to 3.
74
+ #
75
+ def self.indent_level
76
+ @indent_level
77
+ end
78
+
79
+ # Sets the number of spaces that tags for this class are indented.
80
+ #
81
+ def self.indent_level=(num)
82
+ expect(num, Integer)
83
+ raise ArgumentError, "Indent level must be non-negative" if num < 0
84
+ @indent_level = num
85
+ end
86
+
87
+ # Returns true or false, depending on whether or not the end tags for
88
+ # this class, </tr>, are included for each row or not. By default, this
89
+ # is set to true.
90
+ #
91
+ def self.end_tags?
92
+ @end_tags
93
+ end
94
+
95
+ # Sets the behavior for whether or not the end tags for this class,
96
+ # </tr>, are included for each row or not. Only true and false are
97
+ # valid arguments.
98
+ #
99
+ def self.end_tags=(bool)
100
+ expect(bool, [TrueClass, FalseClass])
101
+ @end_tags = bool
102
+ end
103
+
104
+ # This method has been redefined to only allow certain classes to be
105
+ # accepted as arguments. Specifically, they are Data and Header. An
106
+ # Array is also valid, but only if it only includes Data or Header objects.
107
+ #
108
+ def []=(index, obj)
109
+ objs = obj.is_a?(Array) ? obj : [obj]
110
+ objs.each { |o| expect(o, [Data, Header]) }
111
+ super
112
+ end
113
+
114
+ # This method has been redefined to only allow certain classes to be
115
+ # accepted as arguments. Specifically, they are String, Integer, Data,
116
+ # and Header.
117
+ #
118
+ # A plain string or number pushed onto a Row is automatically
119
+ # converted to a Data object.
120
+ #
121
+ def push(*args)
122
+ args.each { |obj| super(convert_content(obj)) }
123
+ end
124
+
125
+ # This method has been redefined to only allow certain classes to be
126
+ # accepted as arguments. The rules are the same as they are for Row#push.
127
+ #
128
+ def <<(obj)
129
+ super(convert_content(obj))
130
+ end
131
+
132
+ # This method has been redefined to only allow certain classes to be
133
+ # accepted as arguments. The rules are the same as they are for Row#push.
134
+ #
135
+ def unshift(obj)
136
+ super(convert_content(obj))
137
+ end
138
+
139
+ alias to_s html
140
+ alias to_str html
141
+
142
+ private
143
+
144
+ def push_content(e)
145
+ if e.is_a?(Table::Row::Data) || e.is_a?(Table::Row::Header)
146
+ push(e)
147
+ else
148
+ push(@header ? Table::Row::Header.new(e) : Table::Row::Data.new(e))
40
149
  end
41
-
42
- # Adds content to the Row object.
43
- #
44
- # Because a Row object doesn't store any of its own content, the
45
- # arguments to this method must be a Row::Data object, a Row::Header
46
- # object, or a String (or an array of any of these). In the latter case,
47
- # a single Row::Data object is created for each string.
48
- #
49
- # Examples (with whitespace and newlines removed):
50
- #
51
- # row = Table::Row.new
52
- #
53
- # # Same as Table::Row.new('foo')
54
- # row.content = 'foo'
55
- # row.html => <tr><td>foo</td></tr>
56
- #
57
- # row.content = [['foo,'bar']]
58
- # row.html => <tr><td>foo</td><td>bar</td></tr>
59
- #
60
- # row.content = Table::Row::Data.new('foo')
61
- # row.html => <tr><td>foo</td></tr>
62
- #
63
- # row.content = Table::Row::Header.new('foo')
64
- # row.html => <tr><th>foo</th></tr>
65
- #
66
- def content=(arg)
67
- case arg
68
- when String
69
- if @header
70
- self.push(Table::Row::Header.new(arg))
71
- else
72
- self.push(Table::Row::Data.new(arg))
73
- end
74
- when Array
75
- arg.each{ |e|
76
- if e.kind_of?(Table::Row::Data) || e.kind_of?(Table::Row::Header)
77
- self.push(e)
78
- else
79
- if @header
80
- self.push(Table::Row::Header.new(e))
81
- else
82
- self.push(Table::Row::Data.new(e))
83
- end
84
- end
85
- }
86
- else
87
- self.push(arg)
88
- end
89
- end
90
-
91
- # Returns the number of spaces that tags for this class are indented.
92
- # For the Row class, the indention level defaults to 3.
93
- #
94
- def self.indent_level
95
- @indent_level
150
+ end
151
+
152
+ def convert_content(obj)
153
+ if obj.is_a?(String) || obj.is_a?(Integer)
154
+ Table::Row::Data.new(obj.to_s)
155
+ else
156
+ expect(obj, [Data, Header])
157
+ obj
96
158
  end
97
-
98
- # Sets the number of spaces that tags for this class are indented.
99
- #
100
- def self.indent_level=(num)
101
- expect(num, Integer)
102
- raise ArgumentError if num < 0
103
- @indent_level = num
104
- end
105
-
106
- # Returns true or false, depending on whether or not the end tags for
107
- # this class, </tr>, are included for each row or not. By default, this
108
- # is set to true.
109
- #
110
- def self.end_tags?
111
- @end_tags
112
- end
113
-
114
- # Sets the behavior for whether or not the end tags for this class,
115
- # </tr>, are included for each row or not. Only true and false are
116
- # valid arguments.
117
- #
118
- def self.end_tags=(bool)
119
- expect(bool,[TrueClass,FalseClass])
120
- @end_tags = bool
121
- end
122
-
123
- # This method has been redefined to only allow certain classes to be
124
- # accepted as arguments. Specifically, they are Data and Header. An
125
- # Array is also valid, but only if it only includes Data or Header
126
- # objects.
127
- #
128
- def []=(index, obj)
129
- if obj.kind_of?(Array)
130
- obj.each{ |o| expect(o, [Data, Header]) }
131
- else
132
- expect(obj, [Data, Header])
133
- end
134
- super
135
- end
136
-
137
- # This method has been redefined to only allow certain classes to be
138
- # accepted as arguments. Specifically, they are String, Integer,
139
- # Data and Header.
140
- #
141
- # A plain string or number pushed onto a Row is automatically
142
- # converted to a Data object.
143
- #
144
- def push(*args)
145
- args.each do |obj|
146
- if obj.kind_of?(String) || obj.kind_of?(Integer)
147
- td = Table::Row::Data.new(obj.to_s)
148
- super(td)
149
- next
150
- else
151
- expect(obj, [Data, Header])
152
- end
153
- super(obj)
154
- end
155
- end
156
-
157
- # This method has been redefined to only allow certain classes to be
158
- # accepted as arguments. The rules are the same as they are for
159
- # Row#push.
160
- #
161
- def <<(obj)
162
- if obj.kind_of?(String) || obj.kind_of?(Integer)
163
- td = Table::Row::Data.new(obj.to_s)
164
- super(td)
165
- else
166
- expect(obj, [Data, Header])
167
- end
168
- super(obj)
169
- end
170
-
171
- # This method has been redefined to only allow certain classes to be
172
- # accepted as arguments. The rules are the same as they are for
173
- # Row#push.
174
- #
175
- def unshift(obj)
176
- if obj.kind_of?(String) || obj.kind_of?(Integer)
177
- td = Table::Row::Data.new(obj.to_s)
178
- super(td)
179
- else
180
- expect(obj,[Data,Header])
181
- end
182
- super(obj)
183
- end
184
-
185
- alias to_s html
186
- alias to_str html
187
- end
159
+ end
160
+ end
188
161
  end
data/lib/html/table.rb CHANGED
@@ -2,7 +2,6 @@ require_relative 'mixin/attribute_handler'
2
2
  require_relative 'mixin/html_handler'
3
3
  require_relative 'mixin/strongtyping'
4
4
  require 'structured_warnings'
5
- include HTML::Mixin::StrongTyping
6
5
 
7
6
  # Warning raised if a non-standard extension is used.
8
7
  class NonStandardExtensionWarning < StructuredWarnings::StandardWarning; end
@@ -10,6 +9,9 @@ class NonStandardExtensionWarning < StructuredWarnings::StandardWarning; end
10
9
  # Please, think of the children before using the blink tag.
11
10
  class BlinkWarning < StructuredWarnings::StandardWarning; end
12
11
 
12
+ # Used by the strongtyping mixin.
13
+ class ArgumentTypeError < ArgumentError; end
14
+
13
15
  # The HTML module serves as a namespace only.
14
16
  module HTML
15
17
 
@@ -18,9 +20,11 @@ module HTML
18
20
  class Table < Array
19
21
  include HTML::Mixin::AttributeHandler
20
22
  include HTML::Mixin::HtmlHandler
23
+ include HTML::Mixin::StrongTyping
24
+ extend HTML::Mixin::StrongTyping
21
25
 
22
26
  # The version of the html-table library
23
- VERSION = '1.7.0'.freeze
27
+ VERSION = '1.7.1'.freeze
24
28
 
25
29
  # The indentation level for the <table> and </table> tags
26
30
  @indent_level = 0
@@ -29,7 +33,7 @@ module HTML
29
33
  @html_case = 'lower'
30
34
 
31
35
  # Determines whether or not end tags will be included in printed output
32
- @@global_end_tags = true
36
+ @global_end_tags = true
33
37
 
34
38
  # Returns a new Table object. Optionally takes a block which is
35
39
  # eval'd if provided. If an argument is provided it is interpreted as
@@ -94,9 +98,9 @@ module HTML
94
98
  self.content = arg if arg
95
99
 
96
100
  # Assume html_options are attributes
97
- html_options.each{ |key, val|
98
- self.send("#{key}=", val)
99
- }
101
+ html_options.each do |key, val|
102
+ send("#{key}=", val)
103
+ end
100
104
  end
101
105
 
102
106
  # Adds content to the table. How this method behaves depends on the
@@ -108,8 +112,8 @@ module HTML
108
112
  # object is created, with the string as the content.
109
113
  #
110
114
  def content=(arg)
111
- if arg.kind_of?(Array)
112
- arg.each{ |e| self << Table::Row.new(e) }
115
+ if arg.is_a?(Array)
116
+ arg.each { |e| self << Table::Row.new(e) }
113
117
  else
114
118
  self << Table::Row.new(arg)
115
119
  end
@@ -128,8 +132,8 @@ module HTML
128
132
  # object.
129
133
  #
130
134
  def header=(arg)
131
- if arg.kind_of?(Array)
132
- arg.each{ |h| self << Table::Row.new(h, true) }
135
+ if arg.is_a?(Array)
136
+ arg.each { |h| self << Table::Row.new(h, true) }
133
137
  else
134
138
  self << Table::Row::Header.new(arg)
135
139
  end
@@ -139,18 +143,18 @@ module HTML
139
143
  # turned on or off, respectively.
140
144
  #
141
145
  def self.global_end_tags?
142
- @@global_end_tags
146
+ @global_end_tags
143
147
  end
144
148
 
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.
149
+ # Sets the end tag class variable. This is used to set whether or not
150
+ # to include optional end tags in the final HTML output. The argument
151
+ # sent to this method must be true or false. The default value is true.
148
152
  #
149
153
  # Note that mandatory end tags are unaffected by this setting.
150
154
  #
151
155
  def self.global_end_tags=(bool)
152
156
  expect(bool, [TrueClass, FalseClass])
153
- @@global_end_tags = bool
157
+ @global_end_tags = bool
154
158
  end
155
159
 
156
160
  # Returns either "lower" or "upper", indicating the case of all HTML
@@ -160,13 +164,13 @@ module HTML
160
164
  @html_case
161
165
  end
162
166
 
163
- # Sets the case of all HTML tags to either lower or upper. The only
167
+ # Sets the case of all HTML tags to either lower or upper. The only
164
168
  # valid arguments to this method are 'upper' or 'lower'.
165
169
  #
166
170
  def self.html_case=(arg)
167
171
  expect(arg, String)
168
172
  arg.downcase!
169
- unless arg == "upper" || arg == "lower"
173
+ unless %w[upper lower].include?(arg)
170
174
  msg = "Argument to html_case() must be 'upper' or 'lower'"
171
175
  raise ArgumentError, msg
172
176
  end
@@ -187,7 +191,7 @@ module HTML
187
191
  #
188
192
  def self.indent_level=(num)
189
193
  expect(num, Integer)
190
- raise ArgumentError, "indent level must be >= 0" if num < 0
194
+ raise ArgumentError, 'indent level must be >= 0' if num < 0
191
195
  @indent_level = num
192
196
  end
193
197
 
@@ -200,30 +204,30 @@ module HTML
200
204
  # only be assigned to index 0, or index 1 if a Caption already exists.
201
205
  # A Foot may only be assigned as the last element.
202
206
  #
203
- def []=(index,obj)
207
+ def []=(index, obj)
204
208
  expect(obj, [Caption, ColGroup, Body, Foot, Head, Row])
205
209
 
206
210
  # 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"
211
+ if index != 0 && obj.is_a?(HTML::Table::Caption)
212
+ msg = 'CAPTION can only be added at index 0'
209
213
  raise ArgumentError, msg
210
214
  end
211
215
 
212
216
  # 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"
217
+ if obj.is_a?(HTML::Table::Head)
218
+ if self[0].is_a?(HTML::Table::Caption) && index != 1
219
+ msg = 'THEAD must be at index 1 when Caption is included'
216
220
  raise ArgumentError, msg
217
221
  end
218
222
 
219
- if !self[0].kind_of?(HTML::Table::Caption) && index != 0
220
- msg = "THEAD must be at index 0 when no Caption is included"
223
+ if !self[0].is_a?(HTML::Table::Caption) && index != 0
224
+ msg = 'THEAD must be at index 0 when no Caption is included'
221
225
  raise ArgumentError, msg
222
226
  end
223
227
  end
224
228
 
225
- if obj.kind_of?(HTML::Table::Foot) && index != -1
226
- msg = "FOOT must be last element"
229
+ if obj.is_a?(HTML::Table::Foot) && index != -1
230
+ msg = 'FOOT must be last element'
227
231
  raise ArgumentError, msg
228
232
  end
229
233
 
@@ -242,29 +246,27 @@ module HTML
242
246
  # element, or the second element if a Caption already exists.
243
247
  #
244
248
  def push(*args)
245
- args.each{ |obj|
249
+ args.each do |obj|
246
250
  expect(obj, [Caption, ColGroup, Body, Foot, Head, Row, Row::Data, Row::Header])
247
251
 
248
252
  case obj
249
253
  when Table::Row::Data, Table::Row::Header
250
- self.push(Table::Row.new(obj))
254
+ push(Table::Row.new(obj))
251
255
  when Table::Caption
252
- if self[0].kind_of?(Table::Caption)
256
+ if self[0].is_a?(Table::Caption)
253
257
  self[0] = obj
254
258
  else
255
- self.unshift(obj)
259
+ unshift(obj)
256
260
  end
257
261
  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)
262
+ unshift(obj)
263
+ if self[0].is_a?(Table::Caption)
264
+ self[0], self[1] = self[1], self[0]
263
265
  end
264
266
  else
265
267
  super(obj)
266
268
  end
267
- }
269
+ end
268
270
  end
269
271
 
270
272
  # This method has been redefined to only allow certain subclasses to
@@ -279,20 +281,18 @@ module HTML
279
281
  when Table::Row::Data, Table::Row::Header # Each get their own row
280
282
  self << Table::Row.new(obj)
281
283
  when Table::Caption # Always the first row
282
- if self[0].kind_of?(Table::Caption)
284
+ if self[0].is_a?(Table::Caption)
283
285
  self[0] = obj
284
286
  else
285
- self.unshift(obj)
287
+ unshift(obj)
286
288
  end
287
289
  when Table::Head # Always at row 0 or 1
288
- if self[0].kind_of?(Table::Caption)
289
- self.unshift(obj)
290
+ unshift(obj)
291
+ if self[0].is_a?(Table::Caption)
290
292
  self[0], self[1] = self[1], self[0]
291
- else
292
- self.unshift(obj)
293
293
  end
294
294
  else
295
- super(obj)
295
+ super
296
296
  end
297
297
  end
298
298
 
@@ -1,48 +1,53 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
2
- # Superclass for THEAD, TBODY, TFOOT
3
- #
4
- class Table::TableSection < Array
5
- include HTML::Mixin::AttributeHandler
6
- include HTML::Mixin::HtmlHandler
7
-
8
- def initialize(&block)
9
- instance_eval(&block) if block_given?
10
- end
11
-
12
- # Adds a Table::Row object as content. The +arg+ is passed as the value
13
- # to the Table::Row constructor.
14
- #
15
- def content=(arg)
16
- tr = Table::Row.new(arg)
17
- self.push(tr)
18
- end
19
-
20
- def self.indent_level
21
- @indent_level
22
- end
23
-
24
- def self.indent_level=(num)
25
- expect(num, Integer)
26
- raise ArgumentError, "indent_level must be >= 0" if num < 0
27
- @indent_level = num
28
- end
29
-
30
- def []=(index,obj)
31
- expect(obj,Table::Row)
32
- super
33
- end
34
-
35
- def push(*args)
36
- args.each{ |obj| expect(obj,Table::Row) }
37
- super
38
- end
39
-
40
- def unshift(obj)
41
- expect(obj,Table::Row)
42
- super
43
- end
44
-
45
- alias to_s html
46
- alias to_str html
47
- end
3
+
4
+ # Superclass for THEAD, TBODY, TFOOT
5
+ #
6
+ class Table::TableSection < Array
7
+ include HTML::Mixin::AttributeHandler
8
+ include HTML::Mixin::HtmlHandler
9
+ include HTML::Mixin::StrongTyping
10
+ extend HTML::Mixin::StrongTyping
11
+
12
+ def initialize(&block)
13
+ super
14
+ instance_eval(&block) if block_given?
15
+ end
16
+
17
+ # Adds a Table::Row object as content. The +arg+ is passed as the value
18
+ # to the Table::Row constructor.
19
+ #
20
+ def content=(arg)
21
+ tr = Table::Row.new(arg)
22
+ push(tr)
23
+ end
24
+
25
+ def self.indent_level
26
+ @indent_level
27
+ end
28
+
29
+ def self.indent_level=(num)
30
+ expect(num, Integer)
31
+ raise ArgumentError, 'indent_level must be >= 0' if num < 0
32
+ @indent_level = num
33
+ end
34
+
35
+ def []=(index, obj)
36
+ expect(obj, Table::Row)
37
+ super
38
+ end
39
+
40
+ def push(*args)
41
+ args.each { |obj| expect(obj, Table::Row) }
42
+ super
43
+ end
44
+
45
+ def unshift(obj)
46
+ expect(obj, Table::Row)
47
+ super
48
+ end
49
+
50
+ alias to_s html
51
+ alias to_str html
52
+ end
48
53
  end