html-table 1.5.0 → 1.5.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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +3 -1
- data.tar.gz.sig +0 -0
- data/CHANGES +159 -155
- data/MANIFEST +59 -59
- data/README +132 -132
- data/certs/djberg96_pub.pem +22 -17
- 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 +159 -158
- data/test/test_tablesection.rb +42 -42
- data/test/test_tag_handler.rb +90 -90
- metadata +25 -20
- metadata.gz.sig +0 -0
data/lib/html/html_handler.rb
CHANGED
@@ -1,120 +1,120 @@
|
|
1
|
-
module HtmlHandler
|
2
|
-
|
3
|
-
$upper = false
|
4
|
-
|
5
|
-
# Used on HTML attributes. It creates proper HTML text based on the argument
|
6
|
-
# type. A string looks like "attr='text'", a number looks like "attr=1",
|
7
|
-
# while a true value simply looks like "attr" (no equal sign).
|
8
|
-
#--
|
9
|
-
# This is private method.
|
10
|
-
#
|
11
|
-
def modify_html(attribute,arg=nil)
|
12
|
-
if @html_begin.scan(/\b#{attribute}\b/).empty?
|
13
|
-
if arg.kind_of?(
|
14
|
-
@html_begin << " #{attribute}=#{arg}"
|
15
|
-
elsif arg.kind_of?(TrueClass)
|
16
|
-
@html_begin << " #{attribute}"
|
17
|
-
else
|
18
|
-
@html_begin << " #{attribute}='#{arg}'"
|
19
|
-
end
|
20
|
-
else
|
21
|
-
if arg.kind_of?(
|
22
|
-
@html_begin.gsub!(/#{attribute}=\d+/,"#{attribute}=#{arg}")
|
23
|
-
elsif arg.kind_of?(FalseClass)
|
24
|
-
@html_begin.gsub!(/#{attribute}/,'')
|
25
|
-
else
|
26
|
-
@html_begin.gsub!(/#{attribute}=['\w\.]+/,"#{attribute}='#{arg}'")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Returns the HTML text for the current object. Indentation and end tag
|
32
|
-
# options are optional, based on the settings of the classes themselves.
|
33
|
-
#
|
34
|
-
# If +formatting+ is false, then formatting and whitespace is not applied
|
35
|
-
# and you will get a single, very long string. Note that case is still
|
36
|
-
# honored.
|
37
|
-
#
|
38
|
-
def html(formatting = true)
|
39
|
-
if self.class.respond_to?(:html_case)
|
40
|
-
$upper = true if self.class.html_case == "upper"
|
41
|
-
end
|
42
|
-
|
43
|
-
if $upper
|
44
|
-
@html_begin.upcase!
|
45
|
-
@html_end.upcase!
|
46
|
-
end
|
47
|
-
|
48
|
-
ilevel = 0
|
49
|
-
|
50
|
-
if formatting && self.class.respond_to?(:indent_level)
|
51
|
-
ilevel = self.class.indent_level
|
52
|
-
end
|
53
|
-
|
54
|
-
html = ' ' * ilevel + @html_begin[0..-1]
|
55
|
-
len = html.length
|
56
|
-
html[len,len] = '>'
|
57
|
-
|
58
|
-
if self.kind_of?(Array)
|
59
|
-
if formatting
|
60
|
-
html << self.map{ |e| "\n" + e.html(formatting).to_s }.join
|
61
|
-
else
|
62
|
-
html << self.map{ |e| e.html(formatting).to_s }.join
|
63
|
-
end
|
64
|
-
else
|
65
|
-
html << @html_body
|
66
|
-
end
|
67
|
-
|
68
|
-
#####################################################################
|
69
|
-
# Add end tags, or not, depending on whether the class supports the
|
70
|
-
# end_tags class method. Those that don't have an end_tags class
|
71
|
-
# method necessarily means that the end tag must be included.
|
72
|
-
#
|
73
|
-
# The Table.global_end_tags method overrides the individual class
|
74
|
-
# preferences with regards to end tags.
|
75
|
-
#####################################################################
|
76
|
-
if self.kind_of?(Array)
|
77
|
-
if HTML::Table.global_end_tags?
|
78
|
-
if self.class.respond_to?(:end_tags?)
|
79
|
-
if formatting
|
80
|
-
if self.class.end_tags?
|
81
|
-
html << "\n" + (' ' * ilevel) + @html_end
|
82
|
-
end
|
83
|
-
else
|
84
|
-
html << (' ' * ilevel) + @html_end if self.class.end_tags?
|
85
|
-
end
|
86
|
-
else
|
87
|
-
if formatting
|
88
|
-
html << "\n" + (' ' * ilevel) + @html_end
|
89
|
-
else
|
90
|
-
html << (' ' * ilevel) + @html_end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
else
|
94
|
-
unless self.class.respond_to?(:end_tags?)
|
95
|
-
if formatting
|
96
|
-
html << "\n" + (' ' * ilevel) + @html_end
|
97
|
-
else
|
98
|
-
html << (' ' * ilevel) + @html_end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
else
|
103
|
-
if HTML::Table.global_end_tags?
|
104
|
-
if self.class.respond_to?(:end_tags?)
|
105
|
-
html << @html_end if self.class.end_tags?
|
106
|
-
else
|
107
|
-
html << @html_end
|
108
|
-
end
|
109
|
-
else
|
110
|
-
unless self.class.respond_to?(:end_tags?)
|
111
|
-
html << @html_end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
return html
|
117
|
-
end
|
118
|
-
|
119
|
-
private :modify_html
|
120
|
-
end
|
1
|
+
module HtmlHandler
|
2
|
+
|
3
|
+
$upper = false
|
4
|
+
|
5
|
+
# Used on HTML attributes. It creates proper HTML text based on the argument
|
6
|
+
# type. A string looks like "attr='text'", a number looks like "attr=1",
|
7
|
+
# while a true value simply looks like "attr" (no equal sign).
|
8
|
+
#--
|
9
|
+
# This is private method.
|
10
|
+
#
|
11
|
+
def modify_html(attribute,arg=nil)
|
12
|
+
if @html_begin.scan(/\b#{attribute}\b/).empty?
|
13
|
+
if arg.kind_of?(Integer)
|
14
|
+
@html_begin << " #{attribute}=#{arg}"
|
15
|
+
elsif arg.kind_of?(TrueClass)
|
16
|
+
@html_begin << " #{attribute}"
|
17
|
+
else
|
18
|
+
@html_begin << " #{attribute}='#{arg}'"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
if arg.kind_of?(Integer)
|
22
|
+
@html_begin.gsub!(/#{attribute}=\d+/,"#{attribute}=#{arg}")
|
23
|
+
elsif arg.kind_of?(FalseClass)
|
24
|
+
@html_begin.gsub!(/#{attribute}/,'')
|
25
|
+
else
|
26
|
+
@html_begin.gsub!(/#{attribute}=['\w\.]+/,"#{attribute}='#{arg}'")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the HTML text for the current object. Indentation and end tag
|
32
|
+
# options are optional, based on the settings of the classes themselves.
|
33
|
+
#
|
34
|
+
# If +formatting+ is false, then formatting and whitespace is not applied
|
35
|
+
# and you will get a single, very long string. Note that case is still
|
36
|
+
# honored.
|
37
|
+
#
|
38
|
+
def html(formatting = true)
|
39
|
+
if self.class.respond_to?(:html_case)
|
40
|
+
$upper = true if self.class.html_case == "upper"
|
41
|
+
end
|
42
|
+
|
43
|
+
if $upper
|
44
|
+
@html_begin.upcase!
|
45
|
+
@html_end.upcase!
|
46
|
+
end
|
47
|
+
|
48
|
+
ilevel = 0
|
49
|
+
|
50
|
+
if formatting && self.class.respond_to?(:indent_level)
|
51
|
+
ilevel = self.class.indent_level
|
52
|
+
end
|
53
|
+
|
54
|
+
html = ' ' * ilevel + @html_begin[0..-1]
|
55
|
+
len = html.length
|
56
|
+
html[len,len] = '>'
|
57
|
+
|
58
|
+
if self.kind_of?(Array)
|
59
|
+
if formatting
|
60
|
+
html << self.map{ |e| "\n" + e.html(formatting).to_s }.join
|
61
|
+
else
|
62
|
+
html << self.map{ |e| e.html(formatting).to_s }.join
|
63
|
+
end
|
64
|
+
else
|
65
|
+
html << @html_body
|
66
|
+
end
|
67
|
+
|
68
|
+
#####################################################################
|
69
|
+
# Add end tags, or not, depending on whether the class supports the
|
70
|
+
# end_tags class method. Those that don't have an end_tags class
|
71
|
+
# method necessarily means that the end tag must be included.
|
72
|
+
#
|
73
|
+
# The Table.global_end_tags method overrides the individual class
|
74
|
+
# preferences with regards to end tags.
|
75
|
+
#####################################################################
|
76
|
+
if self.kind_of?(Array)
|
77
|
+
if HTML::Table.global_end_tags?
|
78
|
+
if self.class.respond_to?(:end_tags?)
|
79
|
+
if formatting
|
80
|
+
if self.class.end_tags?
|
81
|
+
html << "\n" + (' ' * ilevel) + @html_end
|
82
|
+
end
|
83
|
+
else
|
84
|
+
html << (' ' * ilevel) + @html_end if self.class.end_tags?
|
85
|
+
end
|
86
|
+
else
|
87
|
+
if formatting
|
88
|
+
html << "\n" + (' ' * ilevel) + @html_end
|
89
|
+
else
|
90
|
+
html << (' ' * ilevel) + @html_end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
else
|
94
|
+
unless self.class.respond_to?(:end_tags?)
|
95
|
+
if formatting
|
96
|
+
html << "\n" + (' ' * ilevel) + @html_end
|
97
|
+
else
|
98
|
+
html << (' ' * ilevel) + @html_end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
else
|
103
|
+
if HTML::Table.global_end_tags?
|
104
|
+
if self.class.respond_to?(:end_tags?)
|
105
|
+
html << @html_end if self.class.end_tags?
|
106
|
+
else
|
107
|
+
html << @html_end
|
108
|
+
end
|
109
|
+
else
|
110
|
+
unless self.class.respond_to?(:end_tags?)
|
111
|
+
html << @html_end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
return html
|
117
|
+
end
|
118
|
+
|
119
|
+
private :modify_html
|
120
|
+
end
|
data/lib/html/row.rb
CHANGED
@@ -1,188 +1,188 @@
|
|
1
|
-
module HTML
|
2
|
-
class Table::Row < Array
|
3
|
-
include AttributeHandler
|
4
|
-
include 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
|
26
|
-
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
|
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
|
-
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
|
96
|
-
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,
|
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?(
|
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?(
|
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?(
|
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
|
188
|
-
end
|
1
|
+
module HTML
|
2
|
+
class Table::Row < Array
|
3
|
+
include AttributeHandler
|
4
|
+
include 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
|
26
|
+
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
|
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
|
+
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
|
96
|
+
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
|
188
|
+
end
|