Module: Amrita2::ElementHelper
- Included in:
- Hpricot::Elem
- Defined in:
- lib/amrita2/template.rb,
lib/amrita2/template.rb
Overview
:nodoc: all
Instance Method Summary collapse
- #add(elem) ⇒ Object
- #add_text(text) ⇒ Object
- #as_amrita_dictionary(opt = {}) ⇒ Object
- #contents ⇒ Object
- #delete_attribute(key) ⇒ Object
- #elements ⇒ Object
- #set_attribute(key, val) ⇒ Object
Instance Method Details
#add(elem) ⇒ Object
482 483 484 |
# File 'lib/amrita2/template.rb', line 482 def add(elem) insert_after(elem, nil) end |
#add_text(text) ⇒ Object
486 487 488 |
# File 'lib/amrita2/template.rb', line 486 def add_text(text) insert_after(Hpricot::Text.new(text), nil) end |
#as_amrita_dictionary(opt = {}) ⇒ Object
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/amrita2/template.rb', line 490 def as_amrita_dictionary(opt={}) ret = {} attributes.each do |k, v| ret[k.intern] = v end if opt[:use_contents] ret[opt[:use_contents]] = Amrita2::SanitizedString[ children.collect do |c| c.to_s end.join ] end if opt[:use_tag] { name.intern => ret } else ret end end |
#contents ⇒ Object
461 462 463 464 465 466 467 |
# File 'lib/amrita2/template.rb', line 461 def contents if children.size > 0 SanitizedString[children.to_s] else nil end end |
#delete_attribute(key) ⇒ Object
478 479 480 |
# File 'lib/amrita2/template.rb', line 478 def delete_attribute(key) raw_attributes.delete(key) end |
#elements ⇒ Object
455 456 457 458 459 |
# File 'lib/amrita2/template.rb', line 455 def elements children.select do |c| c.kind_of?(Hpricot::Elem) end end |
#set_attribute(key, val) ⇒ Object
469 470 471 472 473 474 475 476 |
# File 'lib/amrita2/template.rb', line 469 def set_attribute(key, val) case val when nil, "" delete_attribute(key) else super end end |