html-table 1.2.2

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 ADDED
@@ -0,0 +1,72 @@
1
+ == 1.2.2 - 17-Jun-2005
2
+ * Each class now defines its own content= method (rather than a generic module
3
+ method that handles it). Internal change only.
4
+ * The Head, Foot and Body classes now use the inherited version of content=
5
+ method, instead of defining them individually (which they should have
6
+ been doing all along).
7
+ * Made the README and CHANGES file rdoc friendly.
8
+ * Removed the .rd and html files under the 'doc' directory. All of those
9
+ files have been made rdoc friendly and been given .rdoc extensions.
10
+ * Some $LOAD_PATH setup changes for the test suite.
11
+
12
+ == 1.2.1 - 26-Oct-2004
13
+ * Documentation additions to make the code rdoc friendly.
14
+ * Minor typo/bug fix in the background method of the AttributeHandler module.
15
+ * Added an assertion to the test suite, mostly to make tc_all.rb work
16
+ correctly (one test was causing other tests to fail due to a global
17
+ setting that was made in a previous test).
18
+
19
+ == 1.2.0 - 8-Aug-2004
20
+ * Added the global_end_tags= class method for the Table class. This allows
21
+ you to configure you want end tags or not for all classes, rather than
22
+ having to configure each class individually. Note that classes which
23
+ require end tags are unaffected.
24
+ * Added handling for '<<' for those classes where it was appropriate (i.e.
25
+ any class that also used 'push').
26
+ * Minor update in the Table::Row#unshift method.
27
+ * Modified the border= method in the AttributeHandler module to accept true
28
+ or false as arguments. I had forgotten that you could specify 'border' as
29
+ an attribute without a value.
30
+ * Yet more tests.
31
+
32
+ == 1.1.0 - 6-Aug-2004
33
+ * Modified the constructors for all of the classes that can contain content
34
+ to accept an optional argument. If present it is assumed to be content.
35
+ * Fixed a bug/feature in Table::Row where it didn't allow you to add or
36
+ delete Fixnums. Henceforth, Fixnum's are stringified.
37
+ * The Table::ColGroup class no longer has the content or content= methods.
38
+ This was illegal in 1.0.0 as well but it now raises a NoMethodError instead.
39
+ * Added many more tests, including tests for attribute handlers and html
40
+ handlers.
41
+ * Made the modify_html method in the HtmlHandler module private. This should
42
+ have no affect on your code.
43
+ * Added another simple sample program under doc/examples.
44
+ * Documentation updates.
45
+
46
+ == 1.0.0 - 23-May-2004
47
+ * No API changes - same as 0.0.4 but now officially declared "stable". The
48
+ only change that was made is that each class is now in its own file.
49
+
50
+ == 0.0.4 - 16-May-2004 (Beta4)
51
+ * Prerequisites now include Ruby 1.8.0 or later and the StrongTyping package from
52
+ Ryan Pavlik.
53
+ * More stringent type checking added using the StrongTyping package.
54
+ * Bug in Table::Foot class corrected.
55
+ * Minor name change for included modules (AttributeHandler, HtmlHandler).
56
+ * Many more tests added
57
+
58
+ == 0.0.3 - 9-Jul-2003 (Beta3)
59
+ * Added html_case() class method for those who want their HTML tags in upper
60
+ case
61
+ * Fixed up the docs, added the html docs to the core distro
62
+ * Added some config info to table.rb so that this package works as expected
63
+ after installation
64
+
65
+ == 0.0.2 - 5-Jul-2003 (Beta2)
66
+ * API completely rewritten
67
+ * End tags and indentation level now configurable
68
+ * Added all remaining tag types (caption, colgroup, col, tbody, tfoot and
69
+ thead)
70
+
71
+ == 0.0.1 11-Jun-2003 (Beta1)
72
+ * Initial Release
@@ -0,0 +1,41 @@
1
+ MANIFEST
2
+ CHANGES
3
+ README
4
+ install.rb
5
+
6
+ doc/attributes.rdoc
7
+ doc/table_body.rdoc
8
+ doc/table_caption.rdoc
9
+ doc/table_colgroup.rdoc
10
+ doc/table_colgroup_col.rdoc
11
+ doc/table_foot.rdoc
12
+ doc/table_head.rdoc
13
+ doc/table_row_data.rdoc
14
+ doc/table_row_header.rdoc
15
+ doc/table_row.rdoc
16
+ doc/table.rdoc
17
+
18
+ doc/examples/advanced.rb
19
+ doc/examples/intermediate1.rb
20
+ doc/examples/intermediate2.rb
21
+ doc/examples/simple1.rb
22
+ doc/examples/simple2.rb
23
+ doc/examples/simple3.rb
24
+
25
+ lib/html/attribute_handler.rb
26
+ lib/html/html_handler.rb
27
+ lib/html/table.rb
28
+
29
+ test/ts_all.rb
30
+ test/tc_attribute_handler.rb
31
+ test/tc_body.rb
32
+ test/tc_caption.rb
33
+ test/tc_col.rb
34
+ test/tc_colgroup.rb
35
+ test/tc_data.rb
36
+ test/tc_head.rb
37
+ test/tc_header.rb
38
+ test/tc_html_handler.rb
39
+ test/tc_row.rb
40
+ test/tc_table.rb
41
+ test/tc_tablesection.rb
data/README ADDED
@@ -0,0 +1,137 @@
1
+ == Description
2
+ An interface for generating HTML Tables with Ruby.
3
+
4
+ == Prerequisites
5
+ * Ruby 1.8.0 or later
6
+ * StrongTyping 2.0.6b or later
7
+
8
+ == Installation
9
+ === Manual Installation
10
+ ruby test/ts_all.rb (optional)
11
+ ruby install.rb
12
+ === Gem Installation, Local
13
+ ruby test/ts_all.rb (optional)
14
+ ruby html-table.gemspec
15
+ gem install html-table-<version>.gem
16
+ === Gem Installation, Remote
17
+ gem install html-table
18
+
19
+ == Synopsis
20
+ require "html/table"
21
+ include HTML
22
+
23
+ table = HTML::Table.new{ |t|
24
+ t.border = 1
25
+ t.bgcolor = "red"
26
+ }
27
+
28
+ table.push Table::Row.new{ |r|
29
+ r.align = "left"
30
+ r.bgcolor = "green"
31
+ r.content = ["foo","bar","baz"]
32
+ }
33
+
34
+ row = Table::Row.new{ |r|
35
+ r.align = "right"
36
+ r.bgcolor = "blue"
37
+ r.content = "hello world"
38
+ }
39
+
40
+ table[1] = row
41
+
42
+ puts table.html
43
+
44
+ # Output
45
+ <table border=1 bgcolor='red'>
46
+ <tr align='left' bgcolor='green'> # row 0
47
+ <td>foo</td> # column 0
48
+ <td>bar</td> # column 1
49
+ <td>baz</td> # column 2
50
+ </tr>
51
+ <tr align='right' bgcolor='blue'> # row 1
52
+ <td>hello world</td> # column 0
53
+ </tr>
54
+ </table>
55
+
56
+ See the 'examples' directory under 'doc' for more examples.
57
+
58
+ == Mixins
59
+ Table is a subclass of Array, and therefore mixes in Enumerable. The
60
+ push, unshift and []= methods have been modified. See below for details.
61
+
62
+ Table also mixes in Attribute_Handler which provides methods for adding
63
+ attributes to each of the tag types. See attributes.rd2 for more details.
64
+
65
+ == Notes
66
+ A Table consists of Table::Row, Table::Caption, Table::ColGroup,
67
+ Table::Body, Table::Foot, Table::Head and Table::Row objects.
68
+
69
+ Table::Row objects in turn consist of Table::Row::Data and
70
+ Table::Row::Header objects.
71
+
72
+ Table::ColGroup objects consist of Table::ColGroup::Col
73
+ objects.
74
+
75
+ Table::Head, Table::Body and Table::Foot objects consist
76
+ of Table::Row objects.
77
+
78
+ String attributes are quoted. Numeric attributes are not.
79
+
80
+ Some attributes have type checking. Some check for valid arguments. In
81
+ the latter case, it is case-insensitive. See the documentation on
82
+ specific methods for more details.
83
+
84
+ Using a non-standard extension (e.g. "background") will send a warning to
85
+ STDERR in $VERBOSE (-w) mode.
86
+
87
+ == Known Bugs
88
+ None that I'm aware of. Please report bugs on the project page at
89
+ http://ruby-miscutils.sf.net.
90
+
91
+ == Future Plans
92
+ Documentation improvements (include inline links to other files).
93
+
94
+ Allow standard html tags to be added to elements as appropriate, such
95
+ as <B>, <I>, etc.
96
+
97
+ == Acknowledgements
98
+ Anthony Peacock, for giving me ideas with his HTML::Table Perl module.
99
+
100
+ Holden Glova and Culley Harrelson for API suggestions and comments.
101
+
102
+ == License
103
+ Ruby's
104
+
105
+ == Copyright
106
+ (C) 2003, 2004 Daniel J. Berger
107
+ All Rights Reserved
108
+
109
+ == Warranty
110
+ This package is provided "as is" and without any express or
111
+ implied warranties, including, without limitation, the implied
112
+ warranties of merchantability and fitness for a particular purpose.
113
+
114
+ == Author
115
+ Daniel J. Berger
116
+ djberg96 at gmail dot com
117
+ imperator on IRC (irc.freenode.net)
118
+
119
+ == Developer's Notes
120
+ Some people might be a little annoyed with the fact that I required Ryan
121
+ Pavlik's strongtyping package. I'm not a big fan of strong typing myself. So,
122
+ why did I do this?
123
+
124
+ Normally when creating code, you setup your own rules as far as what is allowed
125
+ as an argument. You publish the API, set up a good set of tests, and don't
126
+ bother worrying about types because you figure people can read the API and
127
+ won't go out of their way to break it. You certainly don't worry about it
128
+ yourself because you're used to dynamic languages and find that you don't need
129
+ the strong typing training wheels after all (right?).
130
+
131
+ However, HTML tables have a predefined set of rules as far as what content is
132
+ valid, and where it's placed in order to be HTML 4.0 compliant. For example,
133
+ if a caption is included, it should be at the 'top' of your table syntax, you
134
+ can only have one foot section, and so on. So, I chose to enforce these
135
+ conventions and/or rules in Ruby via Ryan's module. I could have lived
136
+ without it, and instead chose to do a plethora of "kind_of?" checks. However,
137
+ Ryan's package is both faster and required less typing on my part.
@@ -0,0 +1,143 @@
1
+ == Description
2
+ A list of attributes handled by html-table. Each of the writers has a
3
+ corresponding reader unless otherwise stated.
4
+
5
+ == Attributes
6
+ abbr=(string)
7
+ Sets the value for the abbr attribute.
8
+
9
+ align=(string)
10
+ Sets the align attribute. Valid arguments are 'left', 'center' and
11
+ 'right'. An ArgumentError is raised if an invalid argument is passed.
12
+
13
+ axis=(string)
14
+ Sets the value for the axis attribute.
15
+
16
+ background=(url)
17
+ Sets the background attribute. The url must be a String or a TypeError
18
+ is raised. This is a non-standard extension.
19
+
20
+ bgcolor=(color)
21
+ Sets the color for the bgcolor attribute. Hex values should still be
22
+ quoted, e.g. "#F80000".
23
+
24
+ border=(num)
25
+ Sets the value for the border attribute.
26
+
27
+ bordercolor=(color)
28
+ Sets the color for the bordercolor attribute. This is a non-standard
29
+ extension.
30
+
31
+ bordercolordark=(color)
32
+ Sets the color for the bordercolordark attribute. This is a non-standard
33
+ extension.
34
+
35
+ bordercolorlight=(color)
36
+ Sets the color for the bordercolorlight attribute. This is a non-standard
37
+ extension.
38
+
39
+ cellpadding=(num)
40
+ Sets the value for the cellpadding attribute. Raises an ArgumentError if
41
+ num.to_i is less than 0.
42
+
43
+ cellspacing=(num)
44
+ Sets the value for the cellspacing attribute. Raises an ArgumentError if
45
+ num.to_i is less than 0.
46
+
47
+ char=(character)
48
+ Sets the value for the char attribute. An ArgumentError is raised if the
49
+ argument passed has a length greater than 1 (i.e. it may only be a char).
50
+
51
+ charoff=(value)
52
+ Sets the value for the charoff attribute.
53
+
54
+ colspan=(num)
55
+ Sets the colspan attribute.
56
+
57
+ content=(*args)
58
+ The behavior of this method varies largely based on the type of instance
59
+ that invokes it. Here are the rules for each +arg+ in +args+:
60
+
61
+ +Table+:
62
+
63
+ If +arg+ is a Row, Head, Foot, Body or ColGroup object, it is
64
+ pushed onto the table. If +arg+ is a string, one Row object with
65
+ one one Data object is pushed onto the Table. If +arg+ is an Array,
66
+ one Row object is created and each element of the array is pushed
67
+ onto that Row.
68
+
69
+ +Table::Row+:
70
+
71
+ If +arg+ is a Header or Data object, it is pushed onto the Row. If
72
+ +arg+ is a String, it is created as a single Data object. Attempts
73
+ to assign any other type will raise a TypeError.
74
+
75
+ +Table::Head, Table::Foot, Table::Body+:
76
+
77
+ Behave identically to Table::Row except that they accept Table::Row
78
+ objects as well.
79
+
80
+ +Table::ColGroup+:
81
+
82
+ Behaves identically to Table::Row except that it only accepts Col objects.
83
+
84
+ +Table::Col+:
85
+
86
+ This method is undefined for Table::Col, because they do not accept
87
+ content.
88
+
89
+ +Table::Data and Table::Header+:
90
+
91
+ Sets the text string for the Data or Header object. Arrays are join'd.
92
+ Any other type raises a TypeError.
93
+
94
+ frame=(type)
95
+ Sets the value for the frame attribute. Valid values are border, void,
96
+ above, below, hsides, lhs, rhs, vsides, and box. An ArgumentError is
97
+ raised if an invalid type is detected.
98
+
99
+ height=(num)
100
+ Sets the value for the height attribute. Raises an ArgumentError if
101
+ num.to_i is less than 0.
102
+
103
+ hspace=(num)
104
+ Sets the value for the hspace attribute. Raises an ArgumentError if
105
+ num.to_i is less than 0.
106
+
107
+ nowrap=(bool)
108
+ Sets the value for the nowrap attribute. Setting it to true means it will
109
+ be included as an attribute for the Table object. The default is false
110
+ (i.e. not included).
111
+
112
+ rowspan=(num)
113
+ Sets the value for the rowspan attribute.
114
+
115
+ rules=(edges)
116
+ Sets the value for the rules attribute. Valid values are all, groups,
117
+ rows, cols, or none. An ArgumentError is raised if an invalid edges value
118
+ is detected.
119
+
120
+ scope=(scope)
121
+ Sets the value for the scope attribute. Valid values for +scope+ are
122
+ row, col, rowgroup or colgroup. An ArgumentError is raised if an invalid
123
+ scope value is passed.
124
+
125
+ span=(num)
126
+ Sets the span attribute. If num.to_i is less than 0, and ArgumentError
127
+ is raised.
128
+
129
+ summary=(string)
130
+ Sets the value for the summary attribute.
131
+
132
+ valign=(position)
133
+ Sets the value for the valign attribute. Valid values are top, center,
134
+ bottom, and baseline. This is a non-standard extension.
135
+
136
+ vspace=(num)
137
+ Sets the value for the vspace attribute. This is a non-standard
138
+ extension.
139
+
140
+ width=(num)
141
+ Sets the value for the width attribute. If num is in 'x%' format, it
142
+ is retained as a string. If num is a Fixnum (or stringified number), an
143
+ ArgumentError is raised if num.to_i is less than 0.
@@ -0,0 +1,157 @@
1
+ == Description
2
+ An interface for generating HTML Tables with Ruby.
3
+
4
+ == Synopsis
5
+ require "html/table"
6
+ include HTML
7
+
8
+ table = HTML::Table.new{ |t|
9
+ t.border = 1
10
+ t.bgcolor = "red"
11
+ }
12
+
13
+ table.push Table::Row.new{ |r|
14
+ r.align = "left"
15
+ r.bgcolor = "green"
16
+ r.content = ["foo","bar","baz"]
17
+ }
18
+
19
+ row = Table::Row.new{ |r|
20
+ r.align = "right"
21
+ r.bgcolor = "blue"
22
+ r.content = "hello world"
23
+ }
24
+
25
+ table[1] = row
26
+
27
+ puts table.html
28
+
29
+ #### output ####
30
+ <table border=1 bgcolor='red'>
31
+ <tr align='left' bgcolor='green'> # row 0
32
+ <td>foo</td> # column 0
33
+ <td>bar</td> # column 1
34
+ <td>baz</td> # column 2
35
+ </tr>
36
+ <tr align='right' bgcolor='blue'> # row 1
37
+ <td>hello world</td> # column 0
38
+ </tr>
39
+ </table>
40
+
41
+ See the 'examples' directory for more examples.
42
+
43
+ == Mixins
44
+ Table is a sublcass of Array, and therefore mixes in Enumerable. The
45
+ push, unshift and []= methods have been modified. See below for details.
46
+
47
+ Table also mixes in Attribute_Handler which provides methods for adding
48
+ attributes to each of the tag types. See attributes.rdoc for more details.
49
+
50
+ == Constants
51
+ VERSION
52
+ The current version number (a String). This serves as the VERSION number
53
+ for the entire html-table package.
54
+
55
+ == Class Methods
56
+ Table.new(arg=nil)
57
+ Table.new(arg=nil){ |t| ... }
58
+ Creates a new Table instance. You can set attributes for the Table by
59
+ passing a block.
60
+
61
+ If +arg+ is supplied, it is automatically interpreted to be content. This
62
+ is a shortcut for Table.new{ |t| t.content = '...' }.
63
+
64
+ Table.global_end_tags?
65
+ Returns the value of the global_end_tags class variable. By default,
66
+ this is true.
67
+
68
+ Table.global_end_tags=(true|false)
69
+ Sets the global_end_tags class variable. This determines class-wide, for
70
+ those classes where end tags are optional, whether or not end tags are
71
+ included in the final html. Classes where end tags are not optional are
72
+ not affected.
73
+
74
+ If set to false, this overrides individual class end tags settings.
75
+
76
+ == Instance Methods
77
+ Table#[]=(index, object)
78
+ Assigns +object+ to +index+. There are restrictions to the data
79
+ types that you can assign to a Table instance. They include Caption,
80
+ ColGroup, Body, Foot, Head and Row. You cannot assign a slice (yet).
81
+
82
+ Table#configure(row_num, col_num=0){ |td_object| block }
83
+ Configures column +col_num+ at row +row_num+, using a block to set
84
+ options. If only +row_num+ is specified, then you'll be configuring
85
+ only the row. Generally speaking, that means you'll be configure a
86
+ Table::Row and not a Data or Header object.
87
+
88
+ Table#content
89
+ Returns the HTML content.
90
+
91
+ Table#content=(arg)
92
+ Adds data to the Table. The +arg+ may be a Table::Row object, an
93
+ Array of Table::Row objects, an Array of Array's, an Array of Strings,
94
+ or a single String. In the last two cases, a single Table::Row with a
95
+ single Table::Row::Data object is created, with the string as the content.
96
+
97
+ Table#html
98
+ Returns the entire HTML content for the Table Object. This is what you
99
+ want to print when you're done creating your Table.
100
+
101
+ Table#push(obj)
102
+ Pushes +obj+ onto the Table, where +obj+ must be a Row, Caption,
103
+ ColGroup, Body, Foot or Head object. Also note that the Caption and Head
104
+ objects will automatically put themselves at row 0 (or possibly 1, in the
105
+ case of a Head object where a Caption already exists).
106
+
107
+ Table#unshift(obj)
108
+ Unshifts +obj+ onto the Table. The same rules apply to unshift as
109
+ they do to push.
110
+
111
+ == Notes
112
+ A Table consists of Table::Row, Table::Caption, Table::ColGroup,
113
+ Table::Body, Table::Foot, Table::Head and Table::Row objects. Table::Row
114
+ objects in turn consist of Table::Row::Data and Table::Row::Header
115
+ objects. Table::ColGroup objects consist of Table::ColGroup::Col
116
+ objects. Table::Head, Table::Body and Table::Foot objects consist
117
+ of Table::Row objects.
118
+
119
+ String attributes are quoted. Numeric attributes are not.
120
+
121
+ Some attributes have type checking. Some check for valid arguments. In
122
+ the latter case, it is case-insensitive. See the documentation on
123
+ specific methods for more details.
124
+
125
+ Using a non-standard extension (e.g. "background") will send a warning to
126
+ STDERR in $VERBOSE (-w) mode.
127
+
128
+ == Known Bugs
129
+ None that I'm aware of. Please report bugs on the project page at
130
+ http://www.rubyforge.org/projects/shards.
131
+
132
+ == Future Plans
133
+ Allow standard html tags to be added to elements as appropriate, such
134
+ as <B>, <I>, etc.
135
+
136
+ CSS support.
137
+
138
+ == Acknowledgements
139
+ Anthony Peacock, for giving me ideas with his HTML::Table Perl module.
140
+ Holden Glova and Culley Harrelson for API suggestions and comments.
141
+
142
+ == License
143
+ Ruby's
144
+
145
+ == Copyright
146
+ (C) 2003-2005 Daniel J. Berger
147
+ All Rights Reserved
148
+
149
+ == Warranty
150
+ This package is provided "as is" and without any express or
151
+ implied warranties, including, without limitation, the implied
152
+ warranties of merchantability and fitness for a particular purpose.
153
+
154
+ == Author
155
+ Daniel J. Berger
156
+ djberg96 at yahoo dot com
157
+ imperator on IRC (irc.freenode.net)