Class: Glimmer::XML::Node
- Inherits:
-
Object
- Object
- Glimmer::XML::Node
- Includes:
- Glimmer
- Defined in:
- lib/glimmer/xml/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
TODO change is_name_space to name_space?.
-
#children ⇒ Object
TODO change is_name_space to name_space?.
-
#contents ⇒ Object
TODO change is_name_space to name_space?.
-
#is_attribute ⇒ Object
TODO change is_name_space to name_space?.
-
#is_name_space ⇒ Object
TODO change is_name_space to name_space?.
-
#name ⇒ Object
TODO change is_name_space to name_space?.
-
#name_space ⇒ Object
TODO change is_name_space to name_space?.
-
#parent ⇒ Object
TODO change is_name_space to name_space?.
Instance Method Summary collapse
-
#id ⇒ Object
override Object default id method and route it to Glimmer engine.
-
#initialize(parent, name, attributes, &contents) ⇒ Node
constructor
A new instance of Node.
- #method_missing(symbol, *args, &block) ⇒ Object
- #name_space_context? ⇒ Boolean
- #rubyize(text) ⇒ Object
- #text_command(text) ⇒ Object
- #to_xml ⇒ Object (also: #to_s)
Constructor Details
#initialize(parent, name, attributes, &contents) ⇒ Node
Returns a new instance of Node.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/glimmer/xml/node.rb', line 34 def initialize(parent, name, attributes, &contents) @is_name_space = false @children = [] @parent = parent if attributes.is_a?(Array) attributes = attributes.compact hash_attributes = attributes.last.is_a?(Hash) ? attributes.delete(attributes.last) : {} hash_attributes = attributes.reduce(hash_attributes) do |hash, attribute| hash.merge(attribute => nil) end attributes = hash_attributes end if (parent and parent.is_name_space) @name_space = parent @parent = @name_space.parent end @parent.children << self if @parent @name = name @contents = contents @attributes = attributes if @attributes @attributes.each_key do |attribute| if attribute.is_a?(Node) attribute.is_attribute = true attribute.parent.children.delete(attribute) if attribute.parent attribute.parent = nil #attributes do not usually have parents end end # Glimmer::Config.logger&.debug(attributes) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/glimmer/xml/node.rb', line 66 def method_missing(symbol, *args, &block) @is_name_space = true parent.children.delete(self) if parent Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::XmlExpression.new, name, attributes) {@tag = super} @tag end |
Instance Attribute Details
#attributes ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def attributes @attributes end |
#children ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def children @children end |
#contents ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def contents @contents end |
#is_attribute ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def is_attribute @is_attribute end |
#is_name_space ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def is_name_space @is_name_space end |
#name ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def name @name end |
#name_space ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def name_space @name_space end |
#parent ⇒ Object
TODO change is_name_space to name_space?
32 33 34 |
# File 'lib/glimmer/xml/node.rb', line 32 def parent @parent end |
Instance Method Details
#id ⇒ Object
override Object default id method and route it to Glimmer engine
95 96 97 |
# File 'lib/glimmer/xml/node.rb', line 95 def id method_missing(:id) end |
#name_space_context? ⇒ Boolean
73 74 75 |
# File 'lib/glimmer/xml/node.rb', line 73 def name_space_context? attributes[:_name_space_context] end |
#rubyize(text) ⇒ Object
88 89 90 91 92 |
# File 'lib/glimmer/xml/node.rb', line 88 def rubyize(text) text = text.gsub(/[}]/, '"}') text = text.gsub(/[{]/, '{"') text = text.gsub(/[#]/, '') end |
#text_command(text) ⇒ Object
84 85 86 |
# File 'lib/glimmer/xml/node.rb', line 84 def text_command(text) "text \"#{text}\"" end |
#to_xml ⇒ Object Also known as: to_s
77 78 79 80 81 |
# File 'lib/glimmer/xml/node.rb', line 77 def to_xml xml_visitor = XmlVisitor.new DepthFirstSearchIterator.new(self, xml_visitor).iterate xml_visitor.document end |