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
@@ -141,10 +141,10 @@ Table#unshift(obj)
141
141
  Holden Glova and Culley Harrelson for API suggestions and comments.
142
142
 
143
143
  == License
144
- Ruby's
144
+ Apache-2.0
145
145
 
146
146
  == Copyright
147
- (C) 2003-2008 Daniel J. Berger
147
+ (C) 2003-2019 Daniel J. Berger
148
148
  All Rights Reserved
149
149
 
150
150
  == Warranty
@@ -154,5 +154,3 @@ Table#unshift(obj)
154
154
 
155
155
  == Author
156
156
  Daniel J. Berger
157
- djberg96 at nospam at gmail dot com
158
- imperator on IRC (irc.freenode.net)
@@ -2,22 +2,21 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'html-table'
5
- spec.version = '1.5.2'
5
+ spec.version = '1.7.0'
6
6
  spec.author = 'Daniel J. Berger'
7
- spec.license = 'Artistic 2.0'
7
+ spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'http://github.com/djberg96/html-table'
10
10
  spec.summary = 'A Ruby interface for generating HTML tables'
11
- spec.test_files = Dir['test/*.rb']
11
+ spec.test_files = Dir['spec/*.rb']
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = ['certs/djberg96_pub.pem']
14
14
 
15
- spec.extra_rdoc_files = ['README', 'CHANGES'] + Dir['doc/*.rdoc']
15
+ spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc'] + Dir['doc/*.rdoc']
16
16
 
17
- spec.add_dependency('strongtyping')
18
- spec.add_dependency('structured_warnings', '~> 0.3.0')
17
+ spec.add_dependency('structured_warnings', '~> 0.4.0')
19
18
 
20
- spec.add_development_dependency('test-unit')
19
+ spec.add_development_dependency('rspec', '~> 3.9')
21
20
  spec.add_development_dependency('rake')
22
21
 
23
22
  spec.metadata = {
@@ -4,8 +4,8 @@ module HTML
4
4
  # a subclass of Table. Note that end tags for this class are mandatory.
5
5
  #
6
6
  class Table::Caption
7
- include AttributeHandler
8
- include HtmlHandler
7
+ include HTML::Mixin::AttributeHandler
8
+ include HTML::Mixin::HtmlHandler
9
9
 
10
10
  undef_method :configure
11
11
  @indent_level = 3
@@ -3,8 +3,8 @@ module HTML
3
3
  # name, it is not a subclass of ColGroup or Table.
4
4
  #
5
5
  class Table::ColGroup::Col
6
- include AttributeHandler
7
- include HtmlHandler
6
+ include HTML::Mixin::AttributeHandler
7
+ include HTML::Mixin::HtmlHandler
8
8
 
9
9
  undef_method :configure, :content
10
10
  @indent_level = 6
@@ -4,8 +4,8 @@ module HTML
4
4
  # of the ColGroup::Col class.
5
5
  #
6
6
  class Table::ColGroup < Array
7
- include AttributeHandler
8
- include HtmlHandler
7
+ include HTML::Mixin::AttributeHandler
8
+ include HTML::Mixin::HtmlHandler
9
9
 
10
10
  @indent_level = 3
11
11
  @end_tags = true
@@ -89,8 +89,8 @@ module HTML
89
89
  raise TypeError, msg
90
90
  end
91
91
  super
92
- end
93
-
92
+ end
93
+
94
94
  # Returns a boolean indicating whether or not end tags are included for
95
95
  # each ColGroup object in the final HTML output. The default is true.
96
96
  #
@@ -4,11 +4,11 @@
4
4
  # This class handles content for Table::Row::Data, Table::Row::Header,
5
5
  # and Table::Row::Caption objects.
6
6
  ########################################################################
7
- require File.join(File.dirname(__FILE__), 'tag_handler')
7
+ require_relative 'mixin/tag_handler'
8
8
 
9
9
  module HTML
10
10
  class Table::Content < String
11
- include TagHandler
11
+ include HTML::Mixin::TagHandler
12
12
 
13
13
  def initialize(string, &block)
14
14
  super(string)
@@ -4,8 +4,8 @@ module HTML
4
4
  # it is not a subclass of Table::Row or Table.
5
5
  #
6
6
  class Table::Row::Data
7
- include AttributeHandler
8
- include HtmlHandler
7
+ include HTML::Mixin::AttributeHandler
8
+ include HTML::Mixin::HtmlHandler
9
9
 
10
10
  undef_method :configure
11
11
 
@@ -4,8 +4,8 @@ module HTML
4
4
  # it is not a subclass of Table or Table::Row.
5
5
  #
6
6
  class Table::Row::Header
7
- include AttributeHandler
8
- include HtmlHandler
7
+ include HTML::Mixin::AttributeHandler
8
+ include HTML::Mixin::HtmlHandler
9
9
 
10
10
  undef_method :configure
11
11
 
@@ -0,0 +1,407 @@
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 DSL.
6
+ #
7
+ module HTML
8
+ module Mixin
9
+ module AttributeHandler
10
+ def abbr(string = nil)
11
+ @abbr ||= nil
12
+ self.abbr = string if string
13
+ @abbr
14
+ end
15
+
16
+ def abbr=(string)
17
+ @abbr = string
18
+ modify_html("abbr", string)
19
+ end
20
+
21
+ def align(position = nil)
22
+ @align ||= nil
23
+ self.align = position if position
24
+ @align
25
+ end
26
+
27
+ def align=(position)
28
+ valid = %w/top bottom left center right/
29
+ raise ArgumentError unless valid.include?(position.downcase)
30
+ @align = position
31
+ modify_html("align", position)
32
+ end
33
+
34
+ def axis(string = nil)
35
+ @axis ||= nil
36
+ self.axis = string if string
37
+ @axis
38
+ end
39
+
40
+ def axis=(string)
41
+ @axis = string
42
+ modify_html("axis", string)
43
+ end
44
+
45
+ def background(url = nil)
46
+ @background ||= nil
47
+ self.background = url if url
48
+ @background
49
+ end
50
+
51
+ def background=(url)
52
+ raise TypeError unless url.kind_of?(String)
53
+ msg = "'background' is a non-standard extension"
54
+ warn NonStandardExtensionWarning, msg
55
+ @background = url
56
+ modify_html("background", url)
57
+ end
58
+
59
+ def bgcolor(color = nil)
60
+ @bgcolor ||= nil
61
+ self.bgcolor = color if color
62
+ @bgcolor
63
+ end
64
+
65
+ def bgcolor=(color)
66
+ @bgcolor = color
67
+ modify_html("bgcolor", color)
68
+ end
69
+
70
+ def border(num = nil)
71
+ @border ||= nil
72
+ self.border = num if num
73
+ @border
74
+ end
75
+
76
+ # Allow either true/false or an integer
77
+ 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)
85
+ end
86
+ end
87
+
88
+ def bordercolor(color = nil)
89
+ @bordercolor ||= nil
90
+ self.bordercolor = color if color
91
+ @bordercolor
92
+ end
93
+
94
+ def bordercolor=(color)
95
+ @bordercolor = color
96
+ msg = "'bordercolor' is a non-standard extension"
97
+ warn NonStandardExtensionWarning, msg
98
+ modify_html("bordercolor", color)
99
+ end
100
+
101
+ def bordercolordark(color = nil)
102
+ @bordercolordark ||= nil
103
+ self.bordercolordark = color if color
104
+ @bordercolordark
105
+ end
106
+
107
+ def bordercolordark=(color)
108
+ @bordercolordark = color
109
+ msg = "'bordercolordark' is a non-standard extension"
110
+ warn NonStandardExtensionWarning, msg
111
+ modify_html("bordercolordark", color)
112
+ end
113
+
114
+ def bordercolorlight(color = nil)
115
+ @bordercolorlight ||= nil
116
+ self.bordercolorlight = color if color
117
+ @bordercolorlight
118
+ end
119
+
120
+ def bordercolorlight=(color)
121
+ @bordercolorlight = color
122
+ msg = "'bordercolorlight' is a non-standard extension"
123
+ warn NonStandardExtensionWarning, msg
124
+ modify_html("bordercolorlight", @bordercolorlight)
125
+ end
126
+
127
+ def cellpadding(num = nil)
128
+ @cellpadding ||= nil
129
+ self.cellpadding = num if num
130
+ @cellpadding
131
+ end
132
+
133
+ def cellpadding=(num)
134
+ raise ArgumentError if num.to_i < 0
135
+ @cellpadding = num.to_i
136
+ modify_html("cellpadding", @cellpadding)
137
+ end
138
+
139
+ def cellspacing(num = nil)
140
+ @cellspacing ||= nil
141
+ self.cellspacing = num if num
142
+ @cellspacing
143
+ end
144
+
145
+ def cellspacing=(num)
146
+ raise ArgumentError if num.to_i < 0
147
+ @cellspacing = num.to_i
148
+ modify_html("cellspacing", @cellspacing)
149
+ end
150
+
151
+ def char(character = nil)
152
+ @char ||= nil
153
+ self.char = character if character
154
+ @char
155
+ end
156
+
157
+ def char=(character)
158
+ raise ArgumentError if character.to_s.length > 1
159
+ @char = character.to_s
160
+ modify_html("char", character.to_s)
161
+ end
162
+
163
+ def charoff(offset = nil)
164
+ @charoff ||= nil
165
+ self.charoff = offset if offset
166
+ @charoff
167
+ end
168
+
169
+ def charoff=(offset)
170
+ raise ArgumentError if offset.to_i < 0
171
+ @charoff = offset
172
+ modify_html("charoff", offset)
173
+ end
174
+
175
+ # Returns the CSS class. The trailing underscore is necessary in order
176
+ # to avoid conflict with the 'class' keyword.
177
+ #
178
+ def class_(klass = nil)
179
+ @class ||= nil
180
+ self.class_ = klass if klass
181
+ @class
182
+ end
183
+
184
+ # Returns the CSS class. The trailing underscore is necessary in order
185
+ # to avoid conflict with the 'class' keyword.
186
+ #
187
+ def class_=(klass)
188
+ modify_html('class', klass)
189
+ @class = klass
190
+ end
191
+
192
+ def col(num = nil)
193
+ @col ||= nil
194
+ self.col = num if num
195
+ @col
196
+ end
197
+
198
+ def col=(num)
199
+ raise ArgumentError if num.to_i < 0
200
+ @col = num.to_i
201
+ modify_html("col", @col)
202
+ end
203
+
204
+ def colspan(span = nil)
205
+ @colspan ||= nil
206
+ self.colspan = span if span
207
+ @colspan
208
+ end
209
+
210
+ def colspan=(span)
211
+ raise ArgumentError if span.to_i < 0
212
+ @colspan = span.to_i
213
+ modify_html("colspan", @colspan)
214
+ end
215
+
216
+ # Allows you to configure various attributes by row or row + column.
217
+ #
218
+ def configure(row, col=nil, &block)
219
+ if col
220
+ begin
221
+ yield self[row][col]
222
+ rescue NameError
223
+ msg = "No column to configure in a " + self.class.to_s + " class"
224
+ raise ArgumentError, msg
225
+ end
226
+ else
227
+ yield self[row]
228
+ end
229
+ end
230
+
231
+ # Returns the HTML content (i.e. text).
232
+ #
233
+ def content(arg = nil, &block)
234
+ case arg
235
+ when String
236
+ self.content = Table::Content.new(arg, &block)
237
+ when Array
238
+ arg.each{ |e|
239
+ if e.kind_of?(Array)
240
+ row = Table::Row.new
241
+ e.each{ |element| row.push(Table::Content.new(element, &block)) }
242
+ self.push(row)
243
+ else
244
+ self.content = Table::Content.new(e, &block)
245
+ end
246
+ }
247
+ else
248
+ self.content = arg if arg
249
+ end
250
+ @html_body
251
+ end
252
+
253
+ alias data content
254
+
255
+ def frame(type = nil)
256
+ @frame ||= nil
257
+ self.frame = type if type
258
+ @frame
259
+ end
260
+
261
+ def frame=(type)
262
+ valid = %w/border void above below hsides lhs rhs vsides box/
263
+ raise ArgumentError unless valid.include?(type.downcase)
264
+ @frame = type
265
+ modify_html("frame", @frame)
266
+ end
267
+
268
+ def height(num = nil)
269
+ @height ||= nil
270
+ self.height = num if num
271
+ @height
272
+ end
273
+
274
+ def height=(num)
275
+ raise ArgumentError if num.to_i < 0
276
+ @height = num.to_i
277
+ modify_html("height", @height)
278
+ end
279
+
280
+ def hspace(num = nil)
281
+ @hspace ||= nil
282
+ self.hspace = num if num
283
+ @hspace
284
+ end
285
+
286
+ def hspace=(num)
287
+ raise ArgumentError if num.to_i < 0
288
+ @hspace = num.to_i
289
+ modify_html("hspace", @hspace)
290
+ end
291
+
292
+ def nowrap(bool = nil)
293
+ @nowrap ||= nil
294
+ self.nowrap = bool if bool
295
+ @nowrap
296
+ end
297
+
298
+ def nowrap=(bool)
299
+ unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
300
+ raise TypeError
301
+ end
302
+ @nowrap = bool
303
+ modify_html("nowrap", @nowrap)
304
+ end
305
+
306
+ def rowspan(num = nil)
307
+ @rowspan ||= nil
308
+ self.rowspan = num if num
309
+ @rowspan
310
+ end
311
+
312
+ def rowspan=(num)
313
+ raise ArgumentError if num.to_i < 0
314
+ @rowspan = num.to_i
315
+ modify_html("rowspan", @rowspan)
316
+ end
317
+
318
+ def rules(edges = nil)
319
+ @rules ||= nil
320
+ self.rules = edges if edges
321
+ @rules
322
+ end
323
+
324
+ def rules=(edges)
325
+ valid = %w/all groups rows cols none/
326
+ raise ArgumentError unless valid.include?(edges.to_s.downcase)
327
+ @rules = edges
328
+ modify_html("rules", @rules)
329
+ end
330
+
331
+ def span(num = nil)
332
+ @span ||= nil
333
+ self.span = num if num
334
+ @span
335
+ end
336
+
337
+ def span=(num)
338
+ raise ArgumentError if num.to_i < 0
339
+ @span = num.to_i
340
+ modify_html("span", @span)
341
+ end
342
+
343
+ def style(string = nil)
344
+ @style ||= nil
345
+ self.style = string if string
346
+ @style
347
+ end
348
+
349
+ def style=(string)
350
+ @style = string.to_s
351
+ modify_html("style", @style)
352
+ end
353
+
354
+ def summary(string = nil)
355
+ @summary ||= nil
356
+ self.summary = string if string
357
+ @summary
358
+ end
359
+
360
+ def summary=(string)
361
+ @summary = string.to_s
362
+ modify_html("summary", @summary)
363
+ end
364
+
365
+ def valign(position = nil)
366
+ @valign ||= nil
367
+ self.valign = position if position
368
+ @valign
369
+ end
370
+
371
+ def valign=(position)
372
+ valid = %w/top center bottom baseline/
373
+ raise ArgumentError unless valid.include?(position.to_s.downcase)
374
+ @valign = position
375
+ modify_html("valign", @valign)
376
+ end
377
+
378
+ def vspace(num = nil)
379
+ @vspace ||= nil
380
+ self.vspace = num if num
381
+ @vspace
382
+ end
383
+
384
+ def vspace=(num)
385
+ raise ArgumentError if num.to_i < 0
386
+ @vspace = num.to_i
387
+ modify_html("vspace", @vspace)
388
+ end
389
+
390
+ def width(num = nil)
391
+ @width ||= nil
392
+ self.width = num if num
393
+ @width
394
+ end
395
+
396
+ def width=(num)
397
+ if num.to_s =~ /%/
398
+ @width = num
399
+ else
400
+ raise ArgumentError if num.to_i < 0
401
+ @width = num.to_i
402
+ end
403
+ modify_html("width", @width)
404
+ end
405
+ end
406
+ end
407
+ end