Class: RichERB::TagNode
- Inherits:
-
Object
- Object
- RichERB::TagNode
- Defined in:
- lib/richerb.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(name, attributes = {}) ⇒ TagNode
constructor
A new instance of TagNode.
- #to_xml ⇒ Object
- #to_xml_node(xml) ⇒ Object
Constructor Details
#initialize(name, attributes = {}) ⇒ TagNode
Returns a new instance of TagNode.
79 80 81 82 83 84 85 |
# File 'lib/richerb.rb', line 79 def initialize name, attributes = {} @name = name @children = [] @parent = nil @attributes = {} attributes.each {|k,v| @attributes[k.to_sym] = v } unless attributes.nil? end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
77 78 79 |
# File 'lib/richerb.rb', line 77 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
74 75 76 |
# File 'lib/richerb.rb', line 74 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
76 77 78 |
# File 'lib/richerb.rb', line 76 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
75 76 77 |
# File 'lib/richerb.rb', line 75 def parent @parent end |
Instance Method Details
#to_xml ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/richerb.rb', line 93 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.send(@name.to_sym, @attributes) { @children.each {|node| node.to_node(xml) } } end builder.doc.root.to_xml end |
#to_xml_node(xml) ⇒ Object
87 88 89 90 91 |
# File 'lib/richerb.rb', line 87 def to_xml_node(xml) xml.send(@name.to_sym, @attributes) { @children.each {|node| node.to_xml_node(xml) } } end |