Class: Glimmer::XML::XmlVisitor
- Inherits:
-
NodeVisitor
- Object
- NodeVisitor
- Glimmer::XML::XmlVisitor
- Defined in:
- lib/glimmer/xml/xml_visitor.rb
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.
10 11 12 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 10 def initialize @document = "" end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 8 def document @document end |
Instance Method Details
#append_attributes(node) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 52 def append_attributes(node) Glimmer::Config.logger&.debug "Take 3" 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) @document << " #{attribute_name}" @document << "=\"#{value}\"" unless value.nil? end end |
#append_close_tag(node) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 44 def append_close_tag(node) if (node.contents) @document << "</" @document << "#{node.name_space.name}:" if node.name_space @document << "#{node.name}>" end end |
#begin_open_tag(node) ⇒ Object
29 30 31 32 33 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 29 def begin_open_tag(node) @document << "<" @document << "#{node.name_space.name}:" if node.name_space @document << node.name end |
#end_open_tag(node) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 35 def end_open_tag(node) if (node.contents) @document << ">" else @document << " " if node.attributes.keys.size > 0 @document << "/>" end end |
#process_after_children(node) ⇒ Object
24 25 26 27 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 24 def process_after_children(node) return if (!node.is_a?(Glimmer::XML::Node)) append_close_tag(node) end |
#process_before_children(node) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/glimmer/xml/xml_visitor.rb', line 14 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 |