rexle 0.9.46 → 0.9.47

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.
Files changed (2) hide show
  1. data/lib/rexle.rb +19 -16
  2. metadata +2 -2
data/lib/rexle.rb CHANGED
@@ -10,6 +10,8 @@ require 'cgi'
10
10
  include REXML
11
11
 
12
12
  # modifications:
13
+ # 10-Sep-2012: bug fix: Removed code from method pretty_print in order to
14
+ # get the XML displayed properly
13
15
  # 23-Aug-2012: feature: implemented xpath function contains()
14
16
  # 17-Aug-2012: bug fix: pretty print now ignores text containing empty space
15
17
  # 16-Aug-2012: the current element's text (if its not empty) is now returned
@@ -31,19 +33,12 @@ include REXML
31
33
  # 14-Jan-2012: Implemented Rexle::Elements#each
32
34
  # 21-Dec-2011: Bug fix: xpath modified to allow querying from the actual
33
35
  # root rather than the 1st child element from the root
34
- # 04-Sep-2011: Bug fix: xpath will now only return Rexle:elements when
35
- # * is used.
36
- # 03-Sep-2011: Implemented deep_clone as well as modifying clone to function
37
- # similar to REXML.
38
- # 28-Au-2011: New line characters between elements are now preserved
39
- # 24-Jul-2011: Smybols are used for attribute keys instead of strings now
40
- # 18-Jun-2011: A Rexle document can now be added to another Rexle document
41
- # e.g. Rexle.new('<root/>').add Rexle.new "<a>123</a>"
36
+
42
37
  module XMLhelper
43
38
 
44
39
  def doc_print(children)
45
40
 
46
- body = children.empty? ? '' : scan_print(children).join
41
+ body = (children.empty? or children.is_an_empty_string? ) ? '' : scan_print(children).join
47
42
  a = self.root.attributes.to_a.map{|k,v| "%s='%s'" % [k,v]}
48
43
  "<%s%s>%s</%s>" % [self.root.name, a.empty? ? '' : ' ' + a.join(' '), body, self.root.name]
49
44
  end
@@ -65,7 +60,7 @@ module XMLhelper
65
60
  a = x.attributes.to_a.map{|k,v| "%s='%s'" % [k,v]}
66
61
  tag = x.name + (a.empty? ? '' : ' ' + a.join(' '))
67
62
 
68
- if x.value.length > 0 or x.children.length > 0 then
63
+ if x.value.length > 0 or (x.children.length > 0 and not x.children.is_an_empty_string?) then
69
64
  out = ["<%s>" % tag]
70
65
  #out << x.value unless x.value.nil? || x.value.empty?
71
66
  out << scan_print(x.children)
@@ -87,10 +82,13 @@ module XMLhelper
87
82
 
88
83
  def pretty_print(nodes, indent='0')
89
84
  indent = indent.to_i
85
+
90
86
  nodes.select(){|x| x.is_a? Rexle::Element or x.strip.length > 0}
91
87
  .map.with_index do |x, i|
88
+
92
89
  if x.is_a? Rexle::Element then
93
90
  unless x.name == '![' then
91
+ #return ["<%s/>" % x.name] if x.value = ''
94
92
  a = x.attributes.to_a.map{|k,v| "%s='%s'" % [k,v]}
95
93
  a ||= []
96
94
  tag = x.name + (a.empty? ? '' : ' ' + a.join(' '))
@@ -172,9 +170,7 @@ class Rexle
172
170
 
173
171
  def contains(raw_args)
174
172
  path, raw_val = raw_args.split(',',2)
175
- val = raw_val.strip[/^["']?.*["']?$/]
176
-
177
- puts 'path : ' + path.inspect
173
+ val = raw_val.strip[/^["']?.*["']?$/]
178
174
 
179
175
  anode = query_xpath(path)
180
176
  return unless anode
@@ -424,11 +420,18 @@ class Rexle
424
420
 
425
421
  def attributes() @attributes end
426
422
 
427
- def children()
428
- (@value.empty? ? [] : [@value]) + @child_elements
423
+ def children()
424
+
425
+ r = (@value.empty? ? [] : [@value]) + @child_elements
426
+ def r.is_an_empty_string?()
427
+ self.length == 1 and self.first == ''
428
+ end
429
+
430
+ return r
429
431
  end
430
432
 
431
- def children=(a) @child_elements = a end
433
+ def children=(a) @child_elements = a end
434
+
432
435
  def deep_clone() Rexle.new(self.xml).root end
433
436
  def clone() Element.new(@name, @value, @attributes) end
434
437
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.46
5
+ version: 0.9.47
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-09-10 00:00:00 Z
13
+ date: 2012-10-07 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rexleparser