Module: HTML::Mixin::AttributeHandler
- Included in:
- Table, Table::Caption, Table::ColGroup, Table::TableSection, Table::ColGroup::Col, Table::Row, Table::Row::Data, Table::Row::Header
- Defined in:
- lib/html/mixin/attribute_handler.rb
Overview
The AttributeHandler module creates methods for each of the various attributes associated with HTML tables. In some cases validation is done on the setters.
Instance Method Summary collapse
- #abbr(string = nil) ⇒ Object
- #abbr=(string) ⇒ Object
- #align(position = nil) ⇒ Object
- #align=(position) ⇒ Object
- #axis(string = nil) ⇒ Object
- #axis=(string) ⇒ Object
- #background(url = nil) ⇒ Object
- #background=(url) ⇒ Object
- #bgcolor(color = nil) ⇒ Object
- #bgcolor=(color) ⇒ Object
- #border(num = nil) ⇒ Object
-
#border=(num) ⇒ Object
Allow either true/false or an integer.
- #bordercolor(color = nil) ⇒ Object
- #bordercolor=(color) ⇒ Object
- #bordercolordark(color = nil) ⇒ Object
- #bordercolordark=(color) ⇒ Object
- #bordercolorlight(color = nil) ⇒ Object
- #bordercolorlight=(color) ⇒ Object
- #cellpadding(num = nil) ⇒ Object
- #cellpadding=(num) ⇒ Object
- #cellspacing(num = nil) ⇒ Object
- #cellspacing=(num) ⇒ Object
- #char(character = nil) ⇒ Object
- #char=(character) ⇒ Object
- #charoff(offset = nil) ⇒ Object
- #charoff=(offset) ⇒ Object
-
#class_(klass = nil) ⇒ Object
Returns the CSS class.
-
#class_=(klass) ⇒ Object
Returns the CSS class.
- #col(num = nil) ⇒ Object
- #col=(num) ⇒ Object
- #colspan(span = nil) ⇒ Object
- #colspan=(span) ⇒ Object
-
#configure(row, col = nil) ⇒ Object
Allows you to configure various attributes by row or row + column.
-
#content(arg = nil, &block) ⇒ Object
(also: #data)
Returns the HTML content (i.e. text).
- #frame(type = nil) ⇒ Object
- #frame=(type) ⇒ Object
- #height(num = nil) ⇒ Object
- #height=(num) ⇒ Object
- #hspace(num = nil) ⇒ Object
- #hspace=(num) ⇒ Object
- #nowrap(bool = nil) ⇒ Object
- #nowrap=(bool) ⇒ Object
- #rowspan(num = nil) ⇒ Object
- #rowspan=(num) ⇒ Object
- #rules(edges = nil) ⇒ Object
- #rules=(edges) ⇒ Object
- #span(num = nil) ⇒ Object
- #span=(num) ⇒ Object
- #style(string = nil) ⇒ Object
- #style=(string) ⇒ Object
- #summary(string = nil) ⇒ Object
- #summary=(string) ⇒ Object
- #valign(position = nil) ⇒ Object
- #valign=(position) ⇒ Object
- #vspace(num = nil) ⇒ Object
- #vspace=(num) ⇒ Object
- #width(num = nil) ⇒ Object
- #width=(num) ⇒ Object
Instance Method Details
#abbr(string = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/html/mixin/attribute_handler.rb', line 13 def abbr(string = nil) @abbr ||= nil self.abbr = string if string @abbr end |
#abbr=(string) ⇒ Object
19 20 21 22 |
# File 'lib/html/mixin/attribute_handler.rb', line 19 def abbr=(string) @abbr = string modify_html('abbr', string) end |
#align(position = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/html/mixin/attribute_handler.rb', line 24 def align(position = nil) @align ||= nil self.align = position if position @align end |
#align=(position) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/html/mixin/attribute_handler.rb', line 30 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
37 38 39 40 41 |
# File 'lib/html/mixin/attribute_handler.rb', line 37 def axis(string = nil) @axis ||= nil self.axis = string if string @axis end |
#axis=(string) ⇒ Object
43 44 45 46 |
# File 'lib/html/mixin/attribute_handler.rb', line 43 def axis=(string) @axis = string modify_html('axis', string) end |
#background(url = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/html/mixin/attribute_handler.rb', line 48 def background(url = nil) @background ||= nil self.background = url if url @background end |
#background=(url) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/html/mixin/attribute_handler.rb', line 54 def background=(url) raise TypeError unless url.is_a?(String) msg = "'background' is a non-standard extension" warn NonStandardExtensionWarning, msg @background = url modify_html('background', url) end |
#bgcolor(color = nil) ⇒ Object
62 63 64 65 66 |
# File 'lib/html/mixin/attribute_handler.rb', line 62 def bgcolor(color = nil) @bgcolor ||= nil self.bgcolor = color if color @bgcolor end |
#bgcolor=(color) ⇒ Object
68 69 70 71 |
# File 'lib/html/mixin/attribute_handler.rb', line 68 def bgcolor=(color) @bgcolor = color modify_html('bgcolor', color) end |
#border(num = nil) ⇒ Object
73 74 75 76 77 |
# File 'lib/html/mixin/attribute_handler.rb', line 73 def border(num = nil) @border ||= nil self.border = num if num @border end |
#border=(num) ⇒ Object
Allow either true/false or an integer
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/html/mixin/attribute_handler.rb', line 80 def border=(num) case num when TrueClass modify_html('border', true) when FalseClass # Do nothing else @border = num.to_i modify_html('border', num.to_i) end end |
#bordercolor(color = nil) ⇒ Object
92 93 94 95 96 |
# File 'lib/html/mixin/attribute_handler.rb', line 92 def bordercolor(color = nil) @bordercolor ||= nil self.bordercolor = color if color @bordercolor end |
#bordercolor=(color) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/html/mixin/attribute_handler.rb', line 98 def bordercolor=(color) @bordercolor = color msg = "'bordercolor' is a non-standard extension" warn NonStandardExtensionWarning, msg modify_html('bordercolor', color) end |
#bordercolordark(color = nil) ⇒ Object
105 106 107 108 109 |
# File 'lib/html/mixin/attribute_handler.rb', line 105 def bordercolordark(color = nil) @bordercolordark ||= nil self.bordercolordark = color if color @bordercolordark end |
#bordercolordark=(color) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/html/mixin/attribute_handler.rb', line 111 def bordercolordark=(color) @bordercolordark = color msg = "'bordercolordark' is a non-standard extension" warn NonStandardExtensionWarning, msg modify_html('bordercolordark', color) end |
#bordercolorlight(color = nil) ⇒ Object
118 119 120 121 122 |
# File 'lib/html/mixin/attribute_handler.rb', line 118 def bordercolorlight(color = nil) @bordercolorlight ||= nil self.bordercolorlight = color if color @bordercolorlight end |
#bordercolorlight=(color) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/html/mixin/attribute_handler.rb', line 124 def bordercolorlight=(color) @bordercolorlight = color msg = "'bordercolorlight' is a non-standard extension" warn NonStandardExtensionWarning, msg modify_html('bordercolorlight', @bordercolorlight) end |
#cellpadding(num = nil) ⇒ Object
131 132 133 134 135 |
# File 'lib/html/mixin/attribute_handler.rb', line 131 def cellpadding(num = nil) @cellpadding ||= nil self.cellpadding = num if num @cellpadding end |
#cellpadding=(num) ⇒ Object
137 138 139 140 141 |
# File 'lib/html/mixin/attribute_handler.rb', line 137 def cellpadding=(num) raise ArgumentError if num.to_i < 0 @cellpadding = num.to_i modify_html('cellpadding', @cellpadding) end |
#cellspacing(num = nil) ⇒ Object
143 144 145 146 147 |
# File 'lib/html/mixin/attribute_handler.rb', line 143 def cellspacing(num = nil) @cellspacing ||= nil self.cellspacing = num if num @cellspacing end |
#cellspacing=(num) ⇒ Object
149 150 151 152 153 |
# File 'lib/html/mixin/attribute_handler.rb', line 149 def cellspacing=(num) raise ArgumentError if num.to_i < 0 @cellspacing = num.to_i modify_html('cellspacing', @cellspacing) end |
#char(character = nil) ⇒ Object
155 156 157 158 159 |
# File 'lib/html/mixin/attribute_handler.rb', line 155 def char(character = nil) @char ||= nil self.char = character if character @char end |
#char=(character) ⇒ Object
161 162 163 164 165 |
# File 'lib/html/mixin/attribute_handler.rb', line 161 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
167 168 169 170 171 |
# File 'lib/html/mixin/attribute_handler.rb', line 167 def charoff(offset = nil) @charoff ||= nil self.charoff = offset if offset @charoff end |
#charoff=(offset) ⇒ Object
173 174 175 176 177 |
# File 'lib/html/mixin/attribute_handler.rb', line 173 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.
182 183 184 185 186 |
# File 'lib/html/mixin/attribute_handler.rb', line 182 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.
191 192 193 194 |
# File 'lib/html/mixin/attribute_handler.rb', line 191 def class_=(klass) modify_html('class', klass) @class = klass end |
#col(num = nil) ⇒ Object
196 197 198 199 200 |
# File 'lib/html/mixin/attribute_handler.rb', line 196 def col(num = nil) @col ||= nil self.col = num if num @col end |
#col=(num) ⇒ Object
202 203 204 205 206 |
# File 'lib/html/mixin/attribute_handler.rb', line 202 def col=(num) raise ArgumentError if num.to_i < 0 @col = num.to_i modify_html('col', @col) end |
#colspan(span = nil) ⇒ Object
208 209 210 211 212 |
# File 'lib/html/mixin/attribute_handler.rb', line 208 def colspan(span = nil) @colspan ||= nil self.colspan = span if span @colspan end |
#colspan=(span) ⇒ Object
214 215 216 217 218 |
# File 'lib/html/mixin/attribute_handler.rb', line 214 def colspan=(span) raise ArgumentError if span.to_i < 0 @colspan = span.to_i modify_html('colspan', @colspan) end |
#configure(row, col = nil) ⇒ Object
Allows you to configure various attributes by row or row + column.
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/html/mixin/attribute_handler.rb', line 222 def configure(row, col = nil) if col begin yield self[row][col] rescue NameError msg = "No column to configure in a #{self.class} 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).
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/html/mixin/attribute_handler.rb', line 237 def content(arg = nil, &block) case arg when String self.content = Table::Content.new(arg, &block) when Array arg.each do |e| if e.is_a?(Array) row = Table::Row.new e.each { |element| row.push(Table::Content.new(element, &block)) } push(row) else self.content = Table::Content.new(e, &block) end end else self.content = arg if arg end @html_body end |
#frame(type = nil) ⇒ Object
259 260 261 262 263 |
# File 'lib/html/mixin/attribute_handler.rb', line 259 def frame(type = nil) @frame ||= nil self.frame = type if type @frame end |
#frame=(type) ⇒ Object
265 266 267 268 269 270 |
# File 'lib/html/mixin/attribute_handler.rb', line 265 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
272 273 274 275 276 |
# File 'lib/html/mixin/attribute_handler.rb', line 272 def height(num = nil) @height ||= nil self.height = num if num @height end |
#height=(num) ⇒ Object
278 279 280 281 282 |
# File 'lib/html/mixin/attribute_handler.rb', line 278 def height=(num) raise ArgumentError if num.to_i < 0 @height = num.to_i modify_html('height', @height) end |
#hspace(num = nil) ⇒ Object
284 285 286 287 288 |
# File 'lib/html/mixin/attribute_handler.rb', line 284 def hspace(num = nil) @hspace ||= nil self.hspace = num if num @hspace end |
#hspace=(num) ⇒ Object
290 291 292 293 294 |
# File 'lib/html/mixin/attribute_handler.rb', line 290 def hspace=(num) raise ArgumentError if num.to_i < 0 @hspace = num.to_i modify_html('hspace', @hspace) end |
#nowrap(bool = nil) ⇒ Object
296 297 298 299 300 |
# File 'lib/html/mixin/attribute_handler.rb', line 296 def nowrap(bool = nil) @nowrap ||= nil self.nowrap = bool if bool @nowrap end |
#nowrap=(bool) ⇒ Object
302 303 304 305 306 307 308 |
# File 'lib/html/mixin/attribute_handler.rb', line 302 def nowrap=(bool) unless bool.is_a?(TrueClass) || bool.is_a?(FalseClass) raise TypeError end @nowrap = bool modify_html('nowrap', @nowrap) end |
#rowspan(num = nil) ⇒ Object
310 311 312 313 314 |
# File 'lib/html/mixin/attribute_handler.rb', line 310 def rowspan(num = nil) @rowspan ||= nil self.rowspan = num if num @rowspan end |
#rowspan=(num) ⇒ Object
316 317 318 319 320 |
# File 'lib/html/mixin/attribute_handler.rb', line 316 def rowspan=(num) raise ArgumentError if num.to_i < 0 @rowspan = num.to_i modify_html('rowspan', @rowspan) end |
#rules(edges = nil) ⇒ Object
322 323 324 325 326 |
# File 'lib/html/mixin/attribute_handler.rb', line 322 def rules(edges = nil) @rules ||= nil self.rules = edges if edges @rules end |
#rules=(edges) ⇒ Object
328 329 330 331 332 333 |
# File 'lib/html/mixin/attribute_handler.rb', line 328 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
335 336 337 338 339 |
# File 'lib/html/mixin/attribute_handler.rb', line 335 def span(num = nil) @span ||= nil self.span = num if num @span end |
#span=(num) ⇒ Object
341 342 343 344 345 |
# File 'lib/html/mixin/attribute_handler.rb', line 341 def span=(num) raise ArgumentError if num.to_i < 0 @span = num.to_i modify_html('span', @span) end |
#style(string = nil) ⇒ Object
347 348 349 350 351 |
# File 'lib/html/mixin/attribute_handler.rb', line 347 def style(string = nil) @style ||= nil self.style = string if string @style end |
#style=(string) ⇒ Object
353 354 355 356 |
# File 'lib/html/mixin/attribute_handler.rb', line 353 def style=(string) @style = string.to_s modify_html('style', @style) end |
#summary(string = nil) ⇒ Object
358 359 360 361 362 |
# File 'lib/html/mixin/attribute_handler.rb', line 358 def summary(string = nil) @summary ||= nil self.summary = string if string @summary end |
#summary=(string) ⇒ Object
364 365 366 367 |
# File 'lib/html/mixin/attribute_handler.rb', line 364 def summary=(string) @summary = string.to_s modify_html('summary', @summary) end |
#valign(position = nil) ⇒ Object
369 370 371 372 373 |
# File 'lib/html/mixin/attribute_handler.rb', line 369 def valign(position = nil) @valign ||= nil self.valign = position if position @valign end |
#valign=(position) ⇒ Object
375 376 377 378 379 380 |
# File 'lib/html/mixin/attribute_handler.rb', line 375 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
382 383 384 385 386 |
# File 'lib/html/mixin/attribute_handler.rb', line 382 def vspace(num = nil) @vspace ||= nil self.vspace = num if num @vspace end |
#vspace=(num) ⇒ Object
388 389 390 391 392 |
# File 'lib/html/mixin/attribute_handler.rb', line 388 def vspace=(num) raise ArgumentError if num.to_i < 0 @vspace = num.to_i modify_html('vspace', @vspace) end |
#width(num = nil) ⇒ Object
394 395 396 397 398 |
# File 'lib/html/mixin/attribute_handler.rb', line 394 def width(num = nil) @width ||= nil self.width = num if num @width end |
#width=(num) ⇒ Object
400 401 402 403 404 405 406 407 408 |
# File 'lib/html/mixin/attribute_handler.rb', line 400 def width=(num) if num.to_s =~ /%/ @width = num else raise ArgumentError if num.to_i < 0 @width = num.to_i end modify_html('width', @width) end |