html-table 1.2.2 → 1.3.0
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.
- data/CHANGES +17 -0
- data/MANIFEST +15 -0
- data/README +8 -1
- data/doc/table_content.rdoc +15 -0
- data/lib/html/attribute_handler.rb +135 -60
- data/lib/html/body.rb +6 -2
- data/lib/html/caption.rb +9 -3
- data/lib/html/col.rb +8 -3
- data/lib/html/colgroup.rb +13 -2
- data/lib/html/content.rb +18 -0
- data/lib/html/data.rb +13 -4
- data/lib/html/foot.rb +8 -2
- data/lib/html/head.rb +11 -4
- data/lib/html/header.rb +13 -4
- data/lib/html/html_handler.rb +33 -7
- data/lib/html/row.rb +79 -23
- data/lib/html/table.rb +90 -62
- data/lib/html/tablesection.rb +7 -4
- data/lib/html/tag_handler.rb +73 -23
- data/test/tc_attribute_handler.rb +165 -151
- data/test/tc_row.rb +14 -1
- data/test/tc_table.rb +1 -1
- data/test/tc_tag_handler.rb +92 -0
- data/test/ts_all.rb +19 -18
- metadata +42 -35
data/lib/html/body.rb
CHANGED
|
@@ -2,22 +2,25 @@ module HTML
|
|
|
2
2
|
|
|
3
3
|
# This class represents an HTML table body (<tbody>). It is a
|
|
4
4
|
# subclass of Table::TableSection.
|
|
5
|
+
#
|
|
5
6
|
class Table::Body < Table::TableSection
|
|
6
7
|
@indent_level = 3
|
|
7
8
|
@end_tags = true
|
|
8
9
|
|
|
9
10
|
# Returns a new Table::Body object. Optionally takes a block. If
|
|
10
11
|
# an argument is provided, it is treated as content.
|
|
11
|
-
|
|
12
|
+
#
|
|
13
|
+
def initialize(arg = nil, &block)
|
|
12
14
|
@html_begin = "<tbody"
|
|
13
15
|
@html_end = "</tbody>"
|
|
14
|
-
|
|
16
|
+
instance_eval(&block) if block_given?
|
|
15
17
|
self.content = arg if arg
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# Returns a boolean indicating whether or not end tags, </tbody>, are
|
|
19
21
|
# included for each Body object in the final HTML output. The
|
|
20
22
|
# default is true.
|
|
23
|
+
#
|
|
21
24
|
def self.end_tags?
|
|
22
25
|
@end_tags
|
|
23
26
|
end
|
|
@@ -25,6 +28,7 @@ module HTML
|
|
|
25
28
|
# Sets whether or not end tags are included for each Body object in
|
|
26
29
|
# the final HTML output. The default is true. Only true or false are
|
|
27
30
|
# valid arguments.
|
|
31
|
+
#
|
|
28
32
|
def self.end_tags=(bool)
|
|
29
33
|
expect(bool,[TrueClass,FalseClass])
|
|
30
34
|
@end_tags = bool
|
data/lib/html/caption.rb
CHANGED
|
@@ -2,34 +2,40 @@ module HTML
|
|
|
2
2
|
|
|
3
3
|
# This class represents an HTML Caption. Despite the name, it is not
|
|
4
4
|
# a subclass of Table. Note that end tags for this class are mandatory.
|
|
5
|
+
#
|
|
5
6
|
class Table::Caption
|
|
6
7
|
include AttributeHandler
|
|
7
8
|
include HtmlHandler
|
|
9
|
+
|
|
8
10
|
undef_method :configure
|
|
9
11
|
@indent_level = 3
|
|
10
12
|
|
|
11
13
|
# Returns a new Table::Caption object. Optionally takes a block. If
|
|
12
14
|
# an argument is provided it is treated as content.
|
|
13
|
-
|
|
15
|
+
#
|
|
16
|
+
def initialize(arg = nil, &block)
|
|
14
17
|
@html_begin = '<caption'
|
|
15
18
|
@html_body = ''
|
|
16
19
|
@html_end = '</caption>'
|
|
17
|
-
|
|
20
|
+
instance_eval(&block) if block_given?
|
|
18
21
|
self.content = arg if arg
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
# Adds content to the Table::Caption object.
|
|
25
|
+
#
|
|
22
26
|
def content=(arg)
|
|
23
|
-
@html_body = arg.to_s
|
|
27
|
+
@html_body = Table::Content.new(arg.to_s)
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
# Returns the number of spaces that tags for this class are indented.
|
|
27
31
|
# For the Table::Caption class, the indention level defaults to 3.
|
|
32
|
+
#
|
|
28
33
|
def self.indent_level
|
|
29
34
|
@indent_level
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
# Sets the number of spaces that tags for this class are indented.
|
|
38
|
+
#
|
|
33
39
|
def self.indent_level=(num)
|
|
34
40
|
expect(num,Integer)
|
|
35
41
|
raise ArgumentError, "indent level must be >= 0" if num < 0
|
data/lib/html/col.rb
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
module HTML
|
|
2
2
|
# This class represents an HTML ColGroup column (<col>). Despite the
|
|
3
3
|
# name, it is not a subclass of ColGroup or Table.
|
|
4
|
+
#
|
|
4
5
|
class Table::ColGroup::Col
|
|
5
6
|
include AttributeHandler
|
|
6
7
|
include HtmlHandler
|
|
8
|
+
|
|
7
9
|
undef_method :configure, :content
|
|
8
10
|
@indent_level = 6
|
|
9
11
|
|
|
10
12
|
# Creates and returns a new ColGroup object. Optionally takes a block.
|
|
11
|
-
# Note that it does not accept an argument - col tags do not have content
|
|
12
|
-
|
|
13
|
+
# Note that it does not accept an argument - col tags do not have content.
|
|
14
|
+
#
|
|
15
|
+
def initialize(&block)
|
|
13
16
|
@html_begin = '<col'
|
|
14
17
|
@html_body = ''
|
|
15
18
|
@html_end = ''
|
|
16
|
-
|
|
19
|
+
instance_eval(&block) if block_given?
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
# Returns the indentation level for the tags of this class. The
|
|
20
23
|
# default is 6.
|
|
24
|
+
#
|
|
21
25
|
def self.indent_level
|
|
22
26
|
@indent_level
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
# Sets the indentation level for the tags of this class. The default
|
|
26
30
|
# is 6.
|
|
31
|
+
#
|
|
27
32
|
def self.indent_level=(num)
|
|
28
33
|
expect(num,Integer)
|
|
29
34
|
raise ArgumentError, "num must be >= 0" if num < 0
|
data/lib/html/colgroup.rb
CHANGED
|
@@ -2,9 +2,11 @@ module HTML
|
|
|
2
2
|
# This class represents an HTML column group (<colgroup>). It is a
|
|
3
3
|
# subclass of Array. The only elements it may contain are instances
|
|
4
4
|
# of the ColGroup::Col class.
|
|
5
|
+
#
|
|
5
6
|
class Table::ColGroup < Array
|
|
6
7
|
include AttributeHandler
|
|
7
8
|
include HtmlHandler
|
|
9
|
+
|
|
8
10
|
@indent_level = 3
|
|
9
11
|
@end_tags = true
|
|
10
12
|
|
|
@@ -12,22 +14,25 @@ module HTML
|
|
|
12
14
|
|
|
13
15
|
# Returns a new ColGroup object. Optionally takes a block. If an
|
|
14
16
|
# argument is provided, it is treated as content.
|
|
15
|
-
|
|
17
|
+
#
|
|
18
|
+
def initialize(arg = nil, &block)
|
|
16
19
|
@html_begin = '<colgroup'
|
|
17
20
|
@html_body = ''
|
|
18
21
|
@html_end = '</colgroup>'
|
|
19
|
-
|
|
22
|
+
instance_eval(&block) if block_given?
|
|
20
23
|
self.push(arg) if arg
|
|
21
24
|
end
|
|
22
25
|
|
|
23
26
|
# Returns the indentation level for the tags of this class. The
|
|
24
27
|
# default is 3.
|
|
28
|
+
#
|
|
25
29
|
def self.indent_level
|
|
26
30
|
@indent_level
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
# Sets the indentation level for the tags of this class. The default
|
|
30
34
|
# is 3.
|
|
35
|
+
#
|
|
31
36
|
def self.indent_level=(num)
|
|
32
37
|
expect(num,Integer)
|
|
33
38
|
raise ArgumentError,"indent_level must be >= 0" if num < 0
|
|
@@ -36,6 +41,7 @@ module HTML
|
|
|
36
41
|
|
|
37
42
|
# This method has been redefined to only allow ColGroup::Col objects
|
|
38
43
|
# to be assigned.
|
|
44
|
+
#
|
|
39
45
|
def []=(index,obj)
|
|
40
46
|
if obj.kind_of?(Array)
|
|
41
47
|
expect(obj.first,Col) # In case of 0 length Array
|
|
@@ -50,6 +56,7 @@ module HTML
|
|
|
50
56
|
|
|
51
57
|
# This method has been redefined to only allow ColGroup::Col objects
|
|
52
58
|
# to be pushed onto a ColGroup instance.
|
|
59
|
+
#
|
|
53
60
|
def push(*args)
|
|
54
61
|
args.each do |obj|
|
|
55
62
|
unless obj.kind_of?(Table::ColGroup::Col)
|
|
@@ -63,6 +70,7 @@ module HTML
|
|
|
63
70
|
|
|
64
71
|
# This method has been redefined to only allow ColGroup::Col objects
|
|
65
72
|
# to be pushed onto a ColGroup instance.
|
|
73
|
+
#
|
|
66
74
|
def <<(obj)
|
|
67
75
|
unless obj.kind_of?(Table::ColGroup::Col)
|
|
68
76
|
msg = "Can only assign Col objects to ColGroup class"
|
|
@@ -74,6 +82,7 @@ module HTML
|
|
|
74
82
|
|
|
75
83
|
# This method has been redefined to only allow ColGroup::Col objects
|
|
76
84
|
# to be unshifted onto a ColGroup instance.
|
|
85
|
+
#
|
|
77
86
|
def unshift(obj)
|
|
78
87
|
unless obj.kind_of?(Table::ColGroup::Col)
|
|
79
88
|
msg = "Can only assign Data and Header objects to Row class"
|
|
@@ -84,6 +93,7 @@ module HTML
|
|
|
84
93
|
|
|
85
94
|
# Returns a boolean indicating whether or not end tags are included for
|
|
86
95
|
# each ColGroup object in the final HTML output. The default is true.
|
|
96
|
+
#
|
|
87
97
|
def self.end_tags?
|
|
88
98
|
@end_tags
|
|
89
99
|
end
|
|
@@ -91,6 +101,7 @@ module HTML
|
|
|
91
101
|
# Sets whether or not end tags are included for each ColGroup object in
|
|
92
102
|
# the final HTML output. The default is true. Only true or false are
|
|
93
103
|
# valid arguments.
|
|
104
|
+
#
|
|
94
105
|
def self.end_tags=(bool)
|
|
95
106
|
expect(bool,[TrueClass,FalseClass])
|
|
96
107
|
@end_tags = bool
|
data/lib/html/content.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
########################################################################
|
|
2
|
+
# content.rb
|
|
3
|
+
#
|
|
4
|
+
# This class handles content for Table::Row::Data, Table::Row::Header,
|
|
5
|
+
# and Table::Row::Caption objects.
|
|
6
|
+
########################################################################
|
|
7
|
+
require 'tag_handler'
|
|
8
|
+
|
|
9
|
+
module HTML
|
|
10
|
+
class Table::Content < String
|
|
11
|
+
include TagHandler
|
|
12
|
+
|
|
13
|
+
def initialize(string, &block)
|
|
14
|
+
super(string)
|
|
15
|
+
instance_eval(&block) if block_given?
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/html/data.rb
CHANGED
|
@@ -2,36 +2,43 @@ module HTML
|
|
|
2
2
|
|
|
3
3
|
# This class represents HTML table data, <td>. Despite the name
|
|
4
4
|
# it is not a subclass of Table::Row or Table.
|
|
5
|
+
#
|
|
5
6
|
class Table::Row::Data
|
|
6
7
|
include AttributeHandler
|
|
7
8
|
include HtmlHandler
|
|
9
|
+
|
|
8
10
|
undef_method :configure
|
|
11
|
+
|
|
9
12
|
@indent_level = 6
|
|
10
13
|
@end_tags = true
|
|
11
14
|
|
|
12
15
|
# Creates and returns a Data object. Optionally takes a block. If
|
|
13
16
|
# an argument is provided, it is treated as content.
|
|
14
|
-
|
|
17
|
+
#
|
|
18
|
+
def initialize(arg = nil, &block)
|
|
15
19
|
@html_begin = '<td'
|
|
16
20
|
@html_body = ''
|
|
17
21
|
@html_end = '</td>'
|
|
18
|
-
|
|
22
|
+
instance_eval(&block) if block_given?
|
|
19
23
|
self.content = arg if arg
|
|
20
24
|
end
|
|
21
|
-
|
|
25
|
+
|
|
22
26
|
# Adds content to the Table::Row::Data object.
|
|
27
|
+
#
|
|
23
28
|
def content=(arg)
|
|
24
|
-
@html_body = arg.to_s
|
|
29
|
+
@html_body = Table::Content.new(arg.to_s)
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
# Returns the indentation level for the tags of this class. The
|
|
28
33
|
# default is 6.
|
|
34
|
+
#
|
|
29
35
|
def self.indent_level
|
|
30
36
|
@indent_level
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
# Sets the indentation level for the tags of this class. The default
|
|
34
40
|
# is 6.
|
|
41
|
+
#
|
|
35
42
|
def self.indent_level=(num)
|
|
36
43
|
expect(num,Integer)
|
|
37
44
|
raise ArgumentError,"indent_level must be >= 0" if num < 0
|
|
@@ -41,6 +48,7 @@ module HTML
|
|
|
41
48
|
# Returns a boolean indicating whether or not end tags, </td>, are
|
|
42
49
|
# included for each Data object in the final HTML output. The
|
|
43
50
|
# default is true.
|
|
51
|
+
#
|
|
44
52
|
def self.end_tags?
|
|
45
53
|
@end_tags
|
|
46
54
|
end
|
|
@@ -48,6 +56,7 @@ module HTML
|
|
|
48
56
|
# Sets whether or not end tags are included for each Data object in
|
|
49
57
|
# the final HTML output. The default is true. Only true or false are
|
|
50
58
|
# valid arguments.
|
|
59
|
+
#
|
|
51
60
|
def self.end_tags=(bool)
|
|
52
61
|
expect(bool,[TrueClass,FalseClass])
|
|
53
62
|
@end_tags = bool
|
data/lib/html/foot.rb
CHANGED
|
@@ -2,8 +2,10 @@ module HTML
|
|
|
2
2
|
|
|
3
3
|
# This class represents an HTML table foot (<tfoot>). It is a
|
|
4
4
|
# subclass of Table::TableSection. It is a singleton class.
|
|
5
|
+
#
|
|
5
6
|
class Table::Foot < Table::TableSection
|
|
6
7
|
private_class_method :new
|
|
8
|
+
|
|
7
9
|
@@foot = nil
|
|
8
10
|
@indent_level = 3
|
|
9
11
|
@end_tags = true
|
|
@@ -11,22 +13,25 @@ module HTML
|
|
|
11
13
|
# This is our constructor for Foot objects because it is a singleton
|
|
12
14
|
# class. Optionally, a block may be provided. If an argument is
|
|
13
15
|
# provided it is treated as content.
|
|
16
|
+
#
|
|
14
17
|
def self.create(arg=nil, &block)
|
|
15
|
-
@@foot = new(arg
|
|
18
|
+
@@foot = new(arg, &block) unless @@foot
|
|
16
19
|
@@foot
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
# Called by create() instead of new(). This initializes the Foot class.
|
|
23
|
+
#
|
|
20
24
|
def initialize(arg, &block)
|
|
21
25
|
@html_begin = "<tfoot"
|
|
22
26
|
@html_end = "</tfoot>"
|
|
23
|
-
|
|
27
|
+
instance_eval(&block) if block_given?
|
|
24
28
|
self.content = arg if arg
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
# Returns a boolean indicating whether or not end tags, </tfoot>, are
|
|
28
32
|
# included for each Foot object in the final HTML output. The
|
|
29
33
|
# default is true.
|
|
34
|
+
#
|
|
30
35
|
def self.end_tags?
|
|
31
36
|
@end_tags
|
|
32
37
|
end
|
|
@@ -34,6 +39,7 @@ module HTML
|
|
|
34
39
|
# Sets whether or not end tags are included for each Foot object in
|
|
35
40
|
# the final HTML output. The default is true. Only true or false are
|
|
36
41
|
# valid arguments.
|
|
42
|
+
#
|
|
37
43
|
def self.end_tags=(bool)
|
|
38
44
|
expect(bool, [TrueClass,FalseClass])
|
|
39
45
|
@end_tags = bool
|
data/lib/html/head.rb
CHANGED
|
@@ -2,31 +2,37 @@ module HTML
|
|
|
2
2
|
|
|
3
3
|
# This class represents an HTML table head (<thead>). It is a
|
|
4
4
|
# subclass of Table::TableSection. It is a singleton class.
|
|
5
|
+
#
|
|
5
6
|
class Table::Head < Table::TableSection
|
|
6
7
|
private_class_method :new
|
|
8
|
+
|
|
7
9
|
@@head = nil
|
|
10
|
+
|
|
8
11
|
@indent_level = 3
|
|
9
12
|
@end_tags = true
|
|
10
13
|
|
|
11
14
|
# This is our constructor for Head objects because it is a singleton
|
|
12
15
|
# class. Optionally, a block may be provided. If an argument is
|
|
13
16
|
# provided it is treated as content.
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
#
|
|
18
|
+
def self.create(arg=nil, &block)
|
|
19
|
+
@@head = new(arg, &block) unless @@head
|
|
16
20
|
@@head
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
# Called by create() instead of new(). This initializes the Head class.
|
|
20
|
-
|
|
24
|
+
#
|
|
25
|
+
def initialize(arg, &block)
|
|
21
26
|
@html_begin = "<thead"
|
|
22
27
|
@html_end = "</thead>"
|
|
23
|
-
|
|
28
|
+
instance_eval(&block) if block_given?
|
|
24
29
|
self.content = arg if arg
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
# Returns a boolean indicating whether or not end tags, </thead>, are
|
|
28
33
|
# included for each Head object in the final HTML output. The
|
|
29
34
|
# default is true.
|
|
35
|
+
#
|
|
30
36
|
def self.end_tags?
|
|
31
37
|
@end_tags
|
|
32
38
|
end
|
|
@@ -34,6 +40,7 @@ module HTML
|
|
|
34
40
|
# Sets whether or not end tags are included for each Head object in
|
|
35
41
|
# the final HTML output. The default is true. Only true or false are
|
|
36
42
|
# valid arguments.
|
|
43
|
+
#
|
|
37
44
|
def self.end_tags=(bool)
|
|
38
45
|
expect(bool,[TrueClass,FalseClass])
|
|
39
46
|
@end_tags = bool
|
data/lib/html/header.rb
CHANGED
|
@@ -2,36 +2,43 @@ module HTML
|
|
|
2
2
|
|
|
3
3
|
# This class represents an HTML table header (<th>). Despite the name
|
|
4
4
|
# it is not a subclass of Table or Table::Row.
|
|
5
|
+
#
|
|
5
6
|
class Table::Row::Header
|
|
6
7
|
include AttributeHandler
|
|
7
8
|
include HtmlHandler
|
|
9
|
+
|
|
8
10
|
undef_method :configure
|
|
11
|
+
|
|
9
12
|
@indent_level = 6
|
|
10
|
-
@end_tags
|
|
13
|
+
@end_tags = true
|
|
11
14
|
|
|
12
15
|
# Creates and returns a new Header object. Optionally takes a block.
|
|
13
16
|
# If an argument is provided, it is treated as content.
|
|
14
|
-
|
|
17
|
+
#
|
|
18
|
+
def initialize(arg = nil, &block)
|
|
15
19
|
@html_begin = '<th'
|
|
16
20
|
@html_body = ''
|
|
17
21
|
@html_end = '</th>'
|
|
18
|
-
|
|
22
|
+
instance_eval(&block) if block_given?
|
|
19
23
|
self.content = arg if arg
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
# Adds content to the Table::Row::Header object.
|
|
27
|
+
#
|
|
23
28
|
def content=(arg)
|
|
24
|
-
@html_body = arg.to_s
|
|
29
|
+
@html_body = Table::Content.new(arg.to_s)
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
# Returns the indentation level for the tags of this class. The
|
|
28
33
|
# default is 6.
|
|
34
|
+
#
|
|
29
35
|
def self.indent_level
|
|
30
36
|
@indent_level
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
# Sets the indentation level for the tags of this class. The default
|
|
34
40
|
# is 6.
|
|
41
|
+
#
|
|
35
42
|
def self.indent_level=(num)
|
|
36
43
|
expect(num,Integer)
|
|
37
44
|
raise ArgumentError,"indent_level must be >= 0" if num < 0
|
|
@@ -40,6 +47,7 @@ module HTML
|
|
|
40
47
|
|
|
41
48
|
# Returns a boolean indicating whether or not end tags are included for
|
|
42
49
|
# each Header object in the final HTML output. The default is true.
|
|
50
|
+
#
|
|
43
51
|
def self.end_tags?
|
|
44
52
|
@end_tags
|
|
45
53
|
end
|
|
@@ -47,6 +55,7 @@ module HTML
|
|
|
47
55
|
# Sets whether or not end tags are included for each Header object in
|
|
48
56
|
# the final HTML output. The default is true. Only true or false are
|
|
49
57
|
# valid arguments.
|
|
58
|
+
#
|
|
50
59
|
def self.end_tags=(bool)
|
|
51
60
|
expect(bool,[TrueClass,FalseClass])
|
|
52
61
|
@end_tags = bool
|