xml-to-haml 0.1.0
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 +38 -0
- metadata +55 -0
data/lib/xml-to-haml.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# file: xml-to-haml.rb
|
4
|
+
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
class XMLtoHAML
|
8
|
+
include REXML
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
doc = Document.new(s)
|
12
|
+
xml_to_haml(doc)
|
13
|
+
end
|
14
|
+
|
15
|
+
def xml_to_haml(nodex, indent ='')
|
16
|
+
|
17
|
+
nodex.elements.each do |node|
|
18
|
+
|
19
|
+
attributex = ' '
|
20
|
+
buffer = indent + '%' + node.name
|
21
|
+
|
22
|
+
if node.attributes.size > 0 then
|
23
|
+
alist = Array.new(node.attributes.size)
|
24
|
+
i = 0
|
25
|
+
node.attributes.each { |x, y|
|
26
|
+
alist[i] = " :#{x} => '#{y}'"
|
27
|
+
i += 1
|
28
|
+
}
|
29
|
+
attributex = '{' + alist.join(",") + '} '
|
30
|
+
end
|
31
|
+
|
32
|
+
buffer += attributex + node.text if not node.text.nil?
|
33
|
+
puts buffer
|
34
|
+
xml_to_haml(node, indent + ' ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xml-to-haml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-05-31 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/xml-to-haml.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage:
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: xml-to-haml converts an XML string to HAML
|
54
|
+
test_files: []
|
55
|
+
|