html-table 1.3.5 → 1.3.6
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 +3 -0
- data/html-table.gemspec +19 -19
- data/lib/html/body.rb +31 -32
- data/lib/html/caption.rb +42 -41
- data/lib/html/content.rb +7 -7
- data/lib/html/data.rb +57 -56
- data/lib/html/header.rb +54 -54
- data/lib/html/html_handler.rb +105 -105
- data/lib/html/table.rb +1 -1
- data/lib/html/tag_handler.rb +113 -113
- data/test/test_caption.rb +66 -66
- data/test/test_table.rb +1 -1
- metadata +5 -5
data/CHANGES
CHANGED
data/html-table.gemspec
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
gem.name = 'html-table'
|
5
|
+
gem.version = '1.3.6'
|
6
|
+
gem.author = 'Daniel J. Berger'
|
7
|
+
gem.license = 'Artistic 2.0'
|
8
|
+
gem.email = 'djberg96@gmail.com'
|
9
|
+
gem.homepage = 'http://shards.rubyforge.org'
|
10
|
+
gem.summary = 'A Ruby interface for generating HTML tables'
|
11
|
+
gem.test_files = Dir['test/*.rb']
|
12
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
gem.rubyforge_project = 'shards'
|
15
|
+
gem.extra_rdoc_files = ['README', 'CHANGES'] + Dir['doc/*.rdoc']
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
gem.add_dependency('strongtyping')
|
18
|
+
gem.add_dependency('structured_warnings')
|
19
19
|
|
20
|
-
|
20
|
+
gem.add_development_dependency('test-unit')
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
gem.description = <<-EOF
|
23
|
+
The html-table library provides an interface for generating HTML tables
|
24
|
+
in a syntax comfortable to Ruby programmers, but with some enforcement
|
25
|
+
of where certain elements can be placed.
|
26
|
+
EOF
|
27
27
|
end
|
data/lib/html/body.rb
CHANGED
@@ -1,38 +1,37 @@
|
|
1
1
|
module HTML
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# This class represents an HTML table body (<tbody>). It is a
|
4
|
+
# subclass of Table::TableSection.
|
5
|
+
#
|
6
|
+
class Table::Body < Table::TableSection
|
7
|
+
@indent_level = 3
|
8
|
+
@end_tags = true
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
# Returns a new Table::Body object. Optionally takes a block. If
|
11
|
+
# an argument is provided, it is treated as content.
|
12
|
+
#
|
13
|
+
def initialize(arg = nil, &block)
|
14
|
+
@html_begin = "<tbody"
|
15
|
+
@html_end = "</tbody>"
|
16
|
+
instance_eval(&block) if block_given?
|
17
|
+
self.content = arg if arg
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
# Returns a boolean indicating whether or not end tags, </tbody>, are
|
21
|
+
# included for each Body object in the final HTML output. The
|
22
|
+
# default is true.
|
23
|
+
#
|
24
|
+
def self.end_tags?
|
25
|
+
@end_tags
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
# Sets whether or not end tags are included for each Body object in
|
29
|
+
# the final HTML output. The default is true. Only true or false are
|
30
|
+
# valid arguments.
|
31
|
+
#
|
32
|
+
def self.end_tags=(bool)
|
33
|
+
expect(bool,[TrueClass, FalseClass])
|
34
|
+
@end_tags = bool
|
35
|
+
end
|
36
|
+
end
|
38
37
|
end
|
data/lib/html/caption.rb
CHANGED
@@ -1,48 +1,49 @@
|
|
1
1
|
module HTML
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# This class represents an HTML Caption. Despite the name, it is not
|
4
|
+
# a subclass of Table. Note that end tags for this class are mandatory.
|
5
|
+
#
|
6
|
+
class Table::Caption
|
7
|
+
include AttributeHandler
|
8
|
+
include HtmlHandler
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
undef_method :configure
|
11
|
+
@indent_level = 3
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# Adds content to the Table::Caption object.
|
25
|
-
#
|
26
|
-
def content=(arg)
|
27
|
-
@html_body = Table::Content.new(arg.to_s)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Returns the number of spaces that tags for this class are indented.
|
31
|
-
# For the Table::Caption class, the indention level defaults to 3.
|
32
|
-
#
|
33
|
-
def self.indent_level
|
34
|
-
@indent_level
|
35
|
-
end
|
13
|
+
# Returns a new Table::Caption object. Optionally takes a block. If
|
14
|
+
# an argument is provided it is treated as content.
|
15
|
+
#
|
16
|
+
def initialize(arg = nil, &block)
|
17
|
+
@html_begin = '<caption'
|
18
|
+
@html_body = ''
|
19
|
+
@html_end = '</caption>'
|
20
|
+
instance_eval(&block) if block_given?
|
21
|
+
self.content = arg if arg
|
22
|
+
end
|
36
23
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
24
|
+
# Adds content to the Table::Caption object.
|
25
|
+
#
|
26
|
+
def content=(arg)
|
27
|
+
arg = arg.is_a?(Array) ? arg.join : arg.to_s
|
28
|
+
@html_body = Table::Content.new(arg)
|
29
|
+
end
|
44
30
|
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
# Returns the number of spaces that tags for this class are indented.
|
32
|
+
# For the Table::Caption class, the indention level defaults to 3.
|
33
|
+
#
|
34
|
+
def self.indent_level
|
35
|
+
@indent_level
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sets the number of spaces that tags for this class are indented.
|
39
|
+
#
|
40
|
+
def self.indent_level=(num)
|
41
|
+
expect(num,Integer)
|
42
|
+
raise ArgumentError, "indent level must be >= 0" if num < 0
|
43
|
+
@indent_level = num
|
44
|
+
end
|
45
|
+
|
46
|
+
alias to_s html
|
47
|
+
alias to_str html
|
48
|
+
end
|
48
49
|
end
|
data/lib/html/content.rb
CHANGED
@@ -7,12 +7,12 @@
|
|
7
7
|
require File.join(File.dirname(__FILE__), 'tag_handler')
|
8
8
|
|
9
9
|
module HTML
|
10
|
-
|
11
|
-
|
10
|
+
class Table::Content < String
|
11
|
+
include TagHandler
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def initialize(string, &block)
|
14
|
+
super(string)
|
15
|
+
instance_eval(&block) if block_given?
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
data/lib/html/data.rb
CHANGED
@@ -1,68 +1,69 @@
|
|
1
1
|
module HTML
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# This class represents HTML table data, <td>. Despite the name
|
4
|
+
# it is not a subclass of Table::Row or Table.
|
5
|
+
#
|
6
|
+
class Table::Row::Data
|
7
|
+
include AttributeHandler
|
8
|
+
include HtmlHandler
|
9
9
|
|
10
|
-
|
10
|
+
undef_method :configure
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
@indent_level = 6
|
13
|
+
@end_tags = true
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
# Creates and returns a Data object. Optionally takes a block. If
|
16
|
+
# an argument is provided, it is treated as content.
|
17
|
+
#
|
18
|
+
def initialize(arg = nil, &block)
|
19
|
+
@html_begin = '<td'
|
20
|
+
@html_body = ''
|
21
|
+
@html_end = '</td>'
|
22
|
+
instance_eval(&block) if block_given?
|
23
|
+
self.content = arg if arg
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
# Adds content to the Table::Row::Data object.
|
27
|
+
#
|
28
|
+
def content=(arg)
|
29
|
+
arg = arg.is_a?(Array) ? arg.join : arg.to_s
|
30
|
+
@html_body = Table::Content.new(arg)
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
# Returns the indentation level for the tags of this class. The
|
34
|
+
# default is 6.
|
35
|
+
#
|
36
|
+
def self.indent_level
|
37
|
+
@indent_level
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
# Sets the indentation level for the tags of this class. The default
|
41
|
+
# is 6.
|
42
|
+
#
|
43
|
+
def self.indent_level=(num)
|
44
|
+
expect(num, Integer)
|
45
|
+
raise ArgumentError,"indent_level must be >= 0" if num < 0
|
46
|
+
@indent_level = num
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
# Returns a boolean indicating whether or not end tags, </td>, are
|
50
|
+
# included for each Data object in the final HTML output. The
|
51
|
+
# default is true.
|
52
|
+
#
|
53
|
+
def self.end_tags?
|
54
|
+
@end_tags
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
# Sets whether or not end tags are included for each Data object in
|
58
|
+
# the final HTML output. The default is true. Only true or false are
|
59
|
+
# valid arguments.
|
60
|
+
#
|
61
|
+
def self.end_tags=(bool)
|
62
|
+
expect(bool, [TrueClass, FalseClass])
|
63
|
+
@end_tags = bool
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
alias to_s html
|
67
|
+
alias to_str html
|
68
|
+
end
|
68
69
|
end
|
data/lib/html/header.rb
CHANGED
@@ -1,65 +1,65 @@
|
|
1
1
|
module HTML
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# This class represents an HTML table header (<th>). Despite the name
|
4
|
+
# it is not a subclass of Table or Table::Row.
|
5
|
+
#
|
6
|
+
class Table::Row::Header
|
7
|
+
include AttributeHandler
|
8
|
+
include HtmlHandler
|
9
9
|
|
10
|
-
|
10
|
+
undef_method :configure
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
@indent_level = 6
|
13
|
+
@end_tags = true
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# Adds content to the Table::Row::Header object.
|
27
|
-
#
|
28
|
-
def content=(arg)
|
29
|
-
@html_body = Table::Content.new(arg.to_s)
|
30
|
-
end
|
15
|
+
# Creates and returns a new Header object. Optionally takes a block.
|
16
|
+
# If an argument is provided, it is treated as content.
|
17
|
+
#
|
18
|
+
def initialize(arg = nil, &block)
|
19
|
+
@html_begin = '<th'
|
20
|
+
@html_body = ''
|
21
|
+
@html_end = '</th>'
|
22
|
+
instance_eval(&block) if block_given?
|
23
|
+
self.content = arg if arg
|
24
|
+
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
# Adds content to the Table::Row::Header object.
|
27
|
+
#
|
28
|
+
def content=(arg)
|
29
|
+
arg = arg.is_a?(Array) ? arg.join : arg.to_s
|
30
|
+
@html_body = Table::Content.new(arg)
|
31
|
+
end
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@indent_level = num
|
46
|
-
end
|
33
|
+
# Returns the indentation level for the tags of this class. The
|
34
|
+
# default is 6.
|
35
|
+
#
|
36
|
+
def self.indent_level
|
37
|
+
@indent_level
|
38
|
+
end
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
# Sets the indentation level for the tags of this class. The default
|
41
|
+
# is 6.
|
42
|
+
#
|
43
|
+
def self.indent_level=(num)
|
44
|
+
expect(num,Integer)
|
45
|
+
raise ArgumentError,"indent_level must be >= 0" if num < 0
|
46
|
+
@indent_level = num
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@end_tags = bool
|
62
|
-
end
|
63
|
-
end
|
49
|
+
# Returns a boolean indicating whether or not end tags are included for
|
50
|
+
# each Header object in the final HTML output. The default is true.
|
51
|
+
#
|
52
|
+
def self.end_tags?
|
53
|
+
@end_tags
|
54
|
+
end
|
64
55
|
|
56
|
+
# Sets whether or not end tags are included for each Header object in
|
57
|
+
# the final HTML output. The default is true. Only true or false are
|
58
|
+
# valid arguments.
|
59
|
+
#
|
60
|
+
def self.end_tags=(bool)
|
61
|
+
expect(bool,[TrueClass,FalseClass])
|
62
|
+
@end_tags = bool
|
63
|
+
end
|
64
|
+
end
|
65
65
|
end
|
data/lib/html/html_handler.rb
CHANGED
@@ -1,120 +1,120 @@
|
|
1
1
|
module HtmlHandler
|
2
2
|
|
3
|
-
|
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?(Fixnum)
|
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?(Fixnum)
|
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
|
3
|
+
$upper = false
|
30
4
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@html_end.upcase!
|
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?(Fixnum)
|
14
|
+
@html_begin << " #{attribute}=#{arg}"
|
15
|
+
elsif arg.kind_of?(TrueClass)
|
16
|
+
@html_begin << " #{attribute}"
|
17
|
+
else
|
18
|
+
@html_begin << " #{attribute}='#{arg}'"
|
46
19
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
20
|
+
else
|
21
|
+
if arg.kind_of?(Fixnum)
|
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}'")
|
52
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
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
if formatting && self.class.respond_to?(:indent_level)
|
51
|
+
ilevel = self.class.indent_level
|
52
|
+
end
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
64
61
|
else
|
65
|
-
|
62
|
+
html << self.map{ |e| e.html(formatting).to_s }.join
|
66
63
|
end
|
64
|
+
else
|
65
|
+
html << @html_body
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
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
|
100
82
|
end
|
101
|
-
|
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
|
102
93
|
else
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
unless self.class.respond_to?(:end_tags?)
|
111
|
-
html << @html_end
|
112
|
-
end
|
113
|
-
end
|
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
|
114
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
|
115
118
|
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
private :modify_html
|
119
|
+
private :modify_html
|
120
120
|
end
|
data/lib/html/table.rb
CHANGED
data/lib/html/tag_handler.rb
CHANGED
@@ -2,120 +2,120 @@
|
|
2
2
|
# tag_handler.rb
|
3
3
|
#
|
4
4
|
# Module for handling standard html physical tags (<b>, <i>, etc).
|
5
|
-
# Only used for Table::Content objects, which are in turn used by
|
5
|
+
# Only used for Table::Content objects, which are in turn used by
|
6
6
|
# Table::Row::Data, Table::Row::Header and Table::Caption.
|
7
7
|
###################################################################
|
8
8
|
module TagHandler
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
9
|
+
def bold(bool = nil)
|
10
|
+
@bold ||= nil
|
11
|
+
self.bold = bool if bool
|
12
|
+
@bold
|
13
|
+
end
|
14
|
+
|
15
|
+
def bold=(bool)
|
16
|
+
handle_physical_tag('b', bool)
|
17
|
+
@bold = bool
|
18
|
+
end
|
19
|
+
|
20
|
+
def big(bool = nil)
|
21
|
+
@big ||= nil
|
22
|
+
self.big = bool if bool
|
23
|
+
@big
|
24
|
+
end
|
25
|
+
|
26
|
+
def big=(bool)
|
27
|
+
handle_physical_tag('big', bool)
|
28
|
+
@big = bool
|
29
|
+
end
|
30
|
+
|
31
|
+
def blink(bool = nil)
|
32
|
+
@blink ||= nil
|
33
|
+
self.blink = bool if bool
|
34
|
+
@blink
|
35
|
+
end
|
36
|
+
|
37
|
+
def blink=(bool)
|
38
|
+
warn BlinkWarning, "The 'blink' tag is very annoying. Please reconsider."
|
39
|
+
handle_physical_tag('blink', bool)
|
40
|
+
@blink = bool
|
41
|
+
end
|
42
|
+
|
43
|
+
def italic(bool = nil)
|
44
|
+
@italic ||= nil
|
45
|
+
self.italic = bool if bool
|
46
|
+
@italic
|
47
|
+
end
|
48
|
+
|
49
|
+
def italic=(bool)
|
50
|
+
handle_physical_tag('i', bool)
|
51
|
+
@italic = bool
|
52
|
+
end
|
53
|
+
|
54
|
+
def strike(bool = nil)
|
55
|
+
@strike ||= nil
|
56
|
+
self.strike = bool if bool
|
57
|
+
@strike
|
58
|
+
end
|
59
|
+
|
60
|
+
def strike=(bool)
|
61
|
+
handle_physical_tag('strike', bool)
|
62
|
+
@strike = bool
|
63
|
+
end
|
64
|
+
|
65
|
+
def sub(bool = nil)
|
66
|
+
@sub ||= nil
|
67
|
+
self.sub = bool if bool
|
68
|
+
@sub
|
69
|
+
end
|
70
|
+
|
71
|
+
def sub=(bool)
|
72
|
+
handle_physical_tag('sub', bool)
|
73
|
+
@sub = bool
|
74
|
+
end
|
75
|
+
|
76
|
+
def sup(bool = nil)
|
77
|
+
@sup ||= nil
|
78
|
+
self.sup = bool if bool
|
79
|
+
@sup
|
80
|
+
end
|
81
|
+
|
82
|
+
def sup=(bool)
|
83
|
+
handle_physical_tag('sup', bool)
|
84
|
+
@sup = bool
|
85
|
+
end
|
86
|
+
|
87
|
+
def tt(bool = nil)
|
88
|
+
@tt ||= nil
|
89
|
+
self.tt = bool if bool
|
90
|
+
@tt
|
91
|
+
end
|
92
|
+
|
93
|
+
def tt=(bool)
|
94
|
+
handle_physical_tag('tt', bool)
|
95
|
+
@tt = bool
|
96
|
+
end
|
97
|
+
|
98
|
+
def underline(bool = nil)
|
99
|
+
@underline ||= nil
|
100
|
+
self.underline = bool if bool
|
101
|
+
@underline
|
102
|
+
end
|
103
|
+
|
104
|
+
def underline=(bool)
|
105
|
+
handle_physical_tag('u', bool)
|
106
|
+
@bool = bool
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def handle_physical_tag(tag, bool)
|
112
|
+
begin_tag = "<#{tag}>"
|
113
|
+
end_tag = "</#{tag}>"
|
114
|
+
|
115
|
+
if bool
|
116
|
+
self.replace(begin_tag << self << end_tag)
|
117
|
+
else
|
118
|
+
self.replace(self.gsub(/#{begin_tag}|#{end_tag}/,''))
|
119
|
+
end
|
120
|
+
end
|
121
121
|
end
|
data/test/test_caption.rb
CHANGED
@@ -11,73 +11,73 @@ require 'html/table'
|
|
11
11
|
include HTML
|
12
12
|
|
13
13
|
class TC_HTML_Table_Caption < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def setup
|
15
|
+
@table = Table.new
|
16
|
+
@tcaption = Table::Caption.new
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def test_basic
|
29
|
-
html = "<caption></caption>"
|
30
|
-
assert_equal(html, @tcaption.html.gsub(/\s+/,''))
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_with_attributes
|
34
|
-
html = "<caption align='left' valign='top'></caption>"
|
35
|
-
@tcaption.align = "left"
|
36
|
-
@tcaption.valign = "top"
|
37
|
-
assert_equal(html, @tcaption.html.gsub(/\s{2,}|\n+/,''))
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_configure_not_allowed
|
41
|
-
assert_raises(NoMethodError){ @tcaption.configure }
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_add_content
|
45
|
-
html = "<caption>hello world</caption>"
|
46
|
-
@tcaption.content = "hello world"
|
47
|
-
assert_equal(html,@tcaption.html.gsub(/\s{2,}/,''))
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_add_multiple_content_items
|
51
|
-
html = "<caption>hello world</caption>"
|
52
|
-
@tcaption.content = "hello"," world"
|
53
|
-
assert_equal(html,@tcaption.html.gsub(/\s{2,}/,''))
|
54
|
-
end
|
19
|
+
def test_constructor
|
20
|
+
assert_nothing_raised{ Table::Caption.new }
|
21
|
+
assert_nothing_raised{ Table::Caption.new("foo") }
|
22
|
+
assert_nothing_raised{ Table::Caption.new(1) }
|
23
|
+
assert_nothing_raised{ Table::Caption.new(%w/foo bar baz/) }
|
24
|
+
assert_nothing_raised{ Table::Caption.new([1,2,3]) }
|
25
|
+
assert_nothing_raised{ Table::Caption.new([[1,2,3],["foo","bar"]]) }
|
26
|
+
end
|
55
27
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
28
|
+
def test_basic
|
29
|
+
html = "<caption></caption>"
|
30
|
+
assert_equal(html, @tcaption.html.gsub(/\s+/,''))
|
31
|
+
end
|
61
32
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
33
|
+
def test_with_attributes
|
34
|
+
html = "<caption align='left' valign='top'></caption>"
|
35
|
+
@tcaption.align = "left"
|
36
|
+
@tcaption.valign = "top"
|
37
|
+
assert_equal(html, @tcaption.html.gsub(/\s{2,}|\n+/,''))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_configure_not_allowed
|
41
|
+
assert_raises(NoMethodError){ @tcaption.configure }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_add_content
|
45
|
+
html = "<caption>hello world</caption>"
|
46
|
+
@tcaption.content = "hello world"
|
47
|
+
assert_equal(html,@tcaption.html.gsub(/\s{2,}/,''))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_multiple_content_items
|
51
|
+
html = "<caption>hello world</caption>"
|
52
|
+
@tcaption.content = "hello"," world"
|
53
|
+
assert_equal(html,@tcaption.html.gsub(/\s{2,}/,''))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add_content_in_constructor
|
57
|
+
html = "<caption>hello world</caption>"
|
58
|
+
@tcaption = Table::Caption.new("hello world")
|
59
|
+
assert_equal(html, @tcaption.html.gsub(/\s{2,}/,''))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_indent_level
|
63
|
+
assert_respond_to(Table::Caption,:indent_level)
|
64
|
+
assert_respond_to(Table::Caption,:indent_level=)
|
65
|
+
assert_raises(ArgumentTypeError){ Table::Caption.indent_level = "foo" }
|
66
|
+
assert_nothing_raised{ Table::Caption.indent_level = 3 }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_only_row_zero_allowed
|
70
|
+
assert_raises(ArgumentError){ @table[1] = @tcaption }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_automatically_set_to_row_zero
|
74
|
+
@table.content = "hello","world"
|
75
|
+
@table.push(@tcaption)
|
76
|
+
assert_equal(true, @table[0].kind_of?(Table::Caption))
|
77
|
+
end
|
78
|
+
|
79
|
+
def teardown
|
80
|
+
@table = nil
|
81
|
+
@tcaption = nil
|
82
|
+
end
|
83
83
|
end
|
data/test/test_table.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 6
|
10
|
+
version: 1.3.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel J. Berger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: strongtyping
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
version: "0"
|
60
60
|
type: :development
|
61
61
|
version_requirements: *id003
|
62
|
-
description: "
|
62
|
+
description: " The html-table library provides an interface for generating HTML tables\n in a syntax comfortable to Ruby programmers, but with some enforcement\n of where certain elements can be placed.\n"
|
63
63
|
email: djberg96@gmail.com
|
64
64
|
executables: []
|
65
65
|
|