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 CHANGED
@@ -1,3 +1,20 @@
1
+ == 1.3.0 - 2-Aug-2006
2
+ * Added support for DSL style syntax, i.e. the ability to omit the explicit
3
+ receiver in block form.
4
+ * The content method now creates a Table::Content object behind the scenes
5
+ (a subclass of String) and allows physical tags to generated on the fly
6
+ via a block.
7
+ * Added support for physical tags for content, e.g. <b>, <i> etc. See the
8
+ documentation for more details.
9
+ * Added the 'style' and 'class_' attribute handlers for you CSS lovers.
10
+ * Added the 'data' alias for the 'content' method.
11
+ * Added the 'header' method to the Table class so that you can explicitly
12
+ generate <th> content instead of <td> content if you prefer.
13
+ * The .html method now accepts an optional boolean that can be used to
14
+ disable formatting. If set to true, the output will not include newlines
15
+ or spaces between the tags (i.e. it will give you a single long string).
16
+ * Some comment additions and tweaks.
17
+
1
18
  == 1.2.2 - 17-Jun-2005
2
19
  * Each class now defines its own content= method (rather than a generic module
3
20
  method that handles it). Internal change only.
data/MANIFEST CHANGED
@@ -6,6 +6,7 @@ install.rb
6
6
  doc/attributes.rdoc
7
7
  doc/table_body.rdoc
8
8
  doc/table_caption.rdoc
9
+ doc/table_content.rdoc
9
10
  doc/table_colgroup.rdoc
10
11
  doc/table_colgroup_col.rdoc
11
12
  doc/table_foot.rdoc
@@ -18,13 +19,26 @@ doc/table.rdoc
18
19
  doc/examples/advanced.rb
19
20
  doc/examples/intermediate1.rb
20
21
  doc/examples/intermediate2.rb
22
+ doc/examples/intermediate3.rb
21
23
  doc/examples/simple1.rb
22
24
  doc/examples/simple2.rb
23
25
  doc/examples/simple3.rb
24
26
 
25
27
  lib/html/attribute_handler.rb
28
+ lib/html/body.rb
29
+ lib/html/caption.rb
30
+ lib/html/col.rb
31
+ lib/html/colgroup.rb
32
+ lib/html/content.rb
33
+ lib/html/data.rb
34
+ lib/html/foot.rb
35
+ lib/html/head.rb
36
+ lib/html/header.rb
26
37
  lib/html/html_handler.rb
38
+ lib/html/row.rb
27
39
  lib/html/table.rb
40
+ lib/html/tablesection.rb
41
+ lib/html/tag_handler.rb
28
42
 
29
43
  test/ts_all.rb
30
44
  test/tc_attribute_handler.rb
@@ -39,3 +53,4 @@ test/tc_html_handler.rb
39
53
  test/tc_row.rb
40
54
  test/tc_table.rb
41
55
  test/tc_tablesection.rb
56
+ test/tc_tag_handler.rb
data/README CHANGED
@@ -20,11 +20,18 @@
20
20
  require "html/table"
21
21
  include HTML
22
22
 
23
+ # Explicit syntax
23
24
  table = HTML::Table.new{ |t|
24
25
  t.border = 1
25
26
  t.bgcolor = "red"
26
27
  }
27
28
 
29
+ # Implicit syntax
30
+ table = HTML::Table.new do
31
+ border 1
32
+ bgcolor 'red'
33
+ end
34
+
28
35
  table.push Table::Row.new{ |r|
29
36
  r.align = "left"
30
37
  r.bgcolor = "green"
@@ -103,7 +110,7 @@
103
110
  Ruby's
104
111
 
105
112
  == Copyright
106
- (C) 2003, 2004 Daniel J. Berger
113
+ (C) 2003-2006 Daniel J. Berger
107
114
  All Rights Reserved
108
115
 
109
116
  == Warranty
@@ -0,0 +1,15 @@
1
+ == Description
2
+ A Table::Content is a wrapper for content used for Table::Row::Data and
3
+ Table::Row::Header objects. Although it can be instantiated directly, in
4
+ practice it is autogenerated for you.
5
+
6
+ == Notes
7
+ Table::Content is a subclass of String and was mostly created in order
8
+ to support a DSL style syntax as well as physical tags.
9
+
10
+ == Synopsis
11
+ content = Table::Content.new('my content') do
12
+ bold true
13
+ italics true
14
+ underline true
15
+ end
@@ -1,17 +1,22 @@
1
1
  # This module creates methods for each of the various attributes associated
2
2
  # with HTML tables. In some cases validation is done on the setters.
3
-
3
+ #--
4
+ # The seemingly redundant writer methods were left here for backwards
5
+ # compatibility and for those who may not prefer the DSL style.
6
+ #
4
7
  module AttributeHandler
5
- def abbr
8
+ def abbr(string = nil)
9
+ self.abbr = string if string
6
10
  @abbr
7
11
  end
8
12
 
9
13
  def abbr=(string)
10
14
  @abbr = string
11
- modify_html("abbr",string)
15
+ modify_html("abbr", string)
12
16
  end
13
17
 
14
- def align
18
+ def align(position = nil)
19
+ self.align = position if position
15
20
  @align
16
21
  end
17
22
 
@@ -19,19 +24,21 @@ module AttributeHandler
19
24
  valid = %w/top bottom left center right/
20
25
  raise ArgumentError unless valid.include?(position.downcase)
21
26
  @align = position
22
- modify_html("align",position)
27
+ modify_html("align", position)
23
28
  end
24
29
 
25
- def axis
30
+ def axis(string = nil)
31
+ self.axis = string if string
26
32
  @axis
27
33
  end
28
34
 
29
35
  def axis=(string)
30
36
  @axis = string
31
- modify_html("axis",string)
37
+ modify_html("axis", string)
32
38
  end
33
39
 
34
- def background
40
+ def background(url = nil)
41
+ self.background = url if url
35
42
  @background
36
43
  end
37
44
 
@@ -42,35 +49,38 @@ module AttributeHandler
42
49
  STDERR.puts msg
43
50
  end
44
51
  @background = url
45
- modify_html("background",url)
52
+ modify_html("background", url)
46
53
  end
47
54
 
48
- def bgcolor
55
+ def bgcolor(color = nil)
56
+ self.bgcolor = color if color
49
57
  @bgcolor
50
58
  end
51
59
 
52
60
  def bgcolor=(color)
53
61
  @bgcolor = color
54
- modify_html("bgcolor",color)
62
+ modify_html("bgcolor", color)
55
63
  end
56
64
 
57
- def border
65
+ def border(num = nil)
66
+ self.border = num if num
58
67
  @border
59
68
  end
60
69
 
61
70
  # Allow either true/false or an integer
62
71
  def border=(num)
63
72
  if num.kind_of?(TrueClass)
64
- modify_html("border",true)
73
+ modify_html("border", true)
65
74
  elsif num.kind_of?(FalseClass)
66
75
  # Do nothing
67
76
  else
68
77
  @border = num.to_i
69
- modify_html("border",num.to_i)
78
+ modify_html("border", num.to_i)
70
79
  end
71
80
  end
72
81
 
73
- def bordercolor
82
+ def bordercolor(color = nil)
83
+ self.bordercolor = color if color
74
84
  @bordercolor
75
85
  end
76
86
 
@@ -80,10 +90,11 @@ module AttributeHandler
80
90
  msg = "'bordercolor' is a non-standard extension"
81
91
  STDERR.puts msg
82
92
  end
83
- modify_html("bordercolor",color)
93
+ modify_html("bordercolor", color)
84
94
  end
85
95
 
86
- def bordercolordark
96
+ def bordercolordark(color = nil)
97
+ self.bordercolordark = color if color
87
98
  @bordercolordark
88
99
  end
89
100
 
@@ -93,10 +104,11 @@ module AttributeHandler
93
104
  msg = "'bordercolordark' is a non-standard extension"
94
105
  STDERR.puts msg
95
106
  end
96
- modify_html("bordercolordark",color)
107
+ modify_html("bordercolordark", color)
97
108
  end
98
109
 
99
- def bordercolorlight
110
+ def bordercolorlight(color = nil)
111
+ self.bordercolorlight = color if color
100
112
  @bordercolorlight
101
113
  end
102
114
 
@@ -106,71 +118,94 @@ module AttributeHandler
106
118
  msg = "'bordercolorlight' is a non-standard extension"
107
119
  STDERR.puts msg
108
120
  end
109
- modify_html("bordercolorlight",@bordercolorlight)
121
+ modify_html("bordercolorlight", @bordercolorlight)
110
122
  end
111
123
 
112
- def cellpadding
124
+ def cellpadding(num = nil)
125
+ self.cellpadding = num if num
113
126
  @cellpadding
114
127
  end
115
128
 
116
129
  def cellpadding=(num)
117
130
  raise ArgumentError if num.to_i < 0
118
131
  @cellpadding = num.to_i
119
- modify_html("cellpadding",@cellpadding)
132
+ modify_html("cellpadding", @cellpadding)
120
133
  end
121
134
 
122
- def cellspacing
135
+ def cellspacing(num = nil)
136
+ self.cellspacing = num if num
123
137
  @cellspacing
124
138
  end
125
139
 
126
140
  def cellspacing=(num)
127
141
  raise ArgumentError if num.to_i < 0
128
142
  @cellspacing = num.to_i
129
- modify_html("cellspacing",@cellspacing)
143
+ modify_html("cellspacing", @cellspacing)
130
144
  end
131
145
 
132
- def char
146
+ def char(character = nil)
147
+ self.char = character if character
133
148
  @char
134
149
  end
135
150
 
136
151
  def char=(character)
137
152
  raise ArgumentError if character.to_s.length > 1
138
153
  @char = character.to_s
139
- modify_html("char",character.to_s)
154
+ modify_html("char", character.to_s)
140
155
  end
141
156
 
142
- def charoff
157
+ def charoff(offset = nil)
158
+ self.charoff = offset if offset
143
159
  @charoff
144
160
  end
145
161
 
146
162
  def charoff=(offset)
147
163
  raise ArgumentError if offset.to_i < 0
148
164
  @charoff = offset
149
- modify_html("charoff",offset)
165
+ modify_html("charoff", offset)
166
+ end
167
+
168
+ # Returns the CSS class. The trailing underscore is necessary in order
169
+ # to avoid conflict with the 'class' keyword.
170
+ #
171
+ def class_(klass = nil)
172
+ self.class_ = klass if klass
173
+ @class
174
+ end
175
+
176
+ # Returns the CSS class. The trailing underscore is necessary in order
177
+ # to avoid conflict with the 'class' keyword.
178
+ #
179
+ def class_=(klass)
180
+ modify_html('class', klass)
181
+ @class = klass
150
182
  end
151
183
 
152
- def col
184
+ def col(num = nil)
185
+ self.col = num if num
153
186
  @col
154
187
  end
155
188
 
156
189
  def col=(num)
157
190
  raise ArgumentError if num.to_i < 0
158
191
  @col = num.to_i
159
- modify_html("col",@col)
192
+ modify_html("col", @col)
160
193
  end
161
194
 
162
- def colspan
195
+ def colspan(span = nil)
196
+ self.colspan = span if span
163
197
  @colspan
164
198
  end
165
199
 
166
200
  def colspan=(span)
167
201
  raise ArgumentError if span.to_i < 0
168
202
  @colspan = span.to_i
169
- modify_html("colspan",@colspan)
203
+ modify_html("colspan", @colspan)
170
204
  end
171
205
 
172
206
  # Allows you to configure various attributes by row or row + column.
173
- def configure(row,col=nil,&block)
207
+ #
208
+ def configure(row, col=nil, &block)
174
209
  if col
175
210
  begin
176
211
  yield self[row][col]
@@ -183,12 +218,32 @@ module AttributeHandler
183
218
  end
184
219
  end
185
220
 
186
- # Returns the HTML content (i.e. text)
187
- def content
221
+ # Returns the HTML content (i.e. text).
222
+ #
223
+ def content(arg = nil, &block)
224
+ case arg
225
+ when String
226
+ self.content = Table::Content.new(arg, &block)
227
+ when Array
228
+ arg.each{ |e|
229
+ if e.kind_of?(Array)
230
+ row = Table::Row.new
231
+ e.each{ |element| row.push(Table::Content.new(element, &block)) }
232
+ self.push(row)
233
+ else
234
+ self.content = Table::Content.new(e, &block)
235
+ end
236
+ }
237
+ else
238
+ self.content = arg if arg
239
+ end
188
240
  @html_body
189
241
  end
190
242
 
191
- def frame
243
+ alias data content
244
+
245
+ def frame(type = nil)
246
+ self.frame = type if type
192
247
  @frame
193
248
  end
194
249
 
@@ -196,30 +251,33 @@ module AttributeHandler
196
251
  valid = %w/border void above below hsides lhs rhs vsides box/
197
252
  raise ArgumentError unless valid.include?(type.downcase)
198
253
  @frame = type
199
- modify_html("frame",@frame)
254
+ modify_html("frame", @frame)
200
255
  end
201
256
 
202
- def height
257
+ def height(num = nil)
258
+ self.height = num if num
203
259
  @height
204
260
  end
205
261
 
206
262
  def height=(num)
207
263
  raise ArgumentError if num.to_i < 0
208
264
  @height = num.to_i
209
- modify_html("height",@height)
265
+ modify_html("height", @height)
210
266
  end
211
267
 
212
- def hspace
268
+ def hspace(num = nil)
269
+ self.hspace = num if num
213
270
  @hspace
214
271
  end
215
272
 
216
273
  def hspace=(num)
217
274
  raise ArgumentError if num.to_i < 0
218
275
  @hspace = num.to_i
219
- modify_html("hspace",@hspace)
276
+ modify_html("hspace", @hspace)
220
277
  end
221
278
 
222
- def nowrap
279
+ def nowrap(bool = nil)
280
+ self.nowrap = bool if bool
223
281
  @nowrap
224
282
  end
225
283
 
@@ -228,20 +286,22 @@ module AttributeHandler
228
286
  raise TypeError
229
287
  end
230
288
  @nowrap = bool
231
- modify_html("nowrap",@nowrap)
289
+ modify_html("nowrap", @nowrap)
232
290
  end
233
291
 
234
- def rowspan
292
+ def rowspan(num = nil)
293
+ self.rowspan = num if num
235
294
  @rowspan
236
295
  end
237
296
 
238
297
  def rowspan=(num)
239
298
  raise ArgumentError if num.to_i < 0
240
299
  @rowspan = num.to_i
241
- modify_html("rowspan",@rowspan)
300
+ modify_html("rowspan", @rowspan)
242
301
  end
243
302
 
244
- def rules
303
+ def rules(edges = nil)
304
+ self.rules = edges if edges
245
305
  @rules
246
306
  end
247
307
 
@@ -249,29 +309,42 @@ module AttributeHandler
249
309
  valid = %w/all groups rows cols none/
250
310
  raise ArgumentError unless valid.include?(edges.to_s.downcase)
251
311
  @rules = edges
252
- modify_html("rules",@rules)
312
+ modify_html("rules", @rules)
253
313
  end
254
314
 
255
- def span
315
+ def span(num = nil)
316
+ self.span = num if num
256
317
  @span
257
318
  end
258
319
 
259
320
  def span=(num)
260
321
  raise ArgumentError if num.to_i < 0
261
322
  @span = num.to_i
262
- modify_html("span",@span)
323
+ modify_html("span", @span)
324
+ end
325
+
326
+ def style(string = nil)
327
+ self.style = string if string
328
+ @style
263
329
  end
264
330
 
265
- def summary
331
+ def style=(string)
332
+ @style = string.to_s
333
+ modify_html("style", @style)
334
+ end
335
+
336
+ def summary(string = nil)
337
+ self.summary = string if string
266
338
  @summary
267
339
  end
268
340
 
269
341
  def summary=(string)
270
342
  @summary = string.to_s
271
- modify_html("summary",@summary)
343
+ modify_html("summary", @summary)
272
344
  end
273
345
 
274
- def valign
346
+ def valign(position = nil)
347
+ self.valign = position if position
275
348
  @valign
276
349
  end
277
350
 
@@ -279,20 +352,22 @@ module AttributeHandler
279
352
  valid = %w/top center bottom baseline/
280
353
  raise ArgumentError unless valid.include?(position.to_s.downcase)
281
354
  @valign = position
282
- modify_html("valign",@valign)
355
+ modify_html("valign", @valign)
356
+ end
357
+
358
+ def vspace(num = nil)
359
+ self.vspace = num if num
360
+ @vspace
283
361
  end
284
362
 
285
363
  def vspace=(num)
286
364
  raise ArgumentError if num.to_i < 0
287
365
  @vspace = num.to_i
288
- modify_html("vspace",@vspace)
289
- end
290
-
291
- def vspace
292
- @vspace
366
+ modify_html("vspace", @vspace)
293
367
  end
294
368
 
295
- def width
369
+ def width(num = nil)
370
+ self.width = num if num
296
371
  @width
297
372
  end
298
373
 
@@ -303,6 +378,6 @@ module AttributeHandler
303
378
  raise ArgumentError if num.to_i < 0
304
379
  @width = num.to_i
305
380
  end
306
- modify_html("width",@width)
381
+ modify_html("width", @width)
307
382
  end
308
383
  end