nokogiri-diff-0.2.0/0000755000175600017570000000000012626261277013314 5ustar pravipravinokogiri-diff-0.2.0/spec/0000755000175600017570000000000012626261277014246 5ustar pravipravinokogiri-diff-0.2.0/spec/spec_helper.rb0000644000175600017570000000004612626261277017064 0ustar pravipravigem 'rspec', '~> 2.4' require 'rspec' nokogiri-diff-0.2.0/spec/diff_spec.rb0000644000175600017570000002064212626261277016521 0ustar pravipravirequire 'spec_helper' require 'nokogiri/diff' describe "nokogiri/diff" do let(:contents) { '

one

' } let(:doc) { Nokogiri::XML(contents) } let(:added_text) { Nokogiri::XML('

one

two
') } let(:added_element) { Nokogiri::XML('

one

two

') } let(:added_attr) { Nokogiri::XML('

one

') } let(:added_attrs) { Nokogiri::XML('

one

') } let(:changed_text) { Nokogiri::XML('

two

') } let(:changed_element) { Nokogiri::XML('
one
') } let(:changed_attr_name) { Nokogiri::XML('

one

') } let(:changed_attr_value) { Nokogiri::XML('

one

') } let(:changed_attr_order) { Nokogiri::XML('

one

') } let(:removed_text) { Nokogiri::XML('

two
') } let(:removed_element) { Nokogiri::XML('
') } let(:removed_attr) { Nokogiri::XML('

one

') } it "should add #diff to Nokogiri::XML::Docuemnt" do doc.should respond_to(:diff) end it "should add #diff to Nokogiri::XML::Element" do added_element.at('div').should respond_to(:diff) end it "should add #diff to Nokogiri::XML::Text" do added_text.at('p/text()').should respond_to(:diff) end it "should add #diff to Nokogiri::XML::Attr" do added_attr.at('p/@id').should respond_to(:diff) end it "should not compare the Document objects" do change = doc.diff(doc).first change[0].should == ' ' change[1].should == doc.root end it "should determine when two different documents are identical" do doc.diff(Nokogiri::XML(contents)).all? { |change,node| change == ' ' }.should == true end it "should search down within Nokogiri::XML::Document objects" do doc.diff(changed_text).any? { |change,node| change != ' ' }.should == true end it "should determine when text nodes are added" do changes = doc.at('div').diff(added_text.at('div')).to_a changes.length.should == 4 changes[0][0].should == ' ' changes[0][1].should == doc.at('div') changes[1][0].should == ' ' changes[1][1].should == doc.at('//p') changes[2][0].should == '+' changes[2][1].should == added_text.at('//div/text()') changes[3][0].should == ' ' changes[3][1].should == doc.at('//p/text()') end it "should determine when elements are added" do changes = doc.at('div').diff(added_element.at('div')).to_a changes.length.should == 5 changes[0][0].should == ' ' changes[0][1].should == doc.at('div') changes[1][0].should == '+' changes[1][1].should == added_element.at('//p[1]') changes[2][0].should == ' ' changes[2][1].should == doc.at('//p') changes[3][0].should == '-' changes[3][1].should == doc.at('//p/text()') changes[4][0].should == '+' changes[4][1].should == added_element.at('//p[2]/text()') end it "should ignore when attribute order changes" do changes = added_attrs.at('p').diff(changed_attr_order.at('p')).to_a changes.all? { |change| change[0] == ' ' }.should be_true end it "should determine when attributes are added" do changes = doc.at('p').diff(added_attr.at('p')).to_a changes.length.should == 3 changes[0][0].should == ' ' changes[0][1].should == doc.at('p') changes[1][0].should == '+' changes[1][1].should == added_attr.at('//p/@id') changes[2][0].should == ' ' changes[2][1].should == doc.at('//p/text()') end it "should determine when text nodes differ" do changes = doc.at('p').diff(changed_text.at('p')).to_a changes.length.should == 3 changes[0][0].should == ' ' changes[0][1].should == doc.at('p') changes[1][0].should == '-' changes[1][1].should == doc.at('//p/text()') changes[2][0].should == '+' changes[2][1].should == changed_text.at('//p/text()') end it "should determine when element names differ" do changes = doc.at('div').diff(changed_element.at('div')).to_a changes.length.should == 3 changes[0][0].should == ' ' changes[0][1].should == doc.at('div') changes[1][0].should == '-' changes[1][1].should == doc.at('p') changes[2][0].should == '+' changes[2][1].should == changed_element.at('span') end it "should determine when attribute names differ" do changes = added_attr.at('p').diff(changed_attr_name.at('p')).to_a changes.length.should == 4 changes[0][0].should == ' ' changes[0][1].should == added_attr.at('p') changes[1][0].should == '-' changes[1][1].should == added_attr.at('//p/@id') changes[2][0].should == '+' changes[2][1].should == changed_attr_name.at('//p/@i') changes[3][0].should == ' ' changes[3][1].should == added_attr.at('//p/text()') end it "should determine when attribute values differ" do changes = added_attr.at('p').diff(changed_attr_value.at('p')).to_a changes.length.should == 4 changes[0][0].should == ' ' changes[0][1].should == added_attr.at('p') changes[1][0].should == '-' changes[1][1].should == added_attr.at('//p/@id') changes[2][0].should == '+' changes[2][1].should == changed_attr_value.at('//p/@id') changes[3][0].should == ' ' changes[3][1].should == added_attr.at('//p/text()') end it "should determine when text nodes are removed" do changes = added_text.at('div').diff(removed_text.at('div')).to_a changes.length.should == 4 changes[0][0].should == ' ' changes[0][1].should == added_text.at('div') changes[1][0].should == ' ' changes[1][1].should == added_text.at('p') changes[2][0].should == ' ' changes[2][1].should == added_text.at('//div/text()') changes[3][0].should == '-' changes[3][1].should == added_text.at('//p/text()') end it "should determine when elements are removed" do changes = added_element.at('div').diff(removed_element.at('div')).to_a changes.length.should == 3 changes[0][0].should == ' ' changes[0][1].should == added_element.at('div') changes[1][0].should == '-' changes[1][1].should == added_element.at('//p[1]') changes[2][0].should == '-' changes[2][1].should == added_element.at('//p[2]') end it "should ignore when attributes change order" do end it "should determine when attributes are removed" do changes = added_attr.at('div').diff(removed_attr.at('div')).to_a changes.length.should == 4 changes[0][0].should == ' ' changes[0][1].should == added_attr.at('div') changes[1][0].should == ' ' changes[1][1].should == added_attr.at('p') changes[2][0].should == '-' changes[2][1].should == added_attr.at('//p/@id') changes[3][0].should == ' ' changes[3][1].should == added_attr.at('//p/text()') end context ":added" do it "should determine only when text nodes are added" do changes = doc.at('div').diff(added_text.at('div'), :added => true).to_a changes.length.should == 1 changes[0][0].should == '+' changes[0][1].should == added_text.at('//div/text()') end it "should determine only when elements are added" do changes = doc.at('div').diff(added_element.at('div'), :added => true).to_a changes.length.should == 1 changes[0][0].should == '+' changes[0][1].should == added_element.at('//div/p[2]') end it "should determine only when attributes are added" do changes = doc.at('div').diff(added_attr.at('div'), :added => true).to_a changes.length.should == 1 changes[0][0].should == '+' changes[0][1].should == added_attr.at('//p/@id') end end context ":removed" do it "should determine only when text nodes are removed" do changes = doc.at('div').diff(removed_text.at('div'), :removed => true).to_a changes.length.should == 1 changes[0][0].should == '-' changes[0][1].should == doc.at('//p/text()') end it "should determine only when elements are removed" do changes = doc.at('div').diff(removed_element.at('div'), :removed => true).to_a changes.length.should == 1 changes[0][0].should == '-' changes[0][1].should == doc.at('//div/p') end it "should determine only when attributes are removed" do changes = added_attr.at('div').diff(removed_attr.at('div'), :removed => true).to_a changes.length.should == 1 changes[0][0].should == '-' changes[0][1].should == added_attr.at('//p/@id') end end end nokogiri-diff-0.2.0/LICENSE.txt0000644000175600017570000000204512626261277015140 0ustar pravipraviCopyright (c) 2010-2012 Hal Brodigan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. nokogiri-diff-0.2.0/.rspec0000644000175600017570000000004012626261277014423 0ustar pravipravi--colour --format documentation nokogiri-diff-0.2.0/ChangeLog.md0000644000175600017570000000150612626261277015467 0ustar pravipravi### 0.2.0 / 2013-04-22 * {Nokogiri::XML::Node#tdiff_each_child} now sorts attributes by name, so that changes in attribute order is ignored. (thanks @bhollis) * {Nokogiri::XML::Node#tdiff_equal} now supports `Nokogiri::XML::Comment` and `Nokogiri::XML::ProcessingInstruction` objects. (thanks @bhollis) ### 0.1.2 / 2012-05-28 * Require tdiff ~> 0.3, >= 0.3.2. * Added {Nokogiri::Diff::VERSION}. * Replaced ore-tasks with [rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme). ### 0.1.1 / 2012-05-09 * Require nokogiri ~> 1.5. ### 0.1.0 / 2010-11-29 * Initial release: * Performs a breadth-first comparison between children nodes. * Compares XML/HTML Elements, Attributes, Text nodes and DTD nodes. * Allows calculating differences between documents, or just enumerating the added or removed nodes. nokogiri-diff-0.2.0/.gemtest0000644000175600017570000000000012626261277014753 0ustar pravipravinokogiri-diff-0.2.0/.document0000644000175600017570000000003412626261277015130 0ustar pravipravi- ChangeLog.md LICENSE.txt nokogiri-diff-0.2.0/README.md0000644000175600017570000000377712626261277014611 0ustar pravipravi# nokogiri-diff * [Source](https://github.com/postmodern/nokogiri-diff) * [Issues](https://github.com/postmodern/nokogiri-diff/issues) * [Documentation](http://rubydoc.info/gems/nokogiri-diff/frames) * [Email](mailto:postmodern.mod3 at gmail.com) ## Description nokogiri-diff adds the ability to calculate the differences (added or removed nodes) between two XML/HTML documents. ## Features * Performs a breadth-first comparison between children nodes. * Compares XML/HTML Elements, Attributes, Text nodes and DTD nodes. * Allows calculating differences between documents, or just enumerating the added or removed nodes. ## Examples Enumerate over the the differences between two HTML documents: require 'nokogiri/diff' doc1 = Nokogiri::HTML('

one

two
') doc2 = Nokogiri::HTML('

one

three

') doc1.diff(doc2) do |change,node| puts "#{change} #{node.to_html}".ljust(30) + node.parent.path end #
#

one

two
/ #

one

/div # - two /div # + /div # +

three

/div # + id="1" /div/p[1] # one /div/p Only find the added nodes: doc1.diff(doc2, :added => true) do |change,node| puts node.to_html.ljust(30) + node.parent.path end # /div #

three

/div # id="1" /div/p[1] Only find the removed nodes: doc1.diff(doc2, :removed => true) do |change,node| puts node.to_html.ljust(30) + node.parent.path end # two /div ## Requirements * [ruby](http://www.ruby-lang.org/) >= 1.8.7 * [tdiff](http://github.com/postmodern/tdiff) ~> 0.3, >= 0.3.2 * [nokogiri](http://nokogiri.rubyforge.org/) ~> 1.5 ## Install $ gem install nokogiri-diff ## Copyright Copyright (c) 2010-2012 Hal Brodigan See {file:LICENSE.txt} for details. nokogiri-diff-0.2.0/gemspec.yml0000644000175600017570000000103712626261277015463 0ustar pravipraviname: nokogiri-diff summary: Calculate the differences between two XML/HTML documents. description: Nokogiri::Diff adds the ability to calculate the differences (added or removed nodes) between two XML/HTML documents. license: MIT authors: Postmodern email: postmodern.mod3@gmail.com homepage: https://github.com/postmodern/nokogiri-diff#readme has_yard: true required_ruby_version: ">= 1.8.7" dependencies: tdiff: ~> 0.3, >= 0.3.2 nokogiri: ~> 1.5 development_dependencies: rubygems-tasks: ~> 0.1 rspec: ~> 2.4 yard: ~> 0.7 nokogiri-diff-0.2.0/.yardopts0000644000175600017570000000010412626261277015155 0ustar pravipravi--markup markdown --title "nokogiri-diff Documentation" --protected nokogiri-diff-0.2.0/metadata.yml0000644000175600017570000000675712626261277015636 0ustar pravipravi--- !ruby/object:Gem::Specification name: nokogiri-diff version: !ruby/object:Gem::Version version: 0.2.0 prerelease: platform: ruby authors: - Postmodern autorequire: bindir: bin cert_chain: [] date: 2013-04-22 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: tdiff requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.3' - - ! '>=' - !ruby/object:Gem::Version version: 0.3.2 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.3' - - ! '>=' - !ruby/object:Gem::Version version: 0.3.2 - !ruby/object:Gem::Dependency name: nokogiri requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.5' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.5' - !ruby/object:Gem::Dependency name: rubygems-tasks requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.1' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.1' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.4' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.4' - !ruby/object:Gem::Dependency name: yard requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.7' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.7' description: Nokogiri::Diff adds the ability to calculate the differences (added or removed nodes) between two XML/HTML documents. email: postmodern.mod3@gmail.com executables: [] extensions: [] extra_rdoc_files: - ChangeLog.md - LICENSE.txt - README.md files: - .document - .gemtest - .gitignore - .rspec - .yardopts - ChangeLog.md - LICENSE.txt - README.md - Rakefile - gemspec.yml - lib/nokogiri/diff.rb - lib/nokogiri/diff/version.rb - lib/nokogiri/diff/xml.rb - lib/nokogiri/diff/xml/document.rb - lib/nokogiri/diff/xml/node.rb - nokogiri-diff.gemspec - spec/diff_spec.rb - spec/spec_helper.rb homepage: https://github.com/postmodern/nokogiri-diff#readme licenses: - MIT post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.8.7 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.25 signing_key: specification_version: 3 summary: Calculate the differences between two XML/HTML documents. test_files: [] nokogiri-diff-0.2.0/lib/0000755000175600017570000000000012626261277014062 5ustar pravipravinokogiri-diff-0.2.0/lib/nokogiri/0000755000175600017570000000000012626261277015703 5ustar pravipravinokogiri-diff-0.2.0/lib/nokogiri/diff/0000755000175600017570000000000012626261277016613 5ustar pravipravinokogiri-diff-0.2.0/lib/nokogiri/diff/xml/0000755000175600017570000000000012626261277017413 5ustar pravipravinokogiri-diff-0.2.0/lib/nokogiri/diff/xml/node.rb0000644000175600017570000000465312626261277020675 0ustar pravipravirequire 'nokogiri' require 'tdiff' class Nokogiri::XML::Node include TDiff include TDiff::Unordered # # Compares the XML/HTML node with another. # # @param [Nokogiri::XML::Node] node # The other XMl/HTML node. # # @return [Boolean] # Specifies whether the two nodes are equal. # def tdiff_equal(node) if (self.class == node.class) case node when Nokogiri::XML::Attr (self.name == node.name && self.value == node.value) when Nokogiri::XML::Element, Nokogiri::XML::DTD self.name == node.name when Nokogiri::XML::Text, Nokogiri::XML::Comment self.text == node.text when Nokogiri::XML::ProcessingInstruction (self.name == node.name && self.content = self.content) else false end else false end end # # Enumerates over the children of another XML/HTML node. # # @param [Nokogiri::XML::Node] node # The other XMl/HTML node. # # @yield [child] # The given block will be passed every child of the node. # # @yieldparam [Nokogiri::XML::Node] node # A child node. # def tdiff_each_child(node,&block) if node.kind_of?(Nokogiri::XML::Element) node.attribute_nodes.sort_by(&:name).each(&block) end node.children.each(&block) end # # Finds the differences between the node and another node. # # @param [Nokogiri::XML::Node] other # The other node to compare against. # # @param [Hash] options # Additional options for filtering changes. # # @option options [Boolean] :added # Yield nodes that were added. # # @option options [Boolean] :removed # Yield nodes that were removed. # # @yield [change, node] # The given block will be passed each changed node. # # @yieldparam [' ', '-', '+'] change # Indicates whether the node stayed the same, was removed or added. # # @yieldparam [Nokogiri::XML::Node] node # The changed node. # # @return [Enumerator] # If no block was given, an Enumerator object will be returned. # def diff(other,options={},&block) return enum_for(__method__,other,options) unless block if (options[:added] || options[:removed]) tdiff_unordered(other) do |change,node| if (change == '+' && options[:added]) then yield change, node elsif (change == '-' && options[:removed]) then yield change, node end end else tdiff(other,&block) end end end nokogiri-diff-0.2.0/lib/nokogiri/diff/xml/document.rb0000644000175600017570000000103712626261277021557 0ustar pravipravirequire 'nokogiri/diff/xml/node' class Nokogiri::XML::Document < Nokogiri::XML::Node # # Overrides `tdiff` to only compare the child nodes of the document. # def tdiff(tree,&block) return enum_for(__method__,tree) unless block tdiff_recursive(tree,&block) return self end # # Overrides `tdiff_unordered` to only compare the child nodes of the document. # def tdiff_unordered(tree,&block) return enum_for(__method__,tree) unless block tdiff_recursive_unordered(tree,&block) return self end end nokogiri-diff-0.2.0/lib/nokogiri/diff/version.rb0000644000175600017570000000013212626261277020621 0ustar pravipravimodule Nokogiri module Diff # nokogiri-diff version VERSION = '0.2.0' end end nokogiri-diff-0.2.0/lib/nokogiri/diff/xml.rb0000644000175600017570000000010612626261277017735 0ustar pravipravirequire 'nokogiri/diff/xml/node' require 'nokogiri/diff/xml/document' nokogiri-diff-0.2.0/lib/nokogiri/diff.rb0000644000175600017570000000007412626261277017141 0ustar pravipravirequire 'nokogiri/diff/xml' require 'nokogiri/diff/version' nokogiri-diff-0.2.0/Rakefile0000644000175600017570000000123012626261277014755 0ustar pravipravirequire 'rubygems' require 'rake' begin gem 'rubygems-tasks', '~> 0.1' require 'rubygems/tasks' Gem::Tasks.new rescue LoadError => e warn e.message warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'." end begin gem 'rspec', '~> 2.4' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new rescue LoadError => e task :spec do abort "Please run `gem install rspec` to install RSpec." end end task :test => :spec task :default => :spec begin gem 'yard', '~> 0.7' require 'yard' YARD::Rake::YardocTask.new rescue LoadError => e task :yard do abort "Please run `gem install yard` to install YARD." end end nokogiri-diff-0.2.0/nokogiri-diff.gemspec0000644000175600017570000000376312626261277017421 0ustar pravipravi# encoding: utf-8 require 'yaml' Gem::Specification.new do |gem| gemspec = YAML.load_file('gemspec.yml') gem.name = gemspec.fetch('name') gem.version = gemspec.fetch('version') do lib_dir = File.join(File.dirname(__FILE__),'lib') $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir) require 'nokogiri/diff/version' Nokogiri::Diff::VERSION end gem.summary = gemspec['summary'] gem.description = gemspec['description'] gem.licenses = Array(gemspec['license']) gem.authors = Array(gemspec['authors']) gem.email = gemspec['email'] gem.homepage = gemspec['homepage'] glob = lambda { |patterns| gem.files & Dir[*patterns] } gem.files = `git ls-files`.split($/) gem.files = glob[gemspec['files']] if gemspec['files'] gem.executables = gemspec.fetch('executables') do glob['bin/*'].map { |path| File.basename(path) } end gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.' gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb'] gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb'] gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}'] gem.require_paths = Array(gemspec.fetch('require_paths') { %w[ext lib].select { |dir| File.directory?(dir) } }) gem.requirements = gemspec['requirements'] gem.required_ruby_version = gemspec['required_ruby_version'] gem.required_rubygems_version = gemspec['required_rubygems_version'] gem.post_install_message = gemspec['post_install_message'] split = lambda { |string| string.split(/,\s*/) } if gemspec['dependencies'] gemspec['dependencies'].each do |name,versions| gem.add_dependency(name,split[versions]) end end if gemspec['development_dependencies'] gemspec['development_dependencies'].each do |name,versions| gem.add_development_dependency(name,split[versions]) end end end nokogiri-diff-0.2.0/.gitignore0000644000175600017570000000001212626261277015275 0ustar pravipravidoc/ pkg/