Class: RichERB::TagNode

Inherits:
Object
  • Object
show all
Defined in:
lib/richerb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



77
78
79
# File 'lib/richerb.rb', line 77

def attributes
  @attributes
end

#childrenObject

Returns the value of attribute children.



74
75
76
# File 'lib/richerb.rb', line 74

def children
  @children
end

#nameObject

Returns the value of attribute name.



76
77
78
# File 'lib/richerb.rb', line 76

def name
  @name
end

#parentObject

Returns the value of attribute parent.



75
76
77
# File 'lib/richerb.rb', line 75

def parent
  @parent
end

Instance Method Details

#to_xmlObject



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