Class: Tagz::Namespace::Element
- Inherits:
-
String
- Object
- String
- Tagz::Namespace::Element
- Defined in:
- lib/tagz.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, *argv, &block) ⇒ Element
constructor
A new instance of Element.
Constructor Details
#initialize(name, *argv, &block) ⇒ Element
Returns a new instance of Element.
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/tagz.rb', line 328 def initialize(name, *argv, &block) = {} content = [] argv.each do |arg| case arg when Hash .update arg else content.push arg end end content.push block.call if block content.compact! @name = name.to_s if content.empty? replace "<#{ @name }#{ Element.attributes }>" else replace "<#{ @name }#{ Element.attributes }>#{ content.join }</#{ name }>" end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
326 327 328 |
# File 'lib/tagz.rb', line 326 def name @name end |
Class Method Details
.attributes(options) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/tagz.rb', line 306 def Element.attributes() unless .empty? +' ' << .map do |key, value| key = Tagz.escape_key(key) value = Tagz.escape_value(value) if value =~ %r/"/ raise ArgumentError, value if value =~ %r/'/ value = "'#{ value }'" else raise ArgumentError, value if value =~ %r/"/ value = "\"#{ value }\"" end [key, value].join('=') end.join(' ') else '' end end |