rexle 1.1.6 → 1.2.8
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rexle.rb +228 -141
- metadata +14 -14
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca01e7c1d603108ab5cd785b2c94bd2808918f08
|
4
|
+
data.tar.gz: 6fe511dd88951f0b344c5d232cadc1376e9af60e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11bcb67ac710645e4dfa6c99c267c5954237d799d04eec61d7cef774331e4019d8d90d9e0141be0b834405f8b5bc7e873cd672c0fe4a7e27c79abad19a3789c2
|
7
|
+
data.tar.gz: efb46f879e5299669ac5531abd8b70ab33a2e682e2cd0a4e443164a8f3b1a4011182b691bed12cc65b5452408ab8f73ac6e8c7c352f78c05a8b555fd5cd8dcd7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rexle.rb
CHANGED
@@ -11,6 +11,9 @@ require 'cgi'
|
|
11
11
|
|
12
12
|
# modifications:
|
13
13
|
|
14
|
+
# 04-Feb-2015: An xpath containing text() now calls texts() to
|
15
|
+
# return all strings within that element
|
16
|
+
# 03-Feb-2015: feature: Rexle::Element#text now includes the unescape method
|
14
17
|
# 30-Jan-2015: Rexle::Element#texts now returns the values of
|
15
18
|
# CData elements as well as strings
|
16
19
|
# 29-Jan-2015: Removed code references to REXML, as it was no longer needed.
|
@@ -135,7 +138,7 @@ module XMLhelper
|
|
135
138
|
def doc_pretty_print(children, declaration=true)
|
136
139
|
|
137
140
|
body = pretty_print(children,2).join
|
138
|
-
|
141
|
+
|
139
142
|
a = self.root.attributes.to_a.map do |k,v|
|
140
143
|
"%s='%s'" % [k,(v.is_a?(Array) ? v.join(' ') : v)]
|
141
144
|
end
|
@@ -162,33 +165,28 @@ module XMLhelper
|
|
162
165
|
nodes.map do |x|
|
163
166
|
|
164
167
|
if x.is_a? Rexle::Element then
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
"<![CDATA[%s]]>" % x.value
|
170
|
-
else
|
171
|
-
|
172
|
-
a = x.attributes.to_a.map do |k,v|
|
173
|
-
"%s='%s'" % [k,(v.is_a?(Array) ? v.join(' ') : v)]
|
174
|
-
end
|
168
|
+
|
169
|
+
a = x.attributes.to_a.map do |k,v|
|
170
|
+
"%s='%s'" % [k,(v.is_a?(Array) ? v.join(' ') : v)]
|
171
|
+
end
|
175
172
|
|
176
|
-
|
173
|
+
tag = x.name + (a.empty? ? '' : ' ' + a.join(' '))
|
177
174
|
|
178
|
-
|
179
|
-
|
180
|
-
and not x.children.is_an_empty_string?) or x.name == 'script' then
|
175
|
+
if (x.children and x.children.length > 0 \
|
176
|
+
and not x.children.is_an_empty_string?) or x.name == 'script' then
|
181
177
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
elsif x.is_a? String then
|
191
|
-
|
178
|
+
out = ["<%s>" % tag]
|
179
|
+
#out << x.value unless x.value.nil? || x.value.empty?
|
180
|
+
out << scan_print(x.children)
|
181
|
+
out << "</%s>" % x.name
|
182
|
+
else
|
183
|
+
out = ["<%s/>" % tag]
|
184
|
+
end
|
185
|
+
|
186
|
+
elsif x.is_a? String then x
|
187
|
+
elsif x.is_a? Rexle::CData then x.print
|
188
|
+
elsif x.is_a? Rexle::Comment then x.print
|
189
|
+
|
192
190
|
end
|
193
191
|
end
|
194
192
|
|
@@ -200,7 +198,8 @@ module XMLhelper
|
|
200
198
|
|
201
199
|
if x.is_a? Rexle::Element then
|
202
200
|
|
203
|
-
a = [x.name, x.
|
201
|
+
a = [x.name, x.attributes, x.value]
|
202
|
+
|
204
203
|
(a.concat(scan_to_a(x.children))) if x.children.length > 1
|
205
204
|
r << a
|
206
205
|
elsif x.is_a? String then
|
@@ -215,45 +214,42 @@ module XMLhelper
|
|
215
214
|
|
216
215
|
|
217
216
|
def pretty_print(nodes, indent='0')
|
218
|
-
indent = indent.to_i
|
219
217
|
|
218
|
+
indent = indent.to_i
|
220
219
|
return '' unless nodes
|
221
220
|
|
222
|
-
nodes.select(){|x| x.
|
221
|
+
nodes.select(){|x| x.to_s.strip.length > 0}
|
223
222
|
.map.with_index do |x, i|
|
224
223
|
|
225
224
|
if x.is_a? Rexle::Element then
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
225
|
+
|
226
|
+
#return ["<%s/>" % x.name] if x.value = ''
|
227
|
+
a = x.attributes.to_a.map do |k,v|
|
228
|
+
"%s='%s'" % [k,(v.is_a?(Array) ? v.join(' ') : v)]
|
229
|
+
end
|
230
|
+
a ||= []
|
231
|
+
tag = x.name + (a.empty? ? '' : ' ' + a.join(' '))
|
232
|
+
start = i > 0 ? ("\n" + ' ' * (indent - 1)) : ''
|
233
|
+
|
234
|
+
if (x.value and x.value.length > 0) \
|
235
|
+
or (x.children and x.children.length > 0 \
|
236
|
+
and not x.children.is_an_empty_string?) or x.name == 'script' then
|
237
|
+
|
238
|
+
ind1 = (x.children and x.children.grep(Rexle::Element).length > 0) ?
|
239
|
+
("\n" + ' ' * indent) : ''
|
239
240
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
out = ["%s<%s/>" % [start, tag]]
|
253
|
-
end
|
254
|
-
end
|
255
|
-
elsif x.is_a? String then
|
256
|
-
x.sub(/^[\n\s]+$/,'')
|
241
|
+
out = ["%s<%s>%s" % [start, tag, ind1]]
|
242
|
+
out << pretty_print(x.children, (indent + 1).to_s.clone)
|
243
|
+
ind2 = (ind1 and ind1.length > 0) ? ("\n" + ' ' * (indent - 1)) : ''
|
244
|
+
out << "%s</%s>" % [ind2, x.name]
|
245
|
+
else
|
246
|
+
out = ["%s<%s/>" % [start, tag]]
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
elsif x.is_a? String then x.sub(/^[\n\s]+$/,'')
|
251
|
+
elsif x.is_a? Rexle::CData then x.print
|
252
|
+
elsif x.is_a? Rexle::Comment then x.print
|
257
253
|
end
|
258
254
|
end
|
259
255
|
|
@@ -268,7 +264,7 @@ class Rexle
|
|
268
264
|
attr_accessor :instructions
|
269
265
|
|
270
266
|
def initialize(x=nil)
|
271
|
-
|
267
|
+
|
272
268
|
super()
|
273
269
|
|
274
270
|
@instructions = [["xml", "version='1.0' encoding='UTF-8'"]]
|
@@ -281,7 +277,7 @@ class Rexle
|
|
281
277
|
Array: proc {|x| x}
|
282
278
|
}
|
283
279
|
|
284
|
-
doc_node = ['doc',
|
280
|
+
doc_node = ['doc',{}]
|
285
281
|
|
286
282
|
|
287
283
|
@a = procs[x.class.to_s.to_sym].call(x)
|
@@ -289,6 +285,7 @@ class Rexle
|
|
289
285
|
|
290
286
|
# fetch the namespaces
|
291
287
|
@prefixes = []
|
288
|
+
|
292
289
|
if @doc.root.attributes then
|
293
290
|
|
294
291
|
xmlns = @doc.root.attributes.select {|k,v| k[/^xmlns:/]}
|
@@ -319,18 +316,21 @@ class Rexle
|
|
319
316
|
include XMLhelper
|
320
317
|
|
321
318
|
attr_accessor :name, :value, :parent
|
322
|
-
attr_reader :
|
319
|
+
attr_reader :child_elements, :doc_id, :instructions
|
323
320
|
|
324
321
|
alias original_clone clone
|
325
322
|
|
326
|
-
def initialize(name=nil, value
|
323
|
+
def initialize(name=nil, value: nil, attributes: {}, rexle: nil)
|
327
324
|
|
328
325
|
@rexle = rexle
|
329
326
|
super()
|
330
|
-
|
327
|
+
|
328
|
+
@name, @attributes = name.to_s, attributes
|
329
|
+
|
331
330
|
raise "Element name must not be blank" unless name
|
332
331
|
@child_elements = []
|
333
|
-
|
332
|
+
self.add_text value if value
|
333
|
+
|
334
334
|
end
|
335
335
|
|
336
336
|
def cdata?()
|
@@ -378,7 +378,7 @@ class Rexle
|
|
378
378
|
end
|
379
379
|
|
380
380
|
def next_element()
|
381
|
-
|
381
|
+
|
382
382
|
id = self.object_id
|
383
383
|
a = self.parent.child_elements
|
384
384
|
i = a.index {|x| x.object_id == id} + 1
|
@@ -411,8 +411,8 @@ class Rexle
|
|
411
411
|
def filter_xpath(path, rlist=[], &blk)
|
412
412
|
|
413
413
|
# is it a function
|
414
|
-
fn_match = path.match(/^(\w+)\(["']?([^\)]*)["']?\)
|
415
|
-
|
414
|
+
fn_match = path.match(/^(\w+)\(["']?([^\)]*)["']?\)(?:\[(.*)\])?$/)
|
415
|
+
|
416
416
|
# Array: proc {|x| x.flatten.compact},
|
417
417
|
if (fn_match and fn_match.captures.first[/^(attribute|@)/]) or fn_match.nil? then
|
418
418
|
|
@@ -426,7 +426,7 @@ class Rexle
|
|
426
426
|
rs.any?{|x| x == true or x == false} ? rs : rs.uniq(&:object_id)
|
427
427
|
end
|
428
428
|
},
|
429
|
-
|
429
|
+
String: proc {|x| x},
|
430
430
|
Hash: proc {|x| x},
|
431
431
|
TrueClass: proc{|x| x},
|
432
432
|
FalseClass: proc{|x| x},
|
@@ -434,6 +434,7 @@ class Rexle
|
|
434
434
|
}
|
435
435
|
bucket = []
|
436
436
|
raw_results = path.split('|').map do |xp|
|
437
|
+
|
437
438
|
query_xpath(xp.strip, bucket, &blk)
|
438
439
|
end
|
439
440
|
|
@@ -443,7 +444,13 @@ class Rexle
|
|
443
444
|
|
444
445
|
else
|
445
446
|
|
446
|
-
m, xpath_value = fn_match.captures
|
447
|
+
m, xpath_value, index = fn_match.captures
|
448
|
+
|
449
|
+
if m == 'text' then
|
450
|
+
a = texts()
|
451
|
+
return index ? a[index.to_i - 1].to_s : a
|
452
|
+
end
|
453
|
+
|
447
454
|
xpath_value.empty? ? method(m.to_sym).call : method(m.to_sym).call(xpath_value)
|
448
455
|
end
|
449
456
|
|
@@ -486,8 +493,10 @@ class Rexle
|
|
486
493
|
if raw_path[0,2] == '//' then
|
487
494
|
s = ''
|
488
495
|
elsif raw_path == 'text()'
|
496
|
+
|
489
497
|
a_path.shift
|
490
|
-
return @value
|
498
|
+
#return @value
|
499
|
+
return self.texts
|
491
500
|
else
|
492
501
|
|
493
502
|
attribute = xpath_value[/^(attribute::|@)(.*)/,2]
|
@@ -513,6 +522,7 @@ class Rexle
|
|
513
522
|
element_name = nil
|
514
523
|
else
|
515
524
|
condition = element_part
|
525
|
+
|
516
526
|
attr_search = format_condition('[' + condition + ']')
|
517
527
|
return [attribute_search(attr_search, self, self.attributes) != nil]
|
518
528
|
end
|
@@ -544,8 +554,6 @@ class Rexle
|
|
544
554
|
rs = scan_match(self, xpath_value).flatten.compact
|
545
555
|
return n ? rs[n.to_i-1] : rs
|
546
556
|
|
547
|
-
#jr101013 elsif (raw_path == '.' or raw_path == self.name) and attr_search.nil? then
|
548
|
-
#jr101013 return [self]
|
549
557
|
else
|
550
558
|
|
551
559
|
if element_name.is_a? String then
|
@@ -561,11 +569,12 @@ class Rexle
|
|
561
569
|
end
|
562
570
|
|
563
571
|
if ename != '..' then
|
564
|
-
|
565
|
-
return_elements = @
|
566
|
-
|
567
|
-
|
568
|
-
|
572
|
+
|
573
|
+
return_elements = @child_elements.map.with_index.select do |x, i|
|
574
|
+
|
575
|
+
next unless x.is_a? Rexle::Element
|
576
|
+
|
577
|
+
(x.name == ename || ename == '.') or (ename == '*')
|
569
578
|
end
|
570
579
|
|
571
580
|
if selector then
|
@@ -578,13 +587,16 @@ class Rexle
|
|
578
587
|
end
|
579
588
|
end
|
580
589
|
|
581
|
-
return_elements = ne.map {|x| [@
|
590
|
+
return_elements = ne.map {|x| [@child_elements[x], x] if x}
|
582
591
|
end
|
583
592
|
else
|
584
593
|
|
585
594
|
remaining_xpath = raw_path[/\.\.\/(.*)/,1]
|
586
595
|
# select the parent element
|
587
|
-
|
596
|
+
|
597
|
+
r2 = self.parent.xpath(remaining_xpath)
|
598
|
+
|
599
|
+
return r2
|
588
600
|
|
589
601
|
end
|
590
602
|
end
|
@@ -602,8 +614,10 @@ class Rexle
|
|
602
614
|
rlist << return_elements.map.with_index do |x,i|
|
603
615
|
|
604
616
|
rtn_element = filter(x, i+1, attr_search) do |e|
|
617
|
+
|
605
618
|
r = e.xpath(a_path.join('/') + raw_condition.to_s \
|
606
619
|
+ remaining_path, &blk)
|
620
|
+
r
|
607
621
|
#(r || e)
|
608
622
|
end
|
609
623
|
|
@@ -636,7 +650,7 @@ class Rexle
|
|
636
650
|
self.xpath(new_xpath + raw_condition.to_s + remaining_path, rlist,&blk)
|
637
651
|
end
|
638
652
|
end
|
639
|
-
|
653
|
+
|
640
654
|
rlist = rlist.flatten(1) unless not(rlist.is_a? Array) or (rlist.length > 1 and rlist[0].is_a? Array)
|
641
655
|
rlist = [rlist] if rlist.is_a? Rexle::Element
|
642
656
|
rlist = (rlist.length > 0 ? true : false) if flag_func == true
|
@@ -644,20 +658,23 @@ class Rexle
|
|
644
658
|
end
|
645
659
|
|
646
660
|
def add_element(item)
|
647
|
-
|
648
|
-
if item.is_a? Rexle::Element then
|
649
661
|
|
650
|
-
|
662
|
+
if item.is_a? String then
|
663
|
+
@child_elements << item
|
664
|
+
|
665
|
+
elsif item.is_a? Rexle::CData then
|
666
|
+
@child_elements << item
|
667
|
+
elsif item.is_a? Rexle::Element then
|
668
|
+
|
651
669
|
@child_elements << item
|
652
670
|
# add a reference from this element (the parent) to the child
|
653
671
|
item.parent = self
|
654
672
|
item
|
655
|
-
|
656
|
-
@child_lookup << item
|
657
|
-
@child_elements << item
|
673
|
+
|
658
674
|
elsif item.is_a? Rexle then
|
659
675
|
self.add_element(item.root)
|
660
676
|
end
|
677
|
+
|
661
678
|
end
|
662
679
|
|
663
680
|
def add(item)
|
@@ -704,11 +721,7 @@ class Rexle
|
|
704
721
|
end
|
705
722
|
|
706
723
|
def add_text(s)
|
707
|
-
|
708
|
-
@value = s;
|
709
|
-
else
|
710
|
-
self.add s
|
711
|
-
end
|
724
|
+
self.value = (self.value || '') + s.to_s
|
712
725
|
self
|
713
726
|
end
|
714
727
|
|
@@ -726,12 +739,14 @@ class Rexle
|
|
726
739
|
def attributes() @attributes end
|
727
740
|
|
728
741
|
def cdatas()
|
729
|
-
self.children.inject([]){|r,x| x.is_a?(Rexle::CData) ? r << x.
|
742
|
+
self.children.inject([]){|r,x| x.is_a?(Rexle::CData) ? r << x.to_s : r }
|
730
743
|
end
|
731
744
|
|
732
745
|
def children()
|
746
|
+
|
733
747
|
#return unless @value
|
734
|
-
r = (@value.to_s.empty? ? [] : [@value]) + @child_elements
|
748
|
+
#r = (@value.to_s.empty? ? [] : [@value]) + @child_elements
|
749
|
+
r = @child_elements
|
735
750
|
def r.is_an_empty_string?()
|
736
751
|
self.length == 1 and self.first == ''
|
737
752
|
end
|
@@ -741,12 +756,12 @@ class Rexle
|
|
741
756
|
|
742
757
|
#alias child_elements children
|
743
758
|
|
744
|
-
def children=(a) @child_elements = a
|
759
|
+
def children=(a) @child_elements = a if a.is_a? Array end
|
745
760
|
|
746
761
|
def deep_clone() Rexle.new(self.xml).root end
|
747
762
|
|
748
763
|
def clone()
|
749
|
-
Element.new(@name,
|
764
|
+
Element.new(@name, attributes: @attributes)
|
750
765
|
end
|
751
766
|
|
752
767
|
def delete(obj=nil)
|
@@ -757,8 +772,10 @@ class Rexle
|
|
757
772
|
e = self.element obj
|
758
773
|
e.delete if e
|
759
774
|
else
|
775
|
+
|
776
|
+
#jr010215 [@child_elements, @child_lookup].each{|x| x.delete_at i} if i
|
760
777
|
i = @child_elements.index(obj)
|
761
|
-
[@child_elements
|
778
|
+
[@child_elements].each{|x| x.delete_at i} if i
|
762
779
|
end
|
763
780
|
else
|
764
781
|
|
@@ -768,7 +785,7 @@ class Rexle
|
|
768
785
|
|
769
786
|
alias remove delete
|
770
787
|
|
771
|
-
def element(s)
|
788
|
+
def element(s)
|
772
789
|
r = self.xpath(s)
|
773
790
|
r.is_a?(Array) ? r.first : r
|
774
791
|
end
|
@@ -792,53 +809,68 @@ class Rexle
|
|
792
809
|
def map(&blk) self.children.map(&blk) end
|
793
810
|
def root() self end
|
794
811
|
|
795
|
-
def text(s='')
|
796
|
-
|
797
|
-
if s.empty? then
|
798
|
-
result = @value
|
799
|
-
else
|
800
|
-
e = self.element(s)
|
801
|
-
result = e.value if e
|
802
|
-
end
|
803
|
-
#result = CGI.unescape_html result.to_s
|
804
|
-
|
805
|
-
def result.unescape()
|
806
|
-
s = self.clone
|
807
|
-
%w(< < > > & & &pos; ').each_slice(2){|x| s.gsub!(*x)}
|
808
|
-
s
|
809
|
-
end
|
812
|
+
def text(s='')
|
810
813
|
|
811
|
-
|
814
|
+
return @child_elements.first if s.empty?
|
815
|
+
e = self.element(s)
|
816
|
+
e.text if e
|
812
817
|
end
|
813
818
|
|
814
819
|
def texts()
|
815
|
-
|
816
|
-
|
820
|
+
|
821
|
+
r = @child_elements.select do |x|
|
822
|
+
x.respond_to? :to_s
|
823
|
+
end
|
824
|
+
|
825
|
+
r.map do |x|
|
826
|
+
def x.unescape()
|
827
|
+
s = self.clone
|
828
|
+
%w(< < > > & & &pos; ').each_slice(2){|x| s.gsub!(*x)}
|
829
|
+
s
|
830
|
+
end
|
817
831
|
end
|
832
|
+
|
833
|
+
return r
|
818
834
|
end
|
819
835
|
|
820
836
|
def value()
|
821
|
-
|
837
|
+
|
838
|
+
r = @child_elements.first
|
839
|
+
|
840
|
+
def r.unescape()
|
841
|
+
s = self.clone
|
842
|
+
%w(< < > > & & &pos; ').each_slice(2){|x| s.gsub!(*x)}
|
843
|
+
s
|
844
|
+
end
|
845
|
+
|
846
|
+
return r
|
822
847
|
end
|
823
|
-
|
848
|
+
|
824
849
|
def value=(raw_s)
|
825
850
|
|
826
|
-
|
851
|
+
#@value = String.new(raw_s.to_s.clone)
|
852
|
+
val = String.new(raw_s.to_s.clone)
|
853
|
+
|
827
854
|
escape_chars = %w(& & < < > >).each_slice(2).to_a
|
828
|
-
escape_chars.each{|x|
|
829
|
-
|
855
|
+
escape_chars.each{|x| val.gsub!(*x)}
|
856
|
+
=begin
|
830
857
|
a = self.parent.instance_variable_get(:@child_lookup)
|
858
|
+
|
831
859
|
if a then
|
832
860
|
i = a.index(a.assoc(@name))
|
833
|
-
a[i][-1] =
|
861
|
+
a[i][-1] = val
|
834
862
|
self.parent.instance_variable_set(:@child_lookup, a)
|
835
863
|
end
|
864
|
+
=end
|
865
|
+
t = val
|
866
|
+
|
867
|
+
@child_elements.any? ? @child_elements[0] = t : @child_elements << t
|
836
868
|
end
|
837
869
|
|
838
870
|
alias text= value=
|
839
871
|
|
840
872
|
def to_a()
|
841
|
-
[self.name, self.
|
873
|
+
[self.name, self.attributes, self.value, *scan_to_a(self.children)]
|
842
874
|
end
|
843
875
|
|
844
876
|
def xml(options={})
|
@@ -924,6 +956,7 @@ class Rexle
|
|
924
956
|
x[1] = '==' if x[1] == '='
|
925
957
|
if x[0] != '.' then
|
926
958
|
if x[0][/\//] then
|
959
|
+
|
927
960
|
path, value = x.values_at(0,-1)
|
928
961
|
|
929
962
|
if x[0][/@\w+$/] then
|
@@ -985,13 +1018,13 @@ class Rexle
|
|
985
1018
|
|
986
1019
|
def filter(raw_element, i, attr_search, &blk)
|
987
1020
|
|
988
|
-
x = raw_element
|
989
|
-
e = @child_elements[
|
1021
|
+
x, index = raw_element
|
1022
|
+
e = @child_elements[index]
|
990
1023
|
|
991
1024
|
return unless e.is_a? Rexle::Element
|
992
1025
|
name, value = e.name, e.value if e.is_a? Rexle::Element
|
993
1026
|
|
994
|
-
h = x
|
1027
|
+
h = x.attributes # <-- fetch the attributes
|
995
1028
|
|
996
1029
|
if attr_search then
|
997
1030
|
|
@@ -1011,8 +1044,14 @@ class Rexle
|
|
1011
1044
|
block_given? ? blk.call(e) : e
|
1012
1045
|
elsif h and !h.empty? and attr_search[/^h\[/] and eval(attr_search) then
|
1013
1046
|
block_given? ? blk.call(e) : e
|
1014
|
-
elsif attr_search[/^\(name ==/] and e.
|
1047
|
+
elsif attr_search[/^\(name ==/] and e.child_elements.select {|x|
|
1048
|
+
next unless x.is_a? Rexle::Element
|
1049
|
+
name, attributes, value = x.name, x.attributes, x.value.to_s
|
1050
|
+
b = eval(attr_search)
|
1051
|
+
b}.length > 0
|
1052
|
+
|
1015
1053
|
block_given? ? blk.call(e) : e
|
1054
|
+
|
1016
1055
|
elsif attr_search[/^\(name ==/] and eval(attr_search)
|
1017
1056
|
block_given? ? blk.call(e) : e
|
1018
1057
|
elsif attr_search[/^e\.value/]
|
@@ -1034,6 +1073,7 @@ class Rexle
|
|
1034
1073
|
def recursive_scan(nodes, &blk)
|
1035
1074
|
|
1036
1075
|
nodes.each do |x|
|
1076
|
+
|
1037
1077
|
if x.is_a? Rexle::Element then
|
1038
1078
|
blk.call(x)
|
1039
1079
|
recursive_scan(x.children, &blk) if x.children.length > 0
|
@@ -1042,21 +1082,55 @@ class Rexle
|
|
1042
1082
|
end
|
1043
1083
|
|
1044
1084
|
end # -- end of element --
|
1085
|
+
|
1045
1086
|
|
1046
|
-
class CData
|
1087
|
+
class CData
|
1047
1088
|
|
1048
|
-
def initialize(
|
1049
|
-
|
1089
|
+
def initialize(val='')
|
1090
|
+
@value = val
|
1050
1091
|
end
|
1051
1092
|
|
1052
1093
|
def clone()
|
1053
|
-
CData.new(@
|
1094
|
+
CData.new(@value)
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
def inspect()
|
1098
|
+
@value.inspect
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
def print()
|
1102
|
+
"<![CDATA[%s]]>" % @value
|
1054
1103
|
end
|
1055
1104
|
|
1056
1105
|
def to_s()
|
1057
|
-
|
1106
|
+
@value
|
1058
1107
|
end
|
1059
1108
|
|
1109
|
+
def unescape()
|
1110
|
+
s = @value.clone
|
1111
|
+
%w(< < > > & & &pos; ').each_slice(2){|x| s.gsub!(*x)}
|
1112
|
+
s
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
class Comment
|
1118
|
+
|
1119
|
+
def initialize(val='')
|
1120
|
+
@value = val
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
def inspect()
|
1124
|
+
@value
|
1125
|
+
end
|
1126
|
+
|
1127
|
+
def print()
|
1128
|
+
"<!--%s-->" % @value
|
1129
|
+
end
|
1130
|
+
|
1131
|
+
def to_s()
|
1132
|
+
@value
|
1133
|
+
end
|
1060
1134
|
end
|
1061
1135
|
|
1062
1136
|
class Elements
|
@@ -1090,9 +1164,11 @@ class Rexle
|
|
1090
1164
|
else
|
1091
1165
|
a = yield
|
1092
1166
|
end
|
1093
|
-
|
1167
|
+
|
1168
|
+
doc_node = ['doc',{}]
|
1094
1169
|
@a = procs[x.class.to_s.to_sym].call(x)
|
1095
1170
|
@doc = scan_element(*(doc_node << @a))
|
1171
|
+
|
1096
1172
|
self
|
1097
1173
|
end
|
1098
1174
|
|
@@ -1106,8 +1182,7 @@ class Rexle
|
|
1106
1182
|
raise 'attempted adding second root element to document' if @doc.root
|
1107
1183
|
@doc.root.add_element(element)
|
1108
1184
|
else
|
1109
|
-
|
1110
|
-
doc_node = ['doc', '', {}, element.to_a]
|
1185
|
+
doc_node = ['doc', {}, element.to_a]
|
1111
1186
|
@doc = scan_element(*doc_node)
|
1112
1187
|
end
|
1113
1188
|
element
|
@@ -1201,21 +1276,33 @@ class Rexle
|
|
1201
1276
|
|
1202
1277
|
end
|
1203
1278
|
|
1204
|
-
def scan_element(name,
|
1205
|
-
|
1206
|
-
return CData.new(
|
1207
|
-
|
1208
|
-
element = Element.new(name,
|
1279
|
+
def scan_element(name, attributes=nil, *children)
|
1280
|
+
|
1281
|
+
return Rexle::CData.new(children.first) if name == '!['
|
1282
|
+
|
1283
|
+
element = Rexle::Element.new(name, attributes: attributes, rexle: self)
|
1209
1284
|
|
1210
1285
|
if children then
|
1286
|
+
|
1211
1287
|
children.each do |x|
|
1212
1288
|
if x.is_a? Array then
|
1289
|
+
|
1213
1290
|
element.add_element scan_element(*x)
|
1214
|
-
elsif x.is_a? String
|
1215
|
-
|
1291
|
+
elsif x.is_a? String then
|
1292
|
+
|
1293
|
+
e = if x.is_a? String then
|
1294
|
+
|
1295
|
+
x
|
1296
|
+
elsif x.name == '![' then
|
1297
|
+
|
1298
|
+
Rexle::CData.new(x)
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
element.add_element e
|
1216
1302
|
end
|
1217
1303
|
end
|
1218
1304
|
end
|
1305
|
+
|
1219
1306
|
return element
|
1220
1307
|
end
|
1221
1308
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
UOGKUMV5RApHDnC0ywMYNe0HK7qMSTP5YLKs8JUjNxpc5jl8+o3D3sHkNN4DzbQm
|
32
32
|
jVfzDZ+niKvAUA==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-
|
34
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rexleparser
|
@@ -39,40 +39,40 @@ dependencies:
|
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
42
|
+
version: '0.6'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.6.0
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0.
|
52
|
+
version: '0.6'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.6.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: dynarex-parser
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0.
|
62
|
+
version: '0.3'
|
63
63
|
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
65
|
+
version: 0.3.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
70
|
- - "~>"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '0.
|
72
|
+
version: '0.3'
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.3.0
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: polyrex-parser
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,20 +99,20 @@ dependencies:
|
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '0.
|
102
|
+
version: '0.2'
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: 0.
|
105
|
+
version: 0.2.0
|
106
106
|
type: :runtime
|
107
107
|
prerelease: false
|
108
108
|
version_requirements: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
110
|
- - "~>"
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: '0.
|
112
|
+
version: '0.2'
|
113
113
|
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: 0.
|
115
|
+
version: 0.2.0
|
116
116
|
- !ruby/object:Gem::Dependency
|
117
117
|
name: rexle-css
|
118
118
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|