Module: AttributeHandler

Overview

This module creates methods for each of the various attributes associated with HTML tables. In some cases validation is done on the setters.

The seemingly redundant writer methods were left here for backwards compatibility and for those who may not prefer the DSI.

Instance Method Summary collapse

Instance Method Details

#abbr(string = nil) ⇒ Object



8
9
10
11
12
# File 'lib/html/attribute_handler.rb', line 8

def abbr(string = nil)
   @abbr ||= nil
   self.abbr = string if string
   @abbr
end

#abbr=(string) ⇒ Object



14
15
16
17
# File 'lib/html/attribute_handler.rb', line 14

def abbr=(string)
  @abbr = string
  modify_html("abbr", string)
end

#align(position = nil) ⇒ Object



19
20
21
22
23
# File 'lib/html/attribute_handler.rb', line 19

def align(position = nil)
   @align ||= nil
   self.align = position if position
   @align
end

#align=(position) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/html/attribute_handler.rb', line 25

def align=(position)
   valid = %w/top bottom left center right/
   raise ArgumentError unless valid.include?(position.downcase)
   @align = position
   modify_html("align", position)
end

#axis(string = nil) ⇒ Object



32
33
34
35
36
# File 'lib/html/attribute_handler.rb', line 32

def axis(string = nil)
   @axis ||= nil
   self.axis = string if string
   @axis
end

#axis=(string) ⇒ Object



38
39
40
41
# File 'lib/html/attribute_handler.rb', line 38

def axis=(string)
  @axis = string
  modify_html("axis", string)
end

#background(url = nil) ⇒ Object



43
44
45
46
47
# File 'lib/html/attribute_handler.rb', line 43

def background(url = nil)
   @background ||= nil
   self.background = url if url
   @background
end

#background=(url) ⇒ Object

Raises:

  • (TypeError)


49
50
51
52
53
54
55
# File 'lib/html/attribute_handler.rb', line 49

def background=(url)
   raise TypeError unless url.kind_of?(String)
   msg =  "'background' is a non-standard extension"
   warn NonStandardExtensionWarning, msg
   @background = url
   modify_html("background", url)
end

#bgcolor(color = nil) ⇒ Object



57
58
59
60
61
# File 'lib/html/attribute_handler.rb', line 57

def bgcolor(color = nil)
   @bgcolor ||= nil
   self.bgcolor = color if color
   @bgcolor
end

#bgcolor=(color) ⇒ Object



63
64
65
66
# File 'lib/html/attribute_handler.rb', line 63

def bgcolor=(color)
   @bgcolor = color
   modify_html("bgcolor", color)
end

#border(num = nil) ⇒ Object



68
69
70
71
72
# File 'lib/html/attribute_handler.rb', line 68

def border(num = nil)
   @border ||= nil
   self.border = num if num
   @border
end

#border=(num) ⇒ Object

Allow either true/false or an integer



75
76
77
78
79
80
81
82
83
84
# File 'lib/html/attribute_handler.rb', line 75

def border=(num)
   if num.kind_of?(TrueClass)
      modify_html("border", true)
   elsif num.kind_of?(FalseClass)
      # Do nothing
   else
      @border = num.to_i
      modify_html("border", num.to_i)
   end
end

#bordercolor(color = nil) ⇒ Object



86
87
88
89
90
# File 'lib/html/attribute_handler.rb', line 86

def bordercolor(color = nil)
   @bordercolor ||= nil
   self.bordercolor = color if color
   @bordercolor
end

#bordercolor=(color) ⇒ Object



92
93
94
95
96
97
# File 'lib/html/attribute_handler.rb', line 92

def bordercolor=(color)
   @bordercolor = color
   msg =  "'bordercolor' is a non-standard extension"
   warn NonStandardExtensionWarning, msg
   modify_html("bordercolor", color)
end

#bordercolordark(color = nil) ⇒ Object



99
100
101
102
103
# File 'lib/html/attribute_handler.rb', line 99

def bordercolordark(color = nil)
   @bordercolordark ||= nil
   self.bordercolordark = color if color
   @bordercolordark
end

#bordercolordark=(color) ⇒ Object



105
106
107
108
109
110
# File 'lib/html/attribute_handler.rb', line 105

def bordercolordark=(color)
   @bordercolordark = color
   msg = "'bordercolordark' is a non-standard extension"
   warn NonStandardExtensionWarning, msg
   modify_html("bordercolordark", color)
end

#bordercolorlight(color = nil) ⇒ Object



112
113
114
115
116
# File 'lib/html/attribute_handler.rb', line 112

def bordercolorlight(color = nil)
   @bordercolorlight ||= nil
   self.bordercolorlight = color if color
   @bordercolorlight
end

#bordercolorlight=(color) ⇒ Object



118
119
120
121
122
123
# File 'lib/html/attribute_handler.rb', line 118

def bordercolorlight=(color)
   @bordercolorlight = color
   msg = "'bordercolorlight' is a non-standard extension"
   warn NonStandardExtensionWarning, msg
   modify_html("bordercolorlight", @bordercolorlight)
end

#cellpadding(num = nil) ⇒ Object



125
126
127
128
129
# File 'lib/html/attribute_handler.rb', line 125

def cellpadding(num = nil)
   @cellpadding ||= nil
   self.cellpadding = num if num
   @cellpadding
end

#cellpadding=(num) ⇒ Object

Raises:

  • (ArgumentError)


131
132
133
134
135
# File 'lib/html/attribute_handler.rb', line 131

def cellpadding=(num)
   raise ArgumentError if num.to_i < 0
   @cellpadding = num.to_i
   modify_html("cellpadding", @cellpadding)
end

#cellspacing(num = nil) ⇒ Object



137
138
139
140
141
# File 'lib/html/attribute_handler.rb', line 137

def cellspacing(num = nil)
   @cellspacing ||= nil
   self.cellspacing = num if num
   @cellspacing
end

#cellspacing=(num) ⇒ Object

Raises:

  • (ArgumentError)


143
144
145
146
147
# File 'lib/html/attribute_handler.rb', line 143

def cellspacing=(num)
   raise ArgumentError if num.to_i < 0
   @cellspacing = num.to_i
   modify_html("cellspacing", @cellspacing)
end

#char(character = nil) ⇒ Object



149
150
151
152
153
# File 'lib/html/attribute_handler.rb', line 149

def char(character = nil)
   @char ||= nil
   self.char = character if character
   @char
end

#char=(character) ⇒ Object

Raises:

  • (ArgumentError)


155
156
157
158
159
# File 'lib/html/attribute_handler.rb', line 155

def char=(character)
   raise ArgumentError if character.to_s.length > 1
   @char = character.to_s
   modify_html("char", character.to_s)
end

#charoff(offset = nil) ⇒ Object



161
162
163
164
165
# File 'lib/html/attribute_handler.rb', line 161

def charoff(offset = nil)
   @charoff ||= nil
   self.charoff = offset if offset
   @charoff
end

#charoff=(offset) ⇒ Object

Raises:

  • (ArgumentError)


167
168
169
170
171
# File 'lib/html/attribute_handler.rb', line 167

def charoff=(offset)
   raise ArgumentError if offset.to_i < 0
   @charoff = offset
   modify_html("charoff", offset)
end

#class_(klass = nil) ⇒ Object

Returns the CSS class. The trailing underscore is necessary in order to avoid conflict with the 'class' keyword.



176
177
178
179
180
# File 'lib/html/attribute_handler.rb', line 176

def class_(klass = nil)
   @class ||= nil
   self.class_ = klass if klass
   @class
end

#class_=(klass) ⇒ Object

Returns the CSS class. The trailing underscore is necessary in order to avoid conflict with the 'class' keyword.



185
186
187
188
# File 'lib/html/attribute_handler.rb', line 185

def class_=(klass)
   modify_html('class', klass)
   @class = klass
end

#col(num = nil) ⇒ Object



190
191
192
193
194
# File 'lib/html/attribute_handler.rb', line 190

def col(num = nil)
   @col ||= nil
   self.col = num if num
   @col
end

#col=(num) ⇒ Object

Raises:

  • (ArgumentError)


196
197
198
199
200
# File 'lib/html/attribute_handler.rb', line 196

def col=(num)
   raise ArgumentError if num.to_i < 0
   @col = num.to_i
   modify_html("col", @col)
end

#colspan(span = nil) ⇒ Object



202
203
204
205
206
# File 'lib/html/attribute_handler.rb', line 202

def colspan(span = nil)
   @colspan ||= nil
   self.colspan = span if span
   @colspan
end

#colspan=(span) ⇒ Object

Raises:

  • (ArgumentError)


208
209
210
211
212
# File 'lib/html/attribute_handler.rb', line 208

def colspan=(span)
   raise ArgumentError if span.to_i < 0
   @colspan = span.to_i
   modify_html("colspan", @colspan)
end

#configure(row, col = nil, &block) ⇒ Object

Allows you to configure various attributes by row or row + column.



216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/html/attribute_handler.rb', line 216

def configure(row, col=nil, &block)
   if col
      begin
         yield self[row][col]
      rescue NameError
         msg = "No column to configure in a " + self.class.to_s + " class"
         raise ArgumentError, msg
      end
   else
      yield self[row]
   end
end

#content(arg = nil, &block) ⇒ Object Also known as: data

Returns the HTML content (i.e. text).



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/html/attribute_handler.rb', line 231

def content(arg = nil, &block)
   case arg
      when String
         self.content = Table::Content.new(arg, &block)
      when Array
         arg.each{ |e|
            if e.kind_of?(Array)
               row = Table::Row.new
               e.each{ |element| row.push(Table::Content.new(element, &block)) }
               self.push(row)
            else
               self.content = Table::Content.new(e, &block)
            end
         }
      else
         self.content = arg if arg
   end
   @html_body
end

#frame(type = nil) ⇒ Object



253
254
255
256
257
# File 'lib/html/attribute_handler.rb', line 253

def frame(type = nil)
   @frame ||= nil
   self.frame = type if type
   @frame
end

#frame=(type) ⇒ Object

Raises:

  • (ArgumentError)


259
260
261
262
263
264
# File 'lib/html/attribute_handler.rb', line 259

def frame=(type)
   valid = %w/border void above below hsides lhs rhs vsides box/
   raise ArgumentError unless valid.include?(type.downcase)
   @frame = type
   modify_html("frame", @frame)
end

#height(num = nil) ⇒ Object



266
267
268
269
270
# File 'lib/html/attribute_handler.rb', line 266

def height(num = nil)
   @height ||= nil
   self.height = num if num
   @height
end

#height=(num) ⇒ Object

Raises:

  • (ArgumentError)


272
273
274
275
276
# File 'lib/html/attribute_handler.rb', line 272

def height=(num)
   raise ArgumentError if num.to_i < 0
   @height = num.to_i
   modify_html("height", @height)
end

#hspace(num = nil) ⇒ Object



278
279
280
281
282
# File 'lib/html/attribute_handler.rb', line 278

def hspace(num = nil)
   @hspace ||= nil
   self.hspace = num if num
   @hspace
end

#hspace=(num) ⇒ Object

Raises:

  • (ArgumentError)


284
285
286
287
288
# File 'lib/html/attribute_handler.rb', line 284

def hspace=(num)
   raise ArgumentError if num.to_i < 0
   @hspace = num.to_i
   modify_html("hspace", @hspace)
end

#nowrap(bool = nil) ⇒ Object



290
291
292
293
294
# File 'lib/html/attribute_handler.rb', line 290

def nowrap(bool = nil)
   @nowrap ||= nil
   self.nowrap = bool if bool
   @nowrap
end

#nowrap=(bool) ⇒ Object



296
297
298
299
300
301
302
# File 'lib/html/attribute_handler.rb', line 296

def nowrap=(bool)
   unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
      raise TypeError
   end
   @nowrap = bool
   modify_html("nowrap", @nowrap)
end

#rowspan(num = nil) ⇒ Object



304
305
306
307
308
# File 'lib/html/attribute_handler.rb', line 304

def rowspan(num = nil)
   @rowspan ||= nil
   self.rowspan = num if num
   @rowspan
end

#rowspan=(num) ⇒ Object

Raises:

  • (ArgumentError)


310
311
312
313
314
# File 'lib/html/attribute_handler.rb', line 310

def rowspan=(num)
   raise ArgumentError if num.to_i < 0
   @rowspan = num.to_i
   modify_html("rowspan", @rowspan)
end

#rules(edges = nil) ⇒ Object



316
317
318
319
320
# File 'lib/html/attribute_handler.rb', line 316

def rules(edges = nil)
   @rules ||= nil
   self.rules = edges if edges
   @rules
end

#rules=(edges) ⇒ Object

Raises:

  • (ArgumentError)


322
323
324
325
326
327
# File 'lib/html/attribute_handler.rb', line 322

def rules=(edges)
   valid = %w/all groups rows cols none/
   raise ArgumentError unless valid.include?(edges.to_s.downcase)
   @rules = edges
   modify_html("rules", @rules)
end

#span(num = nil) ⇒ Object



329
330
331
332
333
# File 'lib/html/attribute_handler.rb', line 329

def span(num = nil)
   @span ||= nil
   self.span = num if num
   @span
end

#span=(num) ⇒ Object

Raises:

  • (ArgumentError)


335
336
337
338
339
# File 'lib/html/attribute_handler.rb', line 335

def span=(num)
   raise ArgumentError if num.to_i < 0
   @span = num.to_i
   modify_html("span", @span)
end

#style(string = nil) ⇒ Object



341
342
343
344
345
# File 'lib/html/attribute_handler.rb', line 341

def style(string = nil)
   @style ||= nil
   self.style = string if string
   @style
end

#style=(string) ⇒ Object



347
348
349
350
# File 'lib/html/attribute_handler.rb', line 347

def style=(string)
   @style = string.to_s
   modify_html("style", @style)
end

#summary(string = nil) ⇒ Object



352
353
354
355
356
# File 'lib/html/attribute_handler.rb', line 352

def summary(string = nil)
   @summary ||= nil
   self.summary = string if string
   @summary
end

#summary=(string) ⇒ Object



358
359
360
361
# File 'lib/html/attribute_handler.rb', line 358

def summary=(string)
   @summary = string.to_s
   modify_html("summary", @summary)
end

#valign(position = nil) ⇒ Object



363
364
365
366
367
# File 'lib/html/attribute_handler.rb', line 363

def valign(position = nil)
   @valign ||= nil
   self.valign = position if position
   @valign
end

#valign=(position) ⇒ Object

Raises:

  • (ArgumentError)


369
370
371
372
373
374
# File 'lib/html/attribute_handler.rb', line 369

def valign=(position)
   valid = %w/top center bottom baseline/
   raise ArgumentError unless valid.include?(position.to_s.downcase)
   @valign = position
   modify_html("valign", @valign)
end

#vspace(num = nil) ⇒ Object



376
377
378
379
380
# File 'lib/html/attribute_handler.rb', line 376

def vspace(num = nil)
   @vspace ||= nil
   self.vspace = num if num
   @vspace
end

#vspace=(num) ⇒ Object

Raises:

  • (ArgumentError)


382
383
384
385
386
# File 'lib/html/attribute_handler.rb', line 382

def vspace=(num)
   raise ArgumentError if num.to_i < 0
   @vspace = num.to_i
   modify_html("vspace", @vspace)
end

#width(num = nil) ⇒ Object



388
389
390
391
392
# File 'lib/html/attribute_handler.rb', line 388

def width(num = nil)
   @width ||= nil
   self.width = num if num
   @width
end

#width=(num) ⇒ Object



394
395
396
397
398
399
400
401
402
# File 'lib/html/attribute_handler.rb', line 394

def width=(num)
   if num =~ /%/
      @width = num
   else
      raise ArgumentError if num.to_i < 0
      @width = num.to_i
   end
   modify_html("width", @width)
end