rexle 0.9.44 → 0.9.45
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/rexle.rb +13 -11
- metadata +2 -2
data/lib/rexle.rb
CHANGED
@@ -10,6 +10,7 @@ require 'cgi'
|
|
10
10
|
include REXML
|
11
11
|
|
12
12
|
# modifications:
|
13
|
+
# 17-Aug-2012: bug fix: pretty print now ignores text containing empty space
|
13
14
|
# 16-Aug-2012: the current element's text (if its not empty) is now returned
|
14
15
|
# from its children method
|
15
16
|
# 15-Aug-2012: feature: xpath containing child:: now supported
|
@@ -43,15 +44,15 @@ module XMLhelper
|
|
43
44
|
|
44
45
|
body = children.empty? ? '' : scan_print(children).join
|
45
46
|
a = self.root.attributes.to_a.map{|k,v| "%s='%s'" % [k,v]}
|
46
|
-
"<%s%s>%s</%s>" % [self.root.name, a.empty? ? '' : ' ' + a.join(' '),
|
47
|
+
"<%s%s>%s</%s>" % [self.root.name, a.empty? ? '' : ' ' + a.join(' '), body, self.root.name]
|
47
48
|
end
|
48
49
|
|
49
50
|
def doc_pretty_print(children)
|
50
51
|
|
51
|
-
body =
|
52
|
+
body = pretty_print(children,2).join
|
52
53
|
a = self.root.attributes.to_a.map{|k,v| "%s='%s'" % [k,v]}
|
53
54
|
ind = "\n "
|
54
|
-
"<%s%s>%s%s%s</%s>" % [self.root.name, a.empty? ? '' : ' ' + a.join(' '), ind,
|
55
|
+
"<%s%s>%s%s%s</%s>" % [self.root.name, a.empty? ? '' : ' ' + a.join(' '), ind, body, "\n", self.root.name]
|
55
56
|
end
|
56
57
|
|
57
58
|
def scan_print(nodes)
|
@@ -65,7 +66,7 @@ module XMLhelper
|
|
65
66
|
|
66
67
|
if x.value.length > 0 or x.children.length > 0 then
|
67
68
|
out = ["<%s>" % tag]
|
68
|
-
out << x.value unless x.value.nil? || x.value.empty?
|
69
|
+
#out << x.value unless x.value.nil? || x.value.empty?
|
69
70
|
out << scan_print(x.children)
|
70
71
|
out << "</%s>" % x.name
|
71
72
|
else
|
@@ -85,20 +86,21 @@ module XMLhelper
|
|
85
86
|
|
86
87
|
def pretty_print(nodes, indent='0')
|
87
88
|
indent = indent.to_i
|
88
|
-
nodes.
|
89
|
+
nodes.select(){|x| x.is_a? Rexle::Element or x.strip.length > 0}
|
90
|
+
.map.with_index do |x, i|
|
89
91
|
if x.is_a? Rexle::Element then
|
90
92
|
unless x.name == '![' then
|
91
93
|
a = x.attributes.to_a.map{|k,v| "%s='%s'" % [k,v]}
|
92
94
|
a ||= []
|
93
95
|
tag = x.name + (a.empty? ? '' : ' ' + a.join(' '))
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
+
start = i > 0 ? ("\n" + ' ' * (indent - 1)) : ''
|
98
|
+
ind1 = x.children.grep(Rexle::Element).length > 0 ?
|
99
|
+
("\n" + ' ' * indent) : ''
|
97
100
|
out = ["%s<%s>%s" % [start, tag, ind1]]
|
98
101
|
|
99
|
-
out << x.value.sub(/^[\n\s]+$/,'') unless x.value.nil? || x.value.empty?
|
100
102
|
out << pretty_print(x.children, (indent + 1).to_s.clone)
|
101
|
-
ind2 =
|
103
|
+
ind2 = ind1.length > 0 ? ("\n" + ' ' * (indent - 1)) : ''
|
102
104
|
out << "%s</%s>" % [ind2, x.name]
|
103
105
|
else
|
104
106
|
"<![CDATA[%s]]>" % x.value
|
@@ -719,7 +721,7 @@ class Rexle
|
|
719
721
|
def scan_element(name, value=nil, attributes=nil, *children)
|
720
722
|
|
721
723
|
element = Element.new(name, value, attributes, self)
|
722
|
-
|
724
|
+
|
723
725
|
if children then
|
724
726
|
children.each do |x|
|
725
727
|
if x.is_a? Array then
|
@@ -741,4 +743,4 @@ class Rexle
|
|
741
743
|
[node.name, node.text.to_s, attributes, *children]
|
742
744
|
end
|
743
745
|
|
744
|
-
end
|
746
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rexle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.45
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-17 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rexleparser
|