rexle 0.9.39 → 0.9.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rexle.rb +16 -1
  2. metadata +2 -2
data/lib/rexle.rb CHANGED
@@ -10,6 +10,7 @@ require 'cgi'
10
10
  include REXML
11
11
 
12
12
  # modifications:
13
+ # 08-Aug-2012: feature: added Element#insert_before and Element#insert_after
13
14
  # 19-Jul-2012: Changed children to elements where appropriate
14
15
  # 15-Jul-2012: bug fix: self.root.value is no longer appended
15
16
  # to the body if there are no child elements
@@ -147,7 +148,7 @@ class Rexle
147
148
  include XMLhelper
148
149
 
149
150
  attr_accessor :name, :value, :parent
150
- attr_reader :child_lookup
151
+ attr_reader :child_lookup, :child_elements
151
152
 
152
153
  alias original_clone clone
153
154
 
@@ -429,6 +430,10 @@ class Rexle
429
430
  def doc_root() @rexle.root end
430
431
  def each(&blk) @child_elements.each(&blk) end
431
432
  def has_elements?() !self.elements.empty? end
433
+
434
+ def insert_after(node) insert(node, 1) end
435
+ def insert_before(node) insert(node) end
436
+
432
437
  def root() self end #@rexle.root end
433
438
 
434
439
  def text(s='')
@@ -475,6 +480,14 @@ class Rexle
475
480
  alias to_s xml
476
481
 
477
482
  private
483
+
484
+ def insert(node,offset=0)
485
+ i = parent.child_elements.index(self)
486
+ return unless i
487
+ parent.child_elements.insert(i+offset,node)
488
+ parent.child_lookup.insert(i+offset, [node.name, node.attributes, node.value])
489
+ self
490
+ end
478
491
 
479
492
  def format_condition(condition)
480
493
 
@@ -557,6 +570,8 @@ class Rexle
557
570
 
558
571
  x = raw_element
559
572
  e = @child_elements[x.last]
573
+
574
+ return unless e.is_a? Rexle::Element
560
575
  name, value = e.name, e.value if e.is_a? Rexle::Element
561
576
 
562
577
  h = x[0][1] # <-- fetch the attributes
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.39
5
+ version: 0.9.40
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-07-19 00:00:00 Z
13
+ date: 2012-08-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rexleparser