xml-to-haml 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/xml-to-haml.rb +9 -6
- metadata +1 -1
data/lib/xml-to-haml.rb
CHANGED
@@ -9,21 +9,19 @@ class XMLtoHAML
|
|
9
9
|
|
10
10
|
def initialize(s)
|
11
11
|
doc = Document.new(s)
|
12
|
-
@haml = xml_to_haml(doc)
|
12
|
+
@haml = xml_to_haml(doc)
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
16
16
|
@haml
|
17
17
|
end
|
18
18
|
|
19
|
-
private
|
20
|
-
|
21
19
|
def xml_to_haml(nodex, indent ='')
|
22
20
|
|
23
|
-
nodex.elements.
|
21
|
+
buffer = nodex.elements.map do |node|
|
24
22
|
|
25
23
|
attributex = ' '
|
26
|
-
buffer = indent + '%' + node.name
|
24
|
+
buffer = "%s" % [indent + '%' + node.name]
|
27
25
|
|
28
26
|
if node.attributes.size > 0 then
|
29
27
|
alist = Array.new(node.attributes.size)
|
@@ -35,10 +33,15 @@ class XMLtoHAML
|
|
35
33
|
attributex = '{' + alist.join(",") + '} '
|
36
34
|
end
|
37
35
|
|
38
|
-
buffer += attributex + node.text if not node.text.nil?
|
36
|
+
buffer += "%s" % [attributex + node.text] if not node.text.nil?
|
37
|
+
buffer += "\n"
|
39
38
|
buffer += xml_to_haml(node, indent + ' ')
|
39
|
+
|
40
40
|
buffer
|
41
41
|
end
|
42
|
+
|
43
|
+
buffer.join
|
42
44
|
end
|
43
45
|
|
44
46
|
end
|
47
|
+
|