html-table 1.7.0 → 1.7.1

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 (66) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/{CHANGES.rdoc → CHANGES.md} +73 -69
  4. data/Gemfile +2 -7
  5. data/{MANIFEST.rdoc → MANIFEST.md} +15 -15
  6. data/{README.rdoc → README.md} +80 -71
  7. data/Rakefile +7 -2
  8. data/doc/attributes.md +160 -0
  9. data/doc/table.md +173 -0
  10. data/doc/table_body.md +9 -0
  11. data/doc/table_caption.md +10 -0
  12. data/doc/table_colgroup.md +8 -0
  13. data/doc/table_colgroup_col.md +7 -0
  14. data/doc/table_content.md +17 -0
  15. data/doc/table_foot.md +8 -0
  16. data/doc/table_head.md +10 -0
  17. data/doc/table_row.md +114 -0
  18. data/doc/table_row_data.md +100 -0
  19. data/doc/table_row_header.md +6 -0
  20. data/examples/simple1.rb +7 -5
  21. data/html-table.gemspec +13 -8
  22. data/lib/html/body.rb +9 -7
  23. data/lib/html/caption.rb +4 -2
  24. data/lib/html/col.rb +37 -34
  25. data/lib/html/colgroup.rb +90 -97
  26. data/lib/html/content.rb +3 -6
  27. data/lib/html/data.rb +3 -1
  28. data/lib/html/foot.rb +53 -45
  29. data/lib/html/head.rb +54 -47
  30. data/lib/html/header.rb +5 -3
  31. data/lib/html/mixin/attribute_handler.rb +57 -53
  32. data/lib/html/mixin/html_handler.rb +33 -35
  33. data/lib/html/mixin/strongtyping.rb +6 -6
  34. data/lib/html/mixin/tag_handler.rb +6 -2
  35. data/lib/html/row.rb +156 -183
  36. data/lib/html/table.rb +45 -45
  37. data/lib/html/tablesection.rb +51 -46
  38. data/spec/attribute_handler_spec.rb +94 -80
  39. data/spec/body_spec.rb +54 -37
  40. data/spec/caption_spec.rb +41 -32
  41. data/spec/colgroup_col_spec.rb +7 -7
  42. data/spec/colgroup_spec.rb +50 -36
  43. data/spec/data_spec.rb +39 -23
  44. data/spec/foot_spec.rb +58 -46
  45. data/spec/head_spec.rb +62 -47
  46. data/spec/header_spec.rb +35 -22
  47. data/spec/html_handler_spec.rb +15 -12
  48. data/spec/row_spec.rb +95 -68
  49. data/spec/table_spec.rb +65 -31
  50. data/spec/tablesection_spec.rb +13 -13
  51. data/spec/tag_handler_spec.rb +13 -13
  52. data.tar.gz.sig +0 -0
  53. metadata +103 -78
  54. metadata.gz.sig +0 -0
  55. data/doc/attributes.rdoc +0 -143
  56. data/doc/table.rdoc +0 -156
  57. data/doc/table_body.rdoc +0 -9
  58. data/doc/table_caption.rdoc +0 -9
  59. data/doc/table_colgroup.rdoc +0 -8
  60. data/doc/table_colgroup_col.rdoc +0 -9
  61. data/doc/table_content.rdoc +0 -15
  62. data/doc/table_foot.rdoc +0 -8
  63. data/doc/table_head.rdoc +0 -11
  64. data/doc/table_row.rdoc +0 -105
  65. data/doc/table_row_data.rdoc +0 -92
  66. data/doc/table_row_header.rdoc +0 -7
data/lib/html/header.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
2
3
 
3
4
  # This class represents an HTML table header (<th>). Despite the name
@@ -6,6 +7,7 @@ module HTML
6
7
  class Table::Row::Header
7
8
  include HTML::Mixin::AttributeHandler
8
9
  include HTML::Mixin::HtmlHandler
10
+ extend HTML::Mixin::StrongTyping
9
11
 
10
12
  undef_method :configure
11
13
 
@@ -41,8 +43,8 @@ module HTML
41
43
  # is 6.
42
44
  #
43
45
  def self.indent_level=(num)
44
- expect(num,Integer)
45
- raise ArgumentError,"indent_level must be >= 0" if num < 0
46
+ expect(num, Integer)
47
+ raise ArgumentError, 'indent_level must be >= 0' if num < 0
46
48
  @indent_level = num
47
49
  end
48
50
 
@@ -58,7 +60,7 @@ module HTML
58
60
  # valid arguments.
59
61
  #
60
62
  def self.end_tags=(bool)
61
- expect(bool,[TrueClass,FalseClass])
63
+ expect(bool, [TrueClass, FalseClass])
62
64
  @end_tags = bool
63
65
  end
64
66
  end
@@ -1,11 +1,14 @@
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
- #--
1
+ ##########################################################################
4
2
  # The seemingly redundant writer methods were left here for backwards
5
3
  # compatibility and for those who may not prefer the DSL.
6
- #
4
+ ##########################################################################
5
+
6
+ # The HTML module serves as a namespace only.
7
7
  module HTML
8
+ # The Mixin module serves as a namespace to prevent collisions.
8
9
  module Mixin
10
+ # The AttributeHandler module creates methods for each of the various attributes
11
+ # associated with HTML tables. In some cases validation is done on the setters.
9
12
  module AttributeHandler
10
13
  def abbr(string = nil)
11
14
  @abbr ||= nil
@@ -15,7 +18,7 @@ module HTML
15
18
 
16
19
  def abbr=(string)
17
20
  @abbr = string
18
- modify_html("abbr", string)
21
+ modify_html('abbr', string)
19
22
  end
20
23
 
21
24
  def align(position = nil)
@@ -25,10 +28,10 @@ module HTML
25
28
  end
26
29
 
27
30
  def align=(position)
28
- valid = %w/top bottom left center right/
31
+ valid = %w[top bottom left center right]
29
32
  raise ArgumentError unless valid.include?(position.downcase)
30
33
  @align = position
31
- modify_html("align", position)
34
+ modify_html('align', position)
32
35
  end
33
36
 
34
37
  def axis(string = nil)
@@ -39,7 +42,7 @@ module HTML
39
42
 
40
43
  def axis=(string)
41
44
  @axis = string
42
- modify_html("axis", string)
45
+ modify_html('axis', string)
43
46
  end
44
47
 
45
48
  def background(url = nil)
@@ -49,11 +52,11 @@ module HTML
49
52
  end
50
53
 
51
54
  def background=(url)
52
- raise TypeError unless url.kind_of?(String)
53
- msg = "'background' is a non-standard extension"
55
+ raise TypeError unless url.is_a?(String)
56
+ msg = "'background' is a non-standard extension"
54
57
  warn NonStandardExtensionWarning, msg
55
58
  @background = url
56
- modify_html("background", url)
59
+ modify_html('background', url)
57
60
  end
58
61
 
59
62
  def bgcolor(color = nil)
@@ -64,7 +67,7 @@ module HTML
64
67
 
65
68
  def bgcolor=(color)
66
69
  @bgcolor = color
67
- modify_html("bgcolor", color)
70
+ modify_html('bgcolor', color)
68
71
  end
69
72
 
70
73
  def border(num = nil)
@@ -75,13 +78,14 @@ module HTML
75
78
 
76
79
  # Allow either true/false or an integer
77
80
  def border=(num)
78
- if num.kind_of?(TrueClass)
79
- modify_html("border", true)
80
- elsif num.kind_of?(FalseClass)
81
- # Do nothing
82
- else
83
- @border = num.to_i
84
- modify_html("border", num.to_i)
81
+ case num
82
+ when TrueClass
83
+ modify_html('border', true)
84
+ when FalseClass
85
+ # Do nothing
86
+ else
87
+ @border = num.to_i
88
+ modify_html('border', num.to_i)
85
89
  end
86
90
  end
87
91
 
@@ -93,9 +97,9 @@ module HTML
93
97
 
94
98
  def bordercolor=(color)
95
99
  @bordercolor = color
96
- msg = "'bordercolor' is a non-standard extension"
100
+ msg = "'bordercolor' is a non-standard extension"
97
101
  warn NonStandardExtensionWarning, msg
98
- modify_html("bordercolor", color)
102
+ modify_html('bordercolor', color)
99
103
  end
100
104
 
101
105
  def bordercolordark(color = nil)
@@ -108,7 +112,7 @@ module HTML
108
112
  @bordercolordark = color
109
113
  msg = "'bordercolordark' is a non-standard extension"
110
114
  warn NonStandardExtensionWarning, msg
111
- modify_html("bordercolordark", color)
115
+ modify_html('bordercolordark', color)
112
116
  end
113
117
 
114
118
  def bordercolorlight(color = nil)
@@ -121,7 +125,7 @@ module HTML
121
125
  @bordercolorlight = color
122
126
  msg = "'bordercolorlight' is a non-standard extension"
123
127
  warn NonStandardExtensionWarning, msg
124
- modify_html("bordercolorlight", @bordercolorlight)
128
+ modify_html('bordercolorlight', @bordercolorlight)
125
129
  end
126
130
 
127
131
  def cellpadding(num = nil)
@@ -133,7 +137,7 @@ module HTML
133
137
  def cellpadding=(num)
134
138
  raise ArgumentError if num.to_i < 0
135
139
  @cellpadding = num.to_i
136
- modify_html("cellpadding", @cellpadding)
140
+ modify_html('cellpadding', @cellpadding)
137
141
  end
138
142
 
139
143
  def cellspacing(num = nil)
@@ -145,7 +149,7 @@ module HTML
145
149
  def cellspacing=(num)
146
150
  raise ArgumentError if num.to_i < 0
147
151
  @cellspacing = num.to_i
148
- modify_html("cellspacing", @cellspacing)
152
+ modify_html('cellspacing', @cellspacing)
149
153
  end
150
154
 
151
155
  def char(character = nil)
@@ -157,7 +161,7 @@ module HTML
157
161
  def char=(character)
158
162
  raise ArgumentError if character.to_s.length > 1
159
163
  @char = character.to_s
160
- modify_html("char", character.to_s)
164
+ modify_html('char', character.to_s)
161
165
  end
162
166
 
163
167
  def charoff(offset = nil)
@@ -169,7 +173,7 @@ module HTML
169
173
  def charoff=(offset)
170
174
  raise ArgumentError if offset.to_i < 0
171
175
  @charoff = offset
172
- modify_html("charoff", offset)
176
+ modify_html('charoff', offset)
173
177
  end
174
178
 
175
179
  # Returns the CSS class. The trailing underscore is necessary in order
@@ -198,7 +202,7 @@ module HTML
198
202
  def col=(num)
199
203
  raise ArgumentError if num.to_i < 0
200
204
  @col = num.to_i
201
- modify_html("col", @col)
205
+ modify_html('col', @col)
202
206
  end
203
207
 
204
208
  def colspan(span = nil)
@@ -210,17 +214,17 @@ module HTML
210
214
  def colspan=(span)
211
215
  raise ArgumentError if span.to_i < 0
212
216
  @colspan = span.to_i
213
- modify_html("colspan", @colspan)
217
+ modify_html('colspan', @colspan)
214
218
  end
215
219
 
216
220
  # Allows you to configure various attributes by row or row + column.
217
221
  #
218
- def configure(row, col=nil, &block)
222
+ def configure(row, col = nil)
219
223
  if col
220
224
  begin
221
225
  yield self[row][col]
222
226
  rescue NameError
223
- msg = "No column to configure in a " + self.class.to_s + " class"
227
+ msg = "No column to configure in a #{self.class} class"
224
228
  raise ArgumentError, msg
225
229
  end
226
230
  else
@@ -235,15 +239,15 @@ module HTML
235
239
  when String
236
240
  self.content = Table::Content.new(arg, &block)
237
241
  when Array
238
- arg.each{ |e|
239
- if e.kind_of?(Array)
242
+ arg.each do |e|
243
+ if e.is_a?(Array)
240
244
  row = Table::Row.new
241
- e.each{ |element| row.push(Table::Content.new(element, &block)) }
242
- self.push(row)
245
+ e.each { |element| row.push(Table::Content.new(element, &block)) }
246
+ push(row)
243
247
  else
244
248
  self.content = Table::Content.new(e, &block)
245
249
  end
246
- }
250
+ end
247
251
  else
248
252
  self.content = arg if arg
249
253
  end
@@ -259,10 +263,10 @@ module HTML
259
263
  end
260
264
 
261
265
  def frame=(type)
262
- valid = %w/border void above below hsides lhs rhs vsides box/
266
+ valid = %w[border void above below hsides lhs rhs vsides box]
263
267
  raise ArgumentError unless valid.include?(type.downcase)
264
268
  @frame = type
265
- modify_html("frame", @frame)
269
+ modify_html('frame', @frame)
266
270
  end
267
271
 
268
272
  def height(num = nil)
@@ -274,7 +278,7 @@ module HTML
274
278
  def height=(num)
275
279
  raise ArgumentError if num.to_i < 0
276
280
  @height = num.to_i
277
- modify_html("height", @height)
281
+ modify_html('height', @height)
278
282
  end
279
283
 
280
284
  def hspace(num = nil)
@@ -286,7 +290,7 @@ module HTML
286
290
  def hspace=(num)
287
291
  raise ArgumentError if num.to_i < 0
288
292
  @hspace = num.to_i
289
- modify_html("hspace", @hspace)
293
+ modify_html('hspace', @hspace)
290
294
  end
291
295
 
292
296
  def nowrap(bool = nil)
@@ -296,11 +300,11 @@ module HTML
296
300
  end
297
301
 
298
302
  def nowrap=(bool)
299
- unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
300
- raise TypeError
303
+ unless bool.is_a?(TrueClass) || bool.is_a?(FalseClass)
304
+ raise TypeError
301
305
  end
302
306
  @nowrap = bool
303
- modify_html("nowrap", @nowrap)
307
+ modify_html('nowrap', @nowrap)
304
308
  end
305
309
 
306
310
  def rowspan(num = nil)
@@ -312,7 +316,7 @@ module HTML
312
316
  def rowspan=(num)
313
317
  raise ArgumentError if num.to_i < 0
314
318
  @rowspan = num.to_i
315
- modify_html("rowspan", @rowspan)
319
+ modify_html('rowspan', @rowspan)
316
320
  end
317
321
 
318
322
  def rules(edges = nil)
@@ -322,10 +326,10 @@ module HTML
322
326
  end
323
327
 
324
328
  def rules=(edges)
325
- valid = %w/all groups rows cols none/
329
+ valid = %w[all groups rows cols none]
326
330
  raise ArgumentError unless valid.include?(edges.to_s.downcase)
327
331
  @rules = edges
328
- modify_html("rules", @rules)
332
+ modify_html('rules', @rules)
329
333
  end
330
334
 
331
335
  def span(num = nil)
@@ -337,7 +341,7 @@ module HTML
337
341
  def span=(num)
338
342
  raise ArgumentError if num.to_i < 0
339
343
  @span = num.to_i
340
- modify_html("span", @span)
344
+ modify_html('span', @span)
341
345
  end
342
346
 
343
347
  def style(string = nil)
@@ -348,7 +352,7 @@ module HTML
348
352
 
349
353
  def style=(string)
350
354
  @style = string.to_s
351
- modify_html("style", @style)
355
+ modify_html('style', @style)
352
356
  end
353
357
 
354
358
  def summary(string = nil)
@@ -359,7 +363,7 @@ module HTML
359
363
 
360
364
  def summary=(string)
361
365
  @summary = string.to_s
362
- modify_html("summary", @summary)
366
+ modify_html('summary', @summary)
363
367
  end
364
368
 
365
369
  def valign(position = nil)
@@ -369,10 +373,10 @@ module HTML
369
373
  end
370
374
 
371
375
  def valign=(position)
372
- valid = %w/top center bottom baseline/
376
+ valid = %w[top center bottom baseline]
373
377
  raise ArgumentError unless valid.include?(position.to_s.downcase)
374
378
  @valign = position
375
- modify_html("valign", @valign)
379
+ modify_html('valign', @valign)
376
380
  end
377
381
 
378
382
  def vspace(num = nil)
@@ -384,7 +388,7 @@ module HTML
384
388
  def vspace=(num)
385
389
  raise ArgumentError if num.to_i < 0
386
390
  @vspace = num.to_i
387
- modify_html("vspace", @vspace)
391
+ modify_html('vspace', @vspace)
388
392
  end
389
393
 
390
394
  def width(num = nil)
@@ -400,7 +404,7 @@ module HTML
400
404
  raise ArgumentError if num.to_i < 0
401
405
  @width = num.to_i
402
406
  end
403
- modify_html("width", @width)
407
+ modify_html('width', @width)
404
408
  end
405
409
  end
406
410
  end
@@ -1,31 +1,33 @@
1
+ # The HTML module serves as a namespace only.
1
2
  module HTML
3
+ # The Mixin module is a namespace for html-table mixins.
2
4
  module Mixin
5
+ # The HtmlHandler module is the library for generating html output.
3
6
  module HtmlHandler
4
-
5
- $upper = false
6
-
7
7
  # Used on HTML attributes. It creates proper HTML text based on the argument
8
- # type. A string looks like "attr='text'", a number looks like "attr=1",
8
+ # type. A string looks like "attr='text'", a number looks like "attr=1",
9
9
  # while a true value simply looks like "attr" (no equal sign).
10
10
  #--
11
11
  # This is private method.
12
12
  #
13
- def modify_html(attribute,arg=nil)
13
+ def modify_html(attribute, arg = nil)
14
14
  if @html_begin.scan(/\b#{attribute}\b/).empty?
15
- if arg.kind_of?(Integer)
16
- @html_begin << " #{attribute}=#{arg}"
17
- elsif arg.kind_of?(TrueClass)
18
- @html_begin << " #{attribute}"
19
- else
20
- @html_begin << " #{attribute}='#{arg}'"
15
+ case arg
16
+ when Integer
17
+ @html_begin << " #{attribute}=#{arg}"
18
+ when TrueClass
19
+ @html_begin << " #{attribute}"
20
+ else
21
+ @html_begin << " #{attribute}='#{arg}'"
21
22
  end
22
23
  else
23
- if arg.kind_of?(Integer)
24
- @html_begin.gsub!(/#{attribute}=\d+/,"#{attribute}=#{arg}")
25
- elsif arg.kind_of?(FalseClass)
26
- @html_begin.gsub!(/#{attribute}/,'')
27
- else
28
- @html_begin.gsub!(/#{attribute}=['\w\.]+/,"#{attribute}='#{arg}'")
24
+ case arg
25
+ when Integer
26
+ @html_begin.gsub!(/#{attribute}=\d+/, "#{attribute}=#{arg}")
27
+ when FalseClass
28
+ @html_begin.gsub!(/#{attribute}/, '')
29
+ else
30
+ @html_begin.gsub!(/#{attribute}=['\w.]+/, "#{attribute}='#{arg}'")
29
31
  end
30
32
  end
31
33
  end
@@ -38,11 +40,7 @@ module HTML
38
40
  # honored.
39
41
  #
40
42
  def html(formatting = true)
41
- if self.class.respond_to?(:html_case)
42
- $upper = true if self.class.html_case == "upper"
43
- end
44
-
45
- if $upper
43
+ if HTML::Table.html_case == 'upper'
46
44
  @html_begin.upcase!
47
45
  @html_end.upcase!
48
46
  end
@@ -53,15 +51,15 @@ module HTML
53
51
  ilevel = self.class.indent_level
54
52
  end
55
53
 
56
- html = ' ' * ilevel + @html_begin[0..-1]
54
+ html = (' ' * ilevel) + @html_begin[0..]
57
55
  len = html.length
58
- html[len,len] = '>'
56
+ html[len, len] = '>'
59
57
 
60
- if self.kind_of?(Array)
58
+ if is_a?(Array)
61
59
  if formatting
62
- html << self.map{ |e| "\n" + e.html(formatting).to_s }.join
60
+ html << map { |e| "\n#{e.html(formatting)}" }.join
63
61
  else
64
- html << self.map{ |e| e.html(formatting).to_s }.join
62
+ html << map { |e| e.html(formatting).to_s }.join
65
63
  end
66
64
  else
67
65
  html << @html_body
@@ -75,29 +73,29 @@ module HTML
75
73
  # The Table.global_end_tags method overrides the individual class
76
74
  # preferences with regards to end tags.
77
75
  #####################################################################
78
- if self.kind_of?(Array)
76
+ if is_a?(Array)
79
77
  if HTML::Table.global_end_tags?
80
78
  if self.class.respond_to?(:end_tags?)
81
79
  if formatting
82
80
  if self.class.end_tags?
83
- html << "\n" + (' ' * ilevel) + @html_end
81
+ html << ("\n" << (' ' * ilevel) << @html_end)
84
82
  end
85
83
  else
86
- html << (' ' * ilevel) + @html_end if self.class.end_tags?
84
+ html << ((' ' * ilevel) << @html_end) if self.class.end_tags?
87
85
  end
88
86
  else
89
87
  if formatting
90
- html << "\n" + (' ' * ilevel) + @html_end
88
+ html << ("\n" << (' ' * ilevel) << @html_end)
91
89
  else
92
- html << (' ' * ilevel) + @html_end
90
+ html << ((' ' * ilevel) << @html_end)
93
91
  end
94
92
  end
95
93
  else
96
94
  unless self.class.respond_to?(:end_tags?)
97
95
  if formatting
98
- html << "\n" + (' ' * ilevel) + @html_end
96
+ html << ("\n" << (' ' * ilevel) << @html_end)
99
97
  else
100
- html << (' ' * ilevel) + @html_end
98
+ html << ((' ' * ilevel) << @html_end)
101
99
  end
102
100
  end
103
101
  end
@@ -115,7 +113,7 @@ module HTML
115
113
  end
116
114
  end
117
115
 
118
- return html
116
+ html
119
117
  end
120
118
 
121
119
  private :modify_html
@@ -1,16 +1,16 @@
1
- # A pure-ruby replacement for strongtyping gem
2
-
1
+ # The HTML module serves as a namespace only.
3
2
  module HTML
3
+ # The Mixin module serves as a namespace only to prevent collisions.
4
4
  module Mixin
5
+ # The StrongTyping module is a pure Ruby replacement for the strongtyping gem.
5
6
  module StrongTyping
6
- class ArgumentTypeError < ArgumentError; end
7
-
8
7
  def expect(arg, allowed_types)
9
8
  return true if Array(allowed_types).any? do |klass|
10
- arg.kind_of?(klass)
9
+ arg.is_a?(klass)
11
10
  end
12
11
 
13
- raise ArgumentTypeError.new("#{arg} must be of type #{allowed_types}")
12
+ # Defined in table.rb
13
+ raise ArgumentTypeError, "#{arg} must be of type #{allowed_types}"
14
14
  end
15
15
  end
16
16
  end
@@ -5,8 +5,12 @@
5
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
+
9
+ # The HTML module serves as a namespace only.
8
10
  module HTML
11
+ # The Mixin module serves as a namespace only.
9
12
  module Mixin
13
+ # The TagHandler module implements handling for standard html physical tags.
10
14
  module TagHandler
11
15
  def bold(bool = nil)
12
16
  @bold ||= nil
@@ -115,9 +119,9 @@ module HTML
115
119
  end_tag = "</#{tag}>"
116
120
 
117
121
  if bool
118
- self.replace(begin_tag << self << end_tag)
122
+ replace(begin_tag << self << end_tag)
119
123
  else
120
- self.replace(self.gsub(/#{begin_tag}|#{end_tag}/,''))
124
+ replace(gsub(/#{begin_tag}|#{end_tag}/, ''))
121
125
  end
122
126
  end
123
127
  end