Class: RGen::Serializer::XMLSerializer
- Inherits:
-
Object
- Object
- RGen::Serializer::XMLSerializer
show all
- Defined in:
- lib/rgen/serializer/xml_serializer.rb
Constant Summary
collapse
- INDENT_SPACE =
2
Instance Method Summary
collapse
Constructor Details
Returns a new instance of XMLSerializer.
9
10
11
12
13
14
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 9
def initialize(file)
@indent = 0
@lastStartTag = nil
@textContent = false
@file = file
end
|
Instance Method Details
#endTag(tag) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 32
def endTag(tag)
@indent -= 1
unless handleLastStartTag(true, true)
output " "*@indent*INDENT_SPACE unless @textContent
output "</#{tag}>\n"
end
@textContent = false
end
|
#serialize(rootElement) ⇒ Object
16
17
18
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 16
def serialize(rootElement)
raise "Abstract class, overwrite method in subclass!"
end
|
#startTag(tag, attributes = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 20
def startTag(tag, attributes={})
@textContent = false
handleLastStartTag(false, true)
if attributes.is_a?(Hash)
attrString = attributes.keys.collect{|k| "#{k}=\"#{attributes[k]}\""}.join(" ")
else
attrString = attributes.collect{|pair| "#{pair[0]}=\"#{pair[1]}\""}.join(" ")
end
@lastStartTag = " "*@indent*INDENT_SPACE + "<#{tag} "+attrString
@indent += 1
end
|
#writeText(text) ⇒ Object
41
42
43
44
45
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 41
def writeText(text)
handleLastStartTag(false, false)
output "#{text}"
@textContent = true
end
|