xml-smart 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/xml/smart.rb CHANGED
@@ -13,6 +13,7 @@ require File.expand_path(File.dirname(__FILE__) + '/smart_domattributeset')
13
13
  require File.expand_path(File.dirname(__FILE__) + '/smart_domattribute')
14
14
  require File.expand_path(File.dirname(__FILE__) + '/smart_domnamespaceset')
15
15
  require File.expand_path(File.dirname(__FILE__) + '/smart_domnamespace')
16
+ require File.expand_path(File.dirname(__FILE__) + '/smart_processinginstruction')
16
17
 
17
18
  module Nokogiri
18
19
  module XML
@@ -108,7 +109,7 @@ module Nokogiri
108
109
  end
109
110
 
110
111
  module XML
111
- VERSION = '0.3.3'
112
+ VERSION = '0.3.4'
112
113
  LIBXML_VERSION = Nokogiri::VERSION_INFO['libxml']['loaded']
113
114
  LOCKFILE = {
114
115
  :min_sleep => 0.25,
data/lib/xml/smart_dom.rb CHANGED
@@ -70,23 +70,25 @@ module XML
70
70
 
71
71
  def self::smart_helper(node)
72
72
  if node.instance_of? Nokogiri::XML::Element
73
- Element.new(node)
73
+ XML::Smart::Dom::Element.new(node)
74
74
  elsif node.instance_of? Nokogiri::XML::Attr
75
- Attribute.new(node)
75
+ XML::Smart::Dom::Attribute.new(node)
76
76
  elsif node.instance_of? Nokogiri::XML::NodeSet
77
- NodeSet.new(node)
77
+ XML::Smart::Dom::NodeSet.new(node)
78
78
  elsif node.instance_of?(String) || node.instance_of?(TrueClass) || node.instance_of?(FalseClass) || node.instance_of?(Float)
79
79
  node
80
80
  elsif node.instance_of? Nokogiri::XML::Text
81
- Text.new(node)
81
+ XML::Smart::Dom::Text.new(node)
82
82
  elsif node.instance_of? Nokogiri::XML::Namespace
83
- Namespace.new(node)
83
+ XML::Smart::Dom::Namespace.new(node)
84
84
  elsif node.instance_of? Nokogiri::XML::Document
85
- Dom.new(node)
85
+ XML::Smart::Dom.new(node)
86
+ elsif node.instance_of? Nokogiri::XML::ProcessingInstruction
87
+ XML::Smart::ProcessingInstruction.new(node)
86
88
  elsif node.nil?
87
89
  nil
88
90
  else
89
- Other.new(node)
91
+ XML::Smart::Dom::Other.new(node)
90
92
  end
91
93
  end
92
94
 
@@ -14,7 +14,7 @@ module XML
14
14
  end
15
15
 
16
16
  def add_helper(attrs)
17
- if attrs.length>0 && attrs[0].is_a?(String)
17
+ if attrs.length>0 && attrs[0].is_a?(String) && attrs[0][0] != '?'
18
18
  pfx = ''
19
19
  ns = nil
20
20
  attrs[0] = attrs[0].dup
@@ -58,13 +58,11 @@ module XML
58
58
  end
59
59
  end
60
60
  return [tmp,false]
61
- end
62
- if attrs.length == 1 && attrs[0].is_a?(XML::Smart::Dom::Element)
61
+ elsif attrs.length == 1 && attrs[0].is_a?(XML::Smart::Dom::Element)
63
62
  ele = attrs[0].instance_variable_get(:@element)
64
63
  same = ele.document.root.pointer_id == @element.document.root.pointer_id
65
64
  return [same ? ele : ele.dup, !same]
66
- end
67
- if attrs.length == 1 && attrs[0].is_a?(XML::Smart::Dom::NodeSet)
65
+ elsif attrs.length == 1 && attrs[0].is_a?(XML::Smart::Dom::NodeSet)
68
66
  nos = attrs[0].instance_variable_get(:@nodeset)
69
67
  if nos.length > 0
70
68
  same = nos.first.document.root.pointer_id == @element.document.root.pointer_id
@@ -77,13 +75,11 @@ module XML
77
75
  else
78
76
  return [nos, false]
79
77
  end
80
- end
81
- if attrs.length == 2 && attrs[0].is_a?(XML::Smart::Dom::Element) && (attrs[1] == XML::Smart::COPY || attrs[1] == XML::Smart::MOVE)
78
+ elsif attrs.length == 2 && attrs[0].is_a?(XML::Smart::Dom::Element) && (attrs[1] == XML::Smart::COPY || attrs[1] == XML::Smart::MOVE)
82
79
  ele = attrs[0].instance_variable_get(:@element)
83
80
  same = ele.document.root.pointer_id == @element.document.root.pointer_id
84
81
  return [attrs[1] == XML::Smart::COPY ? ele.dup : ele, !same]
85
- end
86
- if attrs.length == 2 && attrs[0].is_a?(XML::Smart::Dom::NodeSet) && (attrs[1] == XML::Smart::COPY || attrs[1] == XML::Smart::MOVE)
82
+ elsif attrs.length == 2 && attrs[0].is_a?(XML::Smart::Dom::NodeSet) && (attrs[1] == XML::Smart::COPY || attrs[1] == XML::Smart::MOVE)
87
83
  nos = attrs[0].instance_variable_get(:@nodeset)
88
84
  if nos.length > 0
89
85
  same = nos.first.document.root.pointer_id == @element.document.root.pointer_id
@@ -96,6 +92,9 @@ module XML
96
92
  else
97
93
  return [nos, false]
98
94
  end
95
+ elsif attrs.length == 2 && attrs[0].is_a?(String) && attrs[1].is_a?(String) && attrs[0][0] == '?'
96
+ tmp = Nokogiri::XML::ProcessingInstruction.new @element.document, attrs[0].sub(/./,''), attrs[1]
97
+ return [tmp,false]
99
98
  end
100
99
  return [nil, false]
101
100
  end
@@ -0,0 +1,41 @@
1
+ module XML
2
+ module Smart
3
+
4
+ class ProcessingInstruction
5
+ def initialize(element)
6
+ @element = element
7
+ end
8
+
9
+ def ===(cls); self.is_a? cls; end
10
+
11
+ def dump; @element.to_s; end
12
+
13
+ def replace_by(n)
14
+ case n
15
+ when ProcessingInstruction; ProcessingInstruction.new @element.replace(n.instance_variable_get(:@element))
16
+ else
17
+ nil
18
+ end
19
+ end
20
+
21
+ def qname; QName.new @element; end
22
+
23
+ def content; @element.content end
24
+ def content=(t); @element.content = t.to_s if t.respond_to? :to_s; end
25
+
26
+ def parent
27
+ Dom::smart_helper(@element.parent)
28
+ end
29
+ def parent?; !@element.parent.nil?; end
30
+
31
+ def path; @element.path; end
32
+
33
+ def ==(other)
34
+ return false unless other
35
+ return false unless other.respond_to?(:unique_id)
36
+ unique_id == other.unique_id
37
+ end
38
+ def unique_id; @element.pointer_id; end
39
+ end
40
+ end
41
+ end
data/test/EXAMPLE.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <test xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xml:lang="de">
2
2
  <names>
3
- <name team="0" a="3">2013-04-24 20:51:43 +0200</name>
3
+ <name team="0" a="3">2013-05-15 11:04:06 +0200</name>
4
4
  <name team="1">Jürgen</name>
5
5
  <name team="1">Michel</name>
6
6
  <name team="1">Raphi</name>
data/test/tc_pi.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require File.expand_path(::File.dirname(__FILE__) + '/../lib/xml/smart')
4
+ require File.expand_path(::File.dirname(__FILE__) + '/smartrunner.rb')
5
+
6
+ class TestAdd < MiniTest::Unit::TestCase
7
+ def test_add
8
+ doc = XML::Smart.open(::File.dirname(__FILE__) + "/EXAMPLE.xml")
9
+ pi = doc.root.add('?tobias', 'dj')
10
+ assert pi.dump == "<?tobias dj?>"
11
+ assert pi.path == "/test/processing-instruction('tobias')"
12
+ assert pi.parent? == true
13
+ assert pi.parent.unique_id == doc.root.unique_id
14
+ assert pi.qname.name == 'tobias'
15
+ assert pi.content == 'dj'
16
+ pi.content = 'vj'
17
+ assert pi.content == 'vj'
18
+
19
+ doc.root.add_before('?xsl-stylesheet', 'a="3" b="7"')
20
+ doc.root.children.delete_all!
21
+ assert doc.to_s == "<?xml version=\"1.0\"?>\n<?xsl-stylesheet a=\"3\" b=\"7\"?>\n<test xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xml:lang=\"de\">\n <?tobias vj?>\n</test>\n"
22
+ end
23
+ end
data/xml-smart.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xml-smart"
3
- s.version = "0.3.3"
3
+ s.version = "0.3.4"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "An xml library that doesn't suck - since 2004."
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-smart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-24 00:00:00.000000000 Z
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &73897900 !ruby/object:Gem::Requirement
16
+ requirement: &77763910 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *73897900
24
+ version_requirements: *77763910
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: lockfile
27
- requirement: &73897640 !ruby/object:Gem::Requirement
27
+ requirement: &77763640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *73897640
35
+ version_requirements: *77763640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: term-ansicolor
38
- requirement: &73897430 !ruby/object:Gem::Requirement
38
+ requirement: &77784950 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *73897430
46
+ version_requirements: *77784950
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &73897220 !ruby/object:Gem::Requirement
49
+ requirement: &77784700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *73897220
57
+ version_requirements: *77784700
58
58
  description: An xml library that doesn't suck (since 2004). Based on Nokogiri since
59
59
  2012. For more info check out the Documentation link below.
60
60
  email: juergen.mangler@gmail.com
@@ -71,6 +71,7 @@ files:
71
71
  - lib/xml/smart_dom.rb
72
72
  - lib/xml/smart_domelement.rb
73
73
  - lib/xml/smart_domother.rb
74
+ - lib/xml/smart_processinginstruction.rb
74
75
  - lib/xml/smart_qname.rb
75
76
  - lib/xml/XSDtoRNG.xsl
76
77
  - lib/xml/smart_domattributeset.rb
@@ -103,6 +104,7 @@ files:
103
104
  - test/tc_qname.rb
104
105
  - test/tc_todoc.rb
105
106
  - test/tc_concurrent.rb
107
+ - test/tc_pi.rb
106
108
  - test/tc_basic.rb
107
109
  - test/tc_namespace_find.rb
108
110
  - test/tc_relaxng.rb
@@ -173,6 +175,7 @@ test_files:
173
175
  - test/tc_qname.rb
174
176
  - test/tc_todoc.rb
175
177
  - test/tc_concurrent.rb
178
+ - test/tc_pi.rb
176
179
  - test/tc_basic.rb
177
180
  - test/tc_namespace_find.rb
178
181
  - test/tc_relaxng.rb