Class: Glimmer::XML::Node
- Inherits:
-
Object
- Object
- Glimmer::XML::Node
- Includes:
- Glimmer
- Defined in:
- lib/glimmer/xml/node.rb
Constant Summary
Constants included from Glimmer
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#children ⇒ Object
Returns the value of attribute children.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#is_attribute ⇒ Object
Returns the value of attribute is_attribute.
-
#is_name_space ⇒ Object
Returns the value of attribute is_name_space.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_space ⇒ Object
Returns the value of attribute name_space.
-
#parent ⇒ Object
Returns the value of attribute parent.
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
- #rubyize(text) ⇒ Object
- #text_command(text) ⇒ Object
- #to_xml ⇒ Object (also: #to_html, #to_s)
Methods included from Glimmer
Constructor Details
#initialize(parent, name, attributes, &contents) ⇒ Node
Returns a new instance of Node.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/glimmer/xml/node.rb', line 12 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
44 45 46 47 48 49 |
# File 'lib/glimmer/xml/node.rb', line 44 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::HtmlExpression.new) {@tag = super} @tag end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def children @children end |
#contents ⇒ Object
Returns the value of attribute contents.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def contents @contents end |
#is_attribute ⇒ Object
Returns the value of attribute is_attribute.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def is_attribute @is_attribute end |
#is_name_space ⇒ Object
Returns the value of attribute is_name_space.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def is_name_space @is_name_space end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def name @name end |
#name_space ⇒ Object
Returns the value of attribute name_space.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def name_space @name_space end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/glimmer/xml/node.rb', line 10 def parent @parent end |
Instance Method Details
#id ⇒ Object
override Object default id method and route it to Glimmer engine
70 71 72 |
# File 'lib/glimmer/xml/node.rb', line 70 def id method_missing(:id) end |
#rubyize(text) ⇒ Object
63 64 65 66 67 |
# File 'lib/glimmer/xml/node.rb', line 63 def rubyize(text) text = text.gsub(/[}]/, '"}') text = text.gsub(/[{]/, '{"') text = text.gsub(/[#]/, '') end |
#text_command(text) ⇒ Object
59 60 61 |
# File 'lib/glimmer/xml/node.rb', line 59 def text_command(text) "text \"#{text}\"" end |
#to_xml ⇒ Object Also known as: to_html, to_s
51 52 53 54 55 |
# File 'lib/glimmer/xml/node.rb', line 51 def to_xml xml_visitor = XmlVisitor.new DepthFirstSearchIterator.new(self, xml_visitor).iterate xml_visitor.document end |