Class: Glimmer::XML::XmlVisitor
- Inherits:
-
NodeVisitor
- Object
- NodeVisitor
- Glimmer::XML::XmlVisitor
- Defined in:
- lib/glimmer/xml/xml_visitor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
- #append_attributes(node) ⇒ Object
- #append_close_tag(node) ⇒ Object
- #begin_open_tag(node) ⇒ Object
- #end_open_tag(node) ⇒ Object
-
#initialize ⇒ XmlVisitor
constructor
A new instance of XmlVisitor.
- #process_after_children(node) ⇒ Object
- #process_before_children(node) ⇒ Object
Constructor Details
#initialize ⇒ XmlVisitor
Returns a new instance of XmlVisitor.
31 32 33 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 31 def initialize @document = "" end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
29 30 31 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 29 def document @document end |
Instance Method Details
#append_attributes(node) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 76 def append_attributes(node) return if node.name == 'xml' || node.name_space_context? # Glimmer::Config.logger&.debug "Append Attributes" # Glimmer::Config.logger&.debug(node.attributes) node.attributes.each do |attribute, value| attribute_name = attribute attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node) attribute_name = attribute_name.to_s.gsub('_', Glimmer::Config.xml_attribute_underscore) if attribute_name.is_a?(Symbol) @document += " #{attribute_name}" @document += "=\"#{value}\"" unless value.nil? end end |
#append_close_tag(node) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 67 def append_close_tag(node) return if node.name == 'xml' || node.name_space_context? if (node.contents) @document += "</" @document += "#{node.name_space.name}:" if node.name_space @document += "#{node.name}>" end end |
#begin_open_tag(node) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 50 def begin_open_tag(node) return if node.name == 'xml' || node.name_space_context? @document += "<" @document += "#{node.name_space.name}:" if node.name_space @document += node.name end |
#end_open_tag(node) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 57 def end_open_tag(node) return if node.name == 'xml' || node.name_space_context? if (node.contents) @document += ">" else @document += " " if node.attributes.keys.size > 0 @document += " />" end end |
#process_after_children(node) ⇒ Object
45 46 47 48 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 45 def process_after_children(node) return if (!node.is_a?(Glimmer::XML::Node)) append_close_tag(node) end |
#process_before_children(node) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 35 def process_before_children(node) if (!node.is_a?(Glimmer::XML::Node)) @document += node.to_s return end begin_open_tag(node) append_attributes(node) if node.attributes end_open_tag(node) end |