nokogiri-diff 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +8 -0
- data/lib/nokogiri/diff/version.rb +1 -1
- data/lib/nokogiri/diff/xml/document.rb +2 -2
- data/lib/nokogiri/diff/xml/node.rb +7 -7
- data/spec/diff_spec.rb +19 -8
- metadata +3 -3
data/ChangeLog.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
### 0.2.0 / 2013-04-22
|
2
|
+
|
3
|
+
* {Nokogiri::XML::Node#tdiff_each_child} now sorts attributes by name, so that
|
4
|
+
changes in attribute order is ignored. (thanks @bhollis)
|
5
|
+
* {Nokogiri::XML::Node#tdiff_equal} now supports `Nokogiri::XML::Comment`
|
6
|
+
and `Nokogiri::XML::ProcessingInstruction` objects. (thanks @bhollis)
|
7
|
+
|
1
8
|
### 0.1.2 / 2012-05-28
|
2
9
|
|
3
10
|
* Require tdiff ~> 0.3, >= 0.3.2.
|
11
|
+
* Added {Nokogiri::Diff::VERSION}.
|
4
12
|
* Replaced ore-tasks with
|
5
13
|
[rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
|
6
14
|
|
@@ -6,7 +6,7 @@ class Nokogiri::XML::Document < Nokogiri::XML::Node
|
|
6
6
|
# Overrides `tdiff` to only compare the child nodes of the document.
|
7
7
|
#
|
8
8
|
def tdiff(tree,&block)
|
9
|
-
return enum_for(
|
9
|
+
return enum_for(__method__,tree) unless block
|
10
10
|
|
11
11
|
tdiff_recursive(tree,&block)
|
12
12
|
return self
|
@@ -16,7 +16,7 @@ class Nokogiri::XML::Document < Nokogiri::XML::Node
|
|
16
16
|
# Overrides `tdiff_unordered` to only compare the child nodes of the document.
|
17
17
|
#
|
18
18
|
def tdiff_unordered(tree,&block)
|
19
|
-
return enum_for(
|
19
|
+
return enum_for(__method__,tree) unless block
|
20
20
|
|
21
21
|
tdiff_recursive_unordered(tree,&block)
|
22
22
|
return self
|
@@ -22,8 +22,10 @@ class Nokogiri::XML::Node
|
|
22
22
|
(self.name == node.name && self.value == node.value)
|
23
23
|
when Nokogiri::XML::Element, Nokogiri::XML::DTD
|
24
24
|
self.name == node.name
|
25
|
-
when Nokogiri::XML::Text
|
25
|
+
when Nokogiri::XML::Text, Nokogiri::XML::Comment
|
26
26
|
self.text == node.text
|
27
|
+
when Nokogiri::XML::ProcessingInstruction
|
28
|
+
(self.name == node.name && self.content = self.content)
|
27
29
|
else
|
28
30
|
false
|
29
31
|
end
|
@@ -46,7 +48,7 @@ class Nokogiri::XML::Node
|
|
46
48
|
#
|
47
49
|
def tdiff_each_child(node,&block)
|
48
50
|
if node.kind_of?(Nokogiri::XML::Element)
|
49
|
-
node.attribute_nodes.each(&block)
|
51
|
+
node.attribute_nodes.sort_by(&:name).each(&block)
|
50
52
|
end
|
51
53
|
|
52
54
|
node.children.each(&block)
|
@@ -80,14 +82,12 @@ class Nokogiri::XML::Node
|
|
80
82
|
# If no block was given, an Enumerator object will be returned.
|
81
83
|
#
|
82
84
|
def diff(other,options={},&block)
|
83
|
-
return enum_for(
|
85
|
+
return enum_for(__method__,other,options) unless block
|
84
86
|
|
85
87
|
if (options[:added] || options[:removed])
|
86
88
|
tdiff_unordered(other) do |change,node|
|
87
|
-
if
|
88
|
-
|
89
|
-
elsif (change == '-' && options[:removed])
|
90
|
-
yield change, node
|
89
|
+
if (change == '+' && options[:added]) then yield change, node
|
90
|
+
elsif (change == '-' && options[:removed]) then yield change, node
|
91
91
|
end
|
92
92
|
end
|
93
93
|
else
|
data/spec/diff_spec.rb
CHANGED
@@ -3,20 +3,22 @@ require 'nokogiri/diff'
|
|
3
3
|
|
4
4
|
describe "nokogiri/diff" do
|
5
5
|
let(:contents) { '<div><p>one</p></div>' }
|
6
|
-
let(:doc)
|
6
|
+
let(:doc) { Nokogiri::XML(contents) }
|
7
7
|
|
8
|
-
let(:added_text)
|
8
|
+
let(:added_text) { Nokogiri::XML('<div><p>one</p>two</div>') }
|
9
9
|
let(:added_element) { Nokogiri::XML('<div><p>one</p><p>two</p></div>') }
|
10
|
-
let(:added_attr)
|
10
|
+
let(:added_attr) { Nokogiri::XML('<div><p id="1">one</p></div>') }
|
11
|
+
let(:added_attrs) { Nokogiri::XML('<div><p id="1" class="2">one</p></div>') }
|
11
12
|
|
12
|
-
let(:changed_text)
|
13
|
-
let(:changed_element)
|
14
|
-
let(:changed_attr_name)
|
13
|
+
let(:changed_text) { Nokogiri::XML('<div><p>two</p></div>') }
|
14
|
+
let(:changed_element) { Nokogiri::XML('<div><span>one</span></div>') }
|
15
|
+
let(:changed_attr_name) { Nokogiri::XML('<div><p i="1">one</p></div>') }
|
15
16
|
let(:changed_attr_value) { Nokogiri::XML('<div><p id="2">one</p></div>') }
|
17
|
+
let(:changed_attr_order) { Nokogiri::XML('<div><p class="2" id="1">one</p></div>') }
|
16
18
|
|
17
|
-
let(:removed_text)
|
19
|
+
let(:removed_text) { Nokogiri::XML('<div><p></p>two</div>') }
|
18
20
|
let(:removed_element) { Nokogiri::XML('<div></div>') }
|
19
|
-
let(:removed_attr)
|
21
|
+
let(:removed_attr) { Nokogiri::XML('<div><p>one</p></div>') }
|
20
22
|
|
21
23
|
it "should add #diff to Nokogiri::XML::Docuemnt" do
|
22
24
|
doc.should respond_to(:diff)
|
@@ -92,6 +94,12 @@ describe "nokogiri/diff" do
|
|
92
94
|
changes[4][1].should == added_element.at('//p[2]/text()')
|
93
95
|
end
|
94
96
|
|
97
|
+
it "should ignore when attribute order changes" do
|
98
|
+
changes = added_attrs.at('p').diff(changed_attr_order.at('p')).to_a
|
99
|
+
|
100
|
+
changes.all? { |change| change[0] == ' ' }.should be_true
|
101
|
+
end
|
102
|
+
|
95
103
|
it "should determine when attributes are added" do
|
96
104
|
changes = doc.at('p').diff(added_attr.at('p')).to_a
|
97
105
|
|
@@ -206,6 +214,9 @@ describe "nokogiri/diff" do
|
|
206
214
|
changes[2][1].should == added_element.at('//p[2]')
|
207
215
|
end
|
208
216
|
|
217
|
+
it "should ignore when attributes change order" do
|
218
|
+
end
|
219
|
+
|
209
220
|
it "should determine when attributes are removed" do
|
210
221
|
changes = added_attr.at('div').diff(removed_attr.at('div')).to_a
|
211
222
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tdiff
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.8.
|
149
|
+
rubygems_version: 1.8.25
|
150
150
|
signing_key:
|
151
151
|
specification_version: 3
|
152
152
|
summary: Calculate the differences between two XML/HTML documents.
|