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
28
29
30
31
32
33
34
35
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 28
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
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 20
def startTag(tag, attributes={})
@textContent = false
handleLastStartTag(false, true)
@lastStartTag = " "*@indent*INDENT_SPACE +
"<#{tag} "+attributes.keys.collect{|k| "#{k}=\"#{attributes[k]}\""}.join(" ")
@indent += 1
end
|
#writeText(text) ⇒ Object
37
38
39
40
41
|
# File 'lib/rgen/serializer/xml_serializer.rb', line 37
def writeText(text)
handleLastStartTag(false, false)
output "#{text}"
@textContent = true
end
|