html-table 1.3.2 → 1.3.3

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 CHANGED
@@ -1,3 +1,16 @@
1
+ == 1.3.3 - 5-Feb-2009
2
+ * Added structured_warnings as a requirement. The non standard tags now
3
+ raise a NonStandardExtensionWarning. These are now _always_ raised whenever
4
+ used (instead of only in $VERBOSE mode), but the warning can be disabled as
5
+ you see fit. See the documentation on structured_warnings for more details.
6
+ * Added test-unit 2.x as a requirement.
7
+ * Refactored and renamed the tests.
8
+ * The gem now includes the example files.
9
+ * Added additional rake tasks for the sake of testing individual portions
10
+ of the html-table library instead of the all or nothing approach I had
11
+ before.
12
+ * Added rake tasks for running the example programs.
13
+
1
14
  == 1.3.2 - 15-Jul-2008
2
15
  * Added to_s and to_str aliases for the html method for all classes.
3
16
  * Some documentation updates.
data/MANIFEST CHANGED
@@ -41,16 +41,16 @@ lib/html/table.rb
41
41
  lib/html/tablesection.rb
42
42
  lib/html/tag_handler.rb
43
43
 
44
- test/tc_attribute_handler.rb
45
- test/tc_body.rb
46
- test/tc_caption.rb
47
- test/tc_col.rb
48
- test/tc_colgroup.rb
49
- test/tc_data.rb
50
- test/tc_head.rb
51
- test/tc_header.rb
52
- test/tc_html_handler.rb
53
- test/tc_row.rb
54
- test/tc_table.rb
55
- test/tc_tablesection.rb
56
- test/tc_tag_handler.rb
44
+ test/test_attribute_handler.rb
45
+ test/test_body.rb
46
+ test/test_caption.rb
47
+ test/test_col.rb
48
+ test/test_colgroup.rb
49
+ test/test_data.rb
50
+ test/test_head.rb
51
+ test/test_header.rb
52
+ test/test_html_handler.rb
53
+ test/test_row.rb
54
+ test/test_table.rb
55
+ test/test_tablesection.rb
56
+ test/test_tag_handler.rb
data/README CHANGED
@@ -3,14 +3,17 @@
3
3
 
4
4
  == Prerequisites
5
5
  * Ruby 1.8.0 or later
6
- * StrongTyping 2.0.6b or later
6
+ * strongtyping 2.0.6 or later
7
+ * structured_warnings 0.1.1 or later
7
8
 
8
9
  == Installation
10
+ === Remote
11
+ gem install html-table
12
+
13
+ === Local
9
14
  rake test (optional)
10
15
  rake install OR rake gem_install
11
16
 
12
- Just do 'gem install html-table' for remote installation.
13
-
14
17
  == Synopsis
15
18
  require 'html/table'
16
19
  include HTML
@@ -83,8 +86,9 @@
83
86
  the latter case, it is case-insensitive. See the documentation on
84
87
  specific methods for more details.
85
88
 
86
- Using a non-standard extension (e.g. "background") will send a warning to
87
- STDERR in $VERBOSE (-w) mode.
89
+ Using a non-standard extension (e.g. "background") will emit a
90
+ NonStandardExtensionWarning. See the documentation for structured_warnings
91
+ for more information on how to control these.
88
92
 
89
93
  == Known Bugs
90
94
  None that I'm aware of. Please report bugs on the project page at
@@ -93,9 +97,6 @@
93
97
  == Future Plans
94
98
  Documentation improvements (include inline links to other files).
95
99
 
96
- Allow standard html tags to be added to elements as appropriate, such
97
- as <B>, <I>, etc.
98
-
99
100
  == Acknowledgements
100
101
  Anthony Peacock, for giving me ideas with his HTML::Table Perl module.
101
102
 
@@ -105,7 +106,7 @@
105
106
  Ruby's
106
107
 
107
108
  == Copyright
108
- (C) 2003-2008 Daniel J. Berger
109
+ (C) 2003-2009 Daniel J. Berger
109
110
  All Rights Reserved
110
111
 
111
112
  == Warranty
@@ -120,20 +121,20 @@
120
121
 
121
122
  == Developer's Notes
122
123
  Some people might be a little annoyed with the fact that I required Ryan
123
- Pavlik's strongtyping library. I'm not a big fan of strong typing myself. So,
124
- why did I do this?
125
-
126
- Normally when creating code, you setup your own rules as far as what is allowed
127
- as an argument. You publish the API, set up a good set of tests, and don't
128
- bother worrying about types because you figure people can read the API and
129
- won't go out of their way to break it. You certainly don't worry about it
130
- yourself because you're used to dynamic languages and find that you don't need
131
- the strong typing training wheels after all (right?).
132
-
133
- However, HTML tables have a predefined set of rules as far as what content is
134
- valid, and where it's placed in order to be HTML 4.0 compliant. For example,
135
- if a caption is included, it should be at the 'top' of your table syntax, you
136
- can only have one foot section, and so on. So, I chose to enforce these
137
- conventions and/or rules in Ruby via Ryan's module. I could have lived
138
- without it, and instead chose to do a plethora of "kind_of?" checks. However,
139
- Ryan's package is both faster and required less typing on my part.
124
+ Pavlik's strongtyping library. I'm not a big fan of strong typing myself.
125
+ So, why did I do this?
126
+
127
+ Normally when creating code, you setup your own rules as far as what is
128
+ allowed as an argument. You publish the API, set up a good set of tests,
129
+ and don't bother worrying about types because you figure people can read
130
+ the API and won't go out of their way to break it. You certainly don't
131
+ worry about it yourself because you're used to dynamic languages and find
132
+ that you don't need the strong typing training wheels after all, right?
133
+
134
+ However, HTML tables have a predefined set of rules as far as what content
135
+ is valid, and where it's placed in order to be HTML 4.0 compliant. For
136
+ example, if a caption is included, it should be at the 'top' of your table
137
+ syntax, you can only have one foot section, and so on. I therefore chose to
138
+ enforce these conventions and rules in Ruby via Ryan's module. I could have
139
+ lived without it, and instead chose to do a plethora of "kind_of?" checks.
140
+ However, Ryan's package is both faster and required less typing on my part.
data/Rakefile CHANGED
@@ -17,8 +17,126 @@ task :install_gem do
17
17
  sh "gem install #{file}"
18
18
  end
19
19
 
20
+
21
+ namespace 'example' do
22
+ desc "Run the first simple html-table example"
23
+ task :simple1 do
24
+ sh 'ruby -Ilib examples/simple1.rb'
25
+ end
26
+
27
+ desc "Run the second simple html-table example"
28
+ task :simple2 do
29
+ sh 'ruby -Ilib examples/simple2.rb'
30
+ end
31
+
32
+ desc "Run the third simple html-table example"
33
+ task :simple3 do
34
+ sh 'ruby -Ilib examples/simple3.rb'
35
+ end
36
+
37
+ desc "Run the first intermediate html-table example"
38
+ task :intermediate1 do
39
+ sh 'ruby -Ilib examples/intermediate1.rb'
40
+ end
41
+
42
+ desc "Run the second intermediate html-table example"
43
+ task :intermediate2 do
44
+ sh 'ruby -Ilib examples/intermediate2.rb'
45
+ end
46
+
47
+ desc "Run the advanced html-table example"
48
+ task :advanced do
49
+ sh 'ruby -Ilib examples/advanced.rb'
50
+ end
51
+ end
52
+
20
53
  Rake::TestTask.new do |t|
21
- t.libs << 'lib'
22
54
  t.warning = true
23
- t.test_files = FileList['test/tc*']
55
+ t.verbose = true
56
+ end
57
+
58
+ namespace 'test' do
59
+ Rake::TestTask.new('attribute_handler') do |t|
60
+ t.warning = true
61
+ t.verbose = true
62
+ t.test_files = FileList['test/test_attribute_handler.rb']
63
+ end
64
+
65
+ Rake::TestTask.new('body') do |t|
66
+ t.warning = true
67
+ t.verbose = true
68
+ t.test_files = FileList['test/test_body.rb']
69
+ end
70
+
71
+ Rake::TestTask.new('caption') do |t|
72
+ t.warning = true
73
+ t.verbose = true
74
+ t.test_files = FileList['test/test_caption.rb']
75
+ end
76
+
77
+ Rake::TestTask.new('col') do |t|
78
+ t.warning = true
79
+ t.verbose = true
80
+ t.test_files = FileList['test/test_col.rb']
81
+ end
82
+
83
+ Rake::TestTask.new('colgroup') do |t|
84
+ t.warning = true
85
+ t.verbose = true
86
+ t.test_files = FileList['test/test_colgroup.rb']
87
+ end
88
+
89
+ Rake::TestTask.new('data') do |t|
90
+ t.warning = true
91
+ t.verbose = true
92
+ t.test_files = FileList['test/test_data.rb']
93
+ end
94
+
95
+ Rake::TestTask.new('foot') do |t|
96
+ t.warning = true
97
+ t.verbose = true
98
+ t.test_files = FileList['test/test_foot.rb']
99
+ end
100
+
101
+ Rake::TestTask.new('head') do |t|
102
+ t.warning = true
103
+ t.verbose = true
104
+ t.test_files = FileList['test/test_head.rb']
105
+ end
106
+
107
+ Rake::TestTask.new('header') do |t|
108
+ t.warning = true
109
+ t.verbose = true
110
+ t.test_files = FileList['test/test_header.rb']
111
+ end
112
+
113
+ Rake::TestTask.new('html_handler') do |t|
114
+ t.warning = true
115
+ t.verbose = true
116
+ t.test_files = FileList['test/test_html_handler.rb']
117
+ end
118
+
119
+ Rake::TestTask.new('row') do |t|
120
+ t.warning = true
121
+ t.verbose = true
122
+ t.test_files = FileList['test/test_row.rb']
123
+ end
124
+
125
+ Rake::TestTask.new('table') do |t|
126
+ t.warning = true
127
+ t.verbose = true
128
+ t.test_files = FileList['test/test_table.rb']
129
+ end
130
+
131
+ Rake::TestTask.new('tablesection') do |t|
132
+ t.warning = true
133
+ t.verbose = true
134
+ t.test_files = FileList['test/test_tablesection.rb']
135
+ end
136
+
137
+ Rake::TestTask.new('tag_handler') do |t|
138
+ t.warning = true
139
+ t.verbose = true
140
+ t.test_files = FileList['test/test_tag_handler.rb']
141
+ end
24
142
  end
@@ -0,0 +1,128 @@
1
+ ##############################################################################
2
+ # advanced1.rb
3
+ #
4
+ # For this example we'll use every feature I can think of to come up with
5
+ # the example found in "HTML: The Definitive Guide", pp. 395-396 (O'Reilly
6
+ # & Associates, 3rd ed).
7
+ #
8
+ # You can run this example via the 'example:advanced' rake task.
9
+ ##############################################################################
10
+ require 'html/table'
11
+ include HTML
12
+
13
+ Table::Row::Data.end_tags = false
14
+ Table::Row::Header.end_tags = false
15
+
16
+ # Demonstrates the DSL style syntax
17
+ table = Table.new do
18
+ border 1
19
+ cellspacing 0
20
+ cellpadding 0
21
+ rules 'groups'
22
+ end
23
+
24
+ # Demonstrates the use of setters after object creation
25
+ caption = Table::Caption.new
26
+ caption.align = "bottom"
27
+ caption.content = "Kumquat versus a poked eye, by gender"
28
+
29
+ thead = Table::Head.create
30
+ tbody = Table::Body.new
31
+ tfoot = Table::Foot.create
32
+
33
+ # Add a row with a td and th, then configure after the fact.
34
+ thead.push Table::Row.new{ |r|
35
+ r.content = Table::Row::Data.new, Table::Row::Header.new
36
+ }
37
+
38
+ # And again, longhand
39
+ hrow = Table::Row.new
40
+ h1 = Table::Row::Header.new('Eating Kumquats')
41
+ h2 = Table::Row::Header.new('Poke In The Eye')
42
+ hrow.push h1, h2
43
+ thead.push hrow
44
+
45
+ # Configure a row after the fact
46
+ thead.configure(0,0){ |d|
47
+ d.colspan = 2
48
+ d.rowspan = 2
49
+ }
50
+
51
+ thead.configure(0,1){ |h|
52
+ h.colspan = 2
53
+ h.align = "center"
54
+ h.content = "Preference"
55
+ }
56
+
57
+ # Ugly, but just to show you that it's possible
58
+ tbody.push(
59
+ Table::Row.new{ |r|
60
+ r.align = "center"
61
+ r.content =
62
+ Table::Row::Header.new{ |h|
63
+ h.rowspan = 2
64
+ h.content = "Gender"
65
+ },
66
+ Table::Row::Header.new{ |h| h.content = "Male" },
67
+ "73%",
68
+ "27%"
69
+ }
70
+ )
71
+
72
+ brow = Table::Row.new{ |r| r.align = "center" }
73
+ bheader = Table::Row::Header.new('Female')
74
+ brow.push(bheader,"16%","84%")
75
+
76
+ tbody.push(brow)
77
+
78
+ frow = Table::Row.new{ |r|
79
+ r.content = Table::Row::Data.new{ |d|
80
+ d.colspan = 4
81
+ d.align = "center"
82
+ d.content = "Note: eye pokes did not result in permanent injury"
83
+ }
84
+ }
85
+
86
+ tfoot[0] = frow
87
+
88
+ table.push thead, tbody, tfoot
89
+
90
+ # caption is added last, but does the right thing
91
+ table.push caption
92
+
93
+ puts table.html
94
+
95
+ =begin
96
+ ### OUTPUT ###
97
+ <table border=1 cellspacing=0 cellpadding=0 rules='groups'>
98
+ <caption align='bottom'>Kumquat versus a poked eye, by gender</caption>
99
+ <thead>
100
+ <tr>
101
+ <td colspan=2 rowspan=2>
102
+ <th colspan=2 align='center'>Preference
103
+ </tr>
104
+ <tr>
105
+ <th>Eating Kumquats
106
+ <th>Poke In The Eye
107
+ </tr>
108
+ </thead>
109
+ <tbody>
110
+ <tr align='center'>
111
+ <th rowspan=2>Gender
112
+ <th>Male
113
+ <td>73%
114
+ <td>27%
115
+ </tr>
116
+ <tr align='center'>
117
+ <th>Female
118
+ <td>16%
119
+ <td>84%
120
+ </tr>
121
+ </tbody>
122
+ <tfoot>
123
+ <tr>
124
+ <td colspan=4 align='center'>Note: eye pokes did not result in permanent injury
125
+ </tr>
126
+ </tfoot>
127
+ </table>
128
+ =end
@@ -0,0 +1,72 @@
1
+ ##############################################################################
2
+ # intermediate1.rb
3
+ #
4
+ # A slightly more advanced HTML Table. This time we'll add some attributes,
5
+ # add a few rows both implicitly and explicitly, then configure it
6
+ # after-the-fact.
7
+ #
8
+ # You can run this via the "example:intermediate1" rake task.
9
+ ##############################################################################
10
+ require 'html/table'
11
+ include HTML
12
+
13
+ # Create a table, add two rows implicitly
14
+ table = Table.new{ |t|
15
+ t.border = 1
16
+ t.align = "left"
17
+ t.content = [
18
+ ["foo","bar","baz"],
19
+ [1,2]
20
+ ]
21
+ }
22
+
23
+ # Create a Table::Row object with one Data object added implicitly
24
+ row1 = Table::Row.new{ |r|
25
+ r.bgcolor = "red"
26
+ r.nowrap = true
27
+ r.content = "test"
28
+ }
29
+
30
+ # Create a Table::Row object, add a Data object explicitly (with some
31
+ # configuration to boot)
32
+ row2 = Table::Row.new{ |r|
33
+ r.bgcolor = "blue"
34
+ r.align = "right"
35
+ r.content = Table::Row::Data.new{ |d|
36
+ d.content = "hello world!"
37
+ d.abbr = "test abbr"
38
+ }
39
+ }
40
+
41
+ # Add the rows explicitly to the table
42
+ table.push row1, row2
43
+
44
+ # Let's configure the row that contains "foo","bar","baz"
45
+ # Remember, row and column counts start at 0, not 1
46
+ table.configure(0){ |r|
47
+ r.bgcolor = "green"
48
+ r.align = "right"
49
+ }
50
+
51
+ puts table.html
52
+
53
+ =begin
54
+ ### OUTPUT ###
55
+ <table border=1 align='left'>
56
+ <tr bgcolor='green' align='right'>
57
+ <td>foo</td>
58
+ <td>bar</td>
59
+ <td>baz</td>
60
+ </tr>
61
+ <tr>
62
+ <td>1</td>
63
+ <td>2</td>
64
+ </tr>
65
+ <tr bgcolor='red' nowrap>
66
+ <td>test</td>
67
+ </tr>
68
+ <tr bgcolor='blue' align='right'>
69
+ <td abbr='test abbr'>hello world!</td>
70
+ </tr>
71
+ </table>
72
+ =end