html-table 1.5.2 → 1.7.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/{CHANGES → CHANGES.rdoc} +22 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE +177 -0
  7. data/MANIFEST.rdoc +57 -0
  8. data/README.rdoc +132 -0
  9. data/Rakefile +117 -146
  10. data/doc/table.rdoc +2 -4
  11. data/html-table.gemspec +6 -7
  12. data/lib/html/caption.rb +2 -2
  13. data/lib/html/col.rb +2 -2
  14. data/lib/html/colgroup.rb +4 -4
  15. data/lib/html/content.rb +2 -2
  16. data/lib/html/data.rb +2 -2
  17. data/lib/html/header.rb +2 -2
  18. data/lib/html/mixin/attribute_handler.rb +407 -0
  19. data/lib/html/mixin/html_handler.rb +124 -0
  20. data/lib/html/mixin/strongtyping.rb +17 -0
  21. data/lib/html/mixin/tag_handler.rb +125 -0
  22. data/lib/html/row.rb +2 -2
  23. data/lib/html/table.rb +7 -7
  24. data/lib/html/tablesection.rb +2 -2
  25. data/spec/attribute_handler_spec.rb +360 -0
  26. data/spec/body_spec.rb +81 -0
  27. data/spec/caption_spec.rb +74 -0
  28. data/spec/colgroup_col_spec.rb +34 -0
  29. data/spec/colgroup_spec.rb +83 -0
  30. data/spec/data_spec.rb +72 -0
  31. data/spec/foot_spec.rb +104 -0
  32. data/spec/head_spec.rb +101 -0
  33. data/spec/header_spec.rb +72 -0
  34. data/spec/html_handler_spec.rb +32 -0
  35. data/spec/row_spec.rb +136 -0
  36. data/spec/table_spec.rb +152 -0
  37. data/spec/tablesection_spec.rb +36 -0
  38. data/spec/tag_handler_spec.rb +85 -0
  39. metadata +55 -66
  40. metadata.gz.sig +0 -0
  41. data/MANIFEST +0 -59
  42. data/README +0 -132
  43. data/lib/html/attribute_handler.rb +0 -403
  44. data/lib/html/html_handler.rb +0 -120
  45. data/lib/html/tag_handler.rb +0 -121
  46. data/test/test_attribute_handler.rb +0 -361
  47. data/test/test_body.rb +0 -87
  48. data/test/test_caption.rb +0 -80
  49. data/test/test_col.rb +0 -40
  50. data/test/test_colgroup.rb +0 -89
  51. data/test/test_data.rb +0 -77
  52. data/test/test_foot.rb +0 -111
  53. data/test/test_head.rb +0 -104
  54. data/test/test_header.rb +0 -77
  55. data/test/test_html_handler.rb +0 -37
  56. data/test/test_row.rb +0 -141
  57. data/test/test_table.rb +0 -159
  58. data/test/test_tablesection.rb +0 -42
  59. data/test/test_tag_handler.rb +0 -90
@@ -1,403 +0,0 @@
1
- # This module creates methods for each of the various attributes associated
2
- # with HTML tables. In some cases validation is done on the setters.
3
- #--
4
- # The seemingly redundant writer methods were left here for backwards
5
- # compatibility and for those who may not prefer the DSI.
6
- #
7
- module AttributeHandler
8
- def abbr(string = nil)
9
- @abbr ||= nil
10
- self.abbr = string if string
11
- @abbr
12
- end
13
-
14
- def abbr=(string)
15
- @abbr = string
16
- modify_html("abbr", string)
17
- end
18
-
19
- def align(position = nil)
20
- @align ||= nil
21
- self.align = position if position
22
- @align
23
- end
24
-
25
- def align=(position)
26
- valid = %w/top bottom left center right/
27
- raise ArgumentError unless valid.include?(position.downcase)
28
- @align = position
29
- modify_html("align", position)
30
- end
31
-
32
- def axis(string = nil)
33
- @axis ||= nil
34
- self.axis = string if string
35
- @axis
36
- end
37
-
38
- def axis=(string)
39
- @axis = string
40
- modify_html("axis", string)
41
- end
42
-
43
- def background(url = nil)
44
- @background ||= nil
45
- self.background = url if url
46
- @background
47
- end
48
-
49
- def background=(url)
50
- raise TypeError unless url.kind_of?(String)
51
- msg = "'background' is a non-standard extension"
52
- warn NonStandardExtensionWarning, msg
53
- @background = url
54
- modify_html("background", url)
55
- end
56
-
57
- def bgcolor(color = nil)
58
- @bgcolor ||= nil
59
- self.bgcolor = color if color
60
- @bgcolor
61
- end
62
-
63
- def bgcolor=(color)
64
- @bgcolor = color
65
- modify_html("bgcolor", color)
66
- end
67
-
68
- def border(num = nil)
69
- @border ||= nil
70
- self.border = num if num
71
- @border
72
- end
73
-
74
- # Allow either true/false or an integer
75
- def border=(num)
76
- if num.kind_of?(TrueClass)
77
- modify_html("border", true)
78
- elsif num.kind_of?(FalseClass)
79
- # Do nothing
80
- else
81
- @border = num.to_i
82
- modify_html("border", num.to_i)
83
- end
84
- end
85
-
86
- def bordercolor(color = nil)
87
- @bordercolor ||= nil
88
- self.bordercolor = color if color
89
- @bordercolor
90
- end
91
-
92
- def bordercolor=(color)
93
- @bordercolor = color
94
- msg = "'bordercolor' is a non-standard extension"
95
- warn NonStandardExtensionWarning, msg
96
- modify_html("bordercolor", color)
97
- end
98
-
99
- def bordercolordark(color = nil)
100
- @bordercolordark ||= nil
101
- self.bordercolordark = color if color
102
- @bordercolordark
103
- end
104
-
105
- def bordercolordark=(color)
106
- @bordercolordark = color
107
- msg = "'bordercolordark' is a non-standard extension"
108
- warn NonStandardExtensionWarning, msg
109
- modify_html("bordercolordark", color)
110
- end
111
-
112
- def bordercolorlight(color = nil)
113
- @bordercolorlight ||= nil
114
- self.bordercolorlight = color if color
115
- @bordercolorlight
116
- end
117
-
118
- def bordercolorlight=(color)
119
- @bordercolorlight = color
120
- msg = "'bordercolorlight' is a non-standard extension"
121
- warn NonStandardExtensionWarning, msg
122
- modify_html("bordercolorlight", @bordercolorlight)
123
- end
124
-
125
- def cellpadding(num = nil)
126
- @cellpadding ||= nil
127
- self.cellpadding = num if num
128
- @cellpadding
129
- end
130
-
131
- def cellpadding=(num)
132
- raise ArgumentError if num.to_i < 0
133
- @cellpadding = num.to_i
134
- modify_html("cellpadding", @cellpadding)
135
- end
136
-
137
- def cellspacing(num = nil)
138
- @cellspacing ||= nil
139
- self.cellspacing = num if num
140
- @cellspacing
141
- end
142
-
143
- def cellspacing=(num)
144
- raise ArgumentError if num.to_i < 0
145
- @cellspacing = num.to_i
146
- modify_html("cellspacing", @cellspacing)
147
- end
148
-
149
- def char(character = nil)
150
- @char ||= nil
151
- self.char = character if character
152
- @char
153
- end
154
-
155
- def char=(character)
156
- raise ArgumentError if character.to_s.length > 1
157
- @char = character.to_s
158
- modify_html("char", character.to_s)
159
- end
160
-
161
- def charoff(offset = nil)
162
- @charoff ||= nil
163
- self.charoff = offset if offset
164
- @charoff
165
- end
166
-
167
- def charoff=(offset)
168
- raise ArgumentError if offset.to_i < 0
169
- @charoff = offset
170
- modify_html("charoff", offset)
171
- end
172
-
173
- # Returns the CSS class. The trailing underscore is necessary in order
174
- # to avoid conflict with the 'class' keyword.
175
- #
176
- def class_(klass = nil)
177
- @class ||= nil
178
- self.class_ = klass if klass
179
- @class
180
- end
181
-
182
- # Returns the CSS class. The trailing underscore is necessary in order
183
- # to avoid conflict with the 'class' keyword.
184
- #
185
- def class_=(klass)
186
- modify_html('class', klass)
187
- @class = klass
188
- end
189
-
190
- def col(num = nil)
191
- @col ||= nil
192
- self.col = num if num
193
- @col
194
- end
195
-
196
- def col=(num)
197
- raise ArgumentError if num.to_i < 0
198
- @col = num.to_i
199
- modify_html("col", @col)
200
- end
201
-
202
- def colspan(span = nil)
203
- @colspan ||= nil
204
- self.colspan = span if span
205
- @colspan
206
- end
207
-
208
- def colspan=(span)
209
- raise ArgumentError if span.to_i < 0
210
- @colspan = span.to_i
211
- modify_html("colspan", @colspan)
212
- end
213
-
214
- # Allows you to configure various attributes by row or row + column.
215
- #
216
- def configure(row, col=nil, &block)
217
- if col
218
- begin
219
- yield self[row][col]
220
- rescue NameError
221
- msg = "No column to configure in a " + self.class.to_s + " class"
222
- raise ArgumentError, msg
223
- end
224
- else
225
- yield self[row]
226
- end
227
- end
228
-
229
- # Returns the HTML content (i.e. text).
230
- #
231
- def content(arg = nil, &block)
232
- case arg
233
- when String
234
- self.content = Table::Content.new(arg, &block)
235
- when Array
236
- arg.each{ |e|
237
- if e.kind_of?(Array)
238
- row = Table::Row.new
239
- e.each{ |element| row.push(Table::Content.new(element, &block)) }
240
- self.push(row)
241
- else
242
- self.content = Table::Content.new(e, &block)
243
- end
244
- }
245
- else
246
- self.content = arg if arg
247
- end
248
- @html_body
249
- end
250
-
251
- alias data content
252
-
253
- def frame(type = nil)
254
- @frame ||= nil
255
- self.frame = type if type
256
- @frame
257
- end
258
-
259
- def frame=(type)
260
- valid = %w/border void above below hsides lhs rhs vsides box/
261
- raise ArgumentError unless valid.include?(type.downcase)
262
- @frame = type
263
- modify_html("frame", @frame)
264
- end
265
-
266
- def height(num = nil)
267
- @height ||= nil
268
- self.height = num if num
269
- @height
270
- end
271
-
272
- def height=(num)
273
- raise ArgumentError if num.to_i < 0
274
- @height = num.to_i
275
- modify_html("height", @height)
276
- end
277
-
278
- def hspace(num = nil)
279
- @hspace ||= nil
280
- self.hspace = num if num
281
- @hspace
282
- end
283
-
284
- def hspace=(num)
285
- raise ArgumentError if num.to_i < 0
286
- @hspace = num.to_i
287
- modify_html("hspace", @hspace)
288
- end
289
-
290
- def nowrap(bool = nil)
291
- @nowrap ||= nil
292
- self.nowrap = bool if bool
293
- @nowrap
294
- end
295
-
296
- def nowrap=(bool)
297
- unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
298
- raise TypeError
299
- end
300
- @nowrap = bool
301
- modify_html("nowrap", @nowrap)
302
- end
303
-
304
- def rowspan(num = nil)
305
- @rowspan ||= nil
306
- self.rowspan = num if num
307
- @rowspan
308
- end
309
-
310
- def rowspan=(num)
311
- raise ArgumentError if num.to_i < 0
312
- @rowspan = num.to_i
313
- modify_html("rowspan", @rowspan)
314
- end
315
-
316
- def rules(edges = nil)
317
- @rules ||= nil
318
- self.rules = edges if edges
319
- @rules
320
- end
321
-
322
- def rules=(edges)
323
- valid = %w/all groups rows cols none/
324
- raise ArgumentError unless valid.include?(edges.to_s.downcase)
325
- @rules = edges
326
- modify_html("rules", @rules)
327
- end
328
-
329
- def span(num = nil)
330
- @span ||= nil
331
- self.span = num if num
332
- @span
333
- end
334
-
335
- def span=(num)
336
- raise ArgumentError if num.to_i < 0
337
- @span = num.to_i
338
- modify_html("span", @span)
339
- end
340
-
341
- def style(string = nil)
342
- @style ||= nil
343
- self.style = string if string
344
- @style
345
- end
346
-
347
- def style=(string)
348
- @style = string.to_s
349
- modify_html("style", @style)
350
- end
351
-
352
- def summary(string = nil)
353
- @summary ||= nil
354
- self.summary = string if string
355
- @summary
356
- end
357
-
358
- def summary=(string)
359
- @summary = string.to_s
360
- modify_html("summary", @summary)
361
- end
362
-
363
- def valign(position = nil)
364
- @valign ||= nil
365
- self.valign = position if position
366
- @valign
367
- end
368
-
369
- def valign=(position)
370
- valid = %w/top center bottom baseline/
371
- raise ArgumentError unless valid.include?(position.to_s.downcase)
372
- @valign = position
373
- modify_html("valign", @valign)
374
- end
375
-
376
- def vspace(num = nil)
377
- @vspace ||= nil
378
- self.vspace = num if num
379
- @vspace
380
- end
381
-
382
- def vspace=(num)
383
- raise ArgumentError if num.to_i < 0
384
- @vspace = num.to_i
385
- modify_html("vspace", @vspace)
386
- end
387
-
388
- def width(num = nil)
389
- @width ||= nil
390
- self.width = num if num
391
- @width
392
- end
393
-
394
- def width=(num)
395
- if num =~ /%/
396
- @width = num
397
- else
398
- raise ArgumentError if num.to_i < 0
399
- @width = num.to_i
400
- end
401
- modify_html("width", @width)
402
- end
403
- end
@@ -1,120 +0,0 @@
1
- module HtmlHandler
2
-
3
- $upper = false
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?(Integer)
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?(Integer)
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
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
49
-
50
- if formatting && self.class.respond_to?(:indent_level)
51
- ilevel = self.class.indent_level
52
- end
53
-
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
61
- else
62
- html << self.map{ |e| e.html(formatting).to_s }.join
63
- end
64
- else
65
- html << @html_body
66
- end
67
-
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
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
100
- end
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
118
-
119
- private :modify_html
120
- end