nokogiri-ext 0.1.0
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 +7 -0
- data/.document +3 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +15 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.md +100 -0
- data/Rakefile +13 -0
- data/gemspec.yml +23 -0
- data/lib/nokogiri/ext/equality/attr.rb +25 -0
- data/lib/nokogiri/ext/equality/element.rb +35 -0
- data/lib/nokogiri/ext/equality/node.rb +24 -0
- data/lib/nokogiri/ext/equality/text.rb +25 -0
- data/lib/nokogiri/ext/equality.rb +4 -0
- data/lib/nokogiri/ext/traverse_count/document.rb +26 -0
- data/lib/nokogiri/ext/traverse_count/node.rb +25 -0
- data/lib/nokogiri/ext/traverse_count.rb +2 -0
- data/lib/nokogiri/ext/traverse_text.rb +33 -0
- data/lib/nokogiri/ext/version.rb +6 -0
- data/lib/nokogiri/ext/xml.rb +5 -0
- data/lib/nokogiri/ext.rb +4 -0
- data/nokogiri-ext.gemspec +61 -0
- data/spec/equality_spec.rb +24 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/traverse_count_spec.rb +14 -0
- data/spec/traverse_text_spec.rb +18 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae753cd9a2d54f2efbe4d3fb749b082a7d697b679d182dfcd402629ffb47037b
|
4
|
+
data.tar.gz: b502556e6d5e95c25094b76641093bd955d88d2e514f72237a11c6c051e4f47d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16e7b8ec620e311170ad0dd2e3e9879d84f5ab9f375ad6888e8eb329a646e98ef823acaeebca266b3d417733ba1fa904d91e1f01543393135fffbeb7f29ceffe
|
7
|
+
data.tar.gz: '092d85d344cee2e9b1839882432042bb21523268fd944847bf0424f5bdb3e64a1446ce5d25e1cb21971170be18d2035257c8b47b3582b067d3676b241bd28433'
|
data/.document
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [ push, pull_request ]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
tests:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby:
|
12
|
+
- 2.6
|
13
|
+
- 2.7
|
14
|
+
- '3.0'
|
15
|
+
- 3.1
|
16
|
+
- jruby
|
17
|
+
- truffleruby
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install --jobs 4 --retry 3
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "nokogiri-ext Documentation" --protected --quiet
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
### 0.1.0 / 2022-01-28
|
2
|
+
|
3
|
+
* Initial release:
|
4
|
+
* Requires [Ruby] >= 2.6.0
|
5
|
+
* Requires [nokogiri] ~> 1.0
|
6
|
+
* Added `nokogiri/ext/equality` which adds a `==` operator to
|
7
|
+
{Nokogiri::XML::Element}, {Nokogiri::XML::Attr}, {Nokogiri::XML::Text},
|
8
|
+
{Nokogiri::XML::Node}.
|
9
|
+
* Added `nokogiri/ext/traverse_count` which adds a `traverse_count` method to
|
10
|
+
{Nokogiri::XML::Document} and {Nokogiri::XML::Node}.
|
11
|
+
* Added `nokogiri/ext/traverse_text` which adds the
|
12
|
+
{Nokogiri::XML::Node#traverse_text} method.
|
13
|
+
|
14
|
+
[Ruby]: https://www.ruby-lang.org/
|
15
|
+
[nokogiri]: https://github.com/sparklemotion/nokogiri#readme
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'rake'
|
7
|
+
gem 'rubygems-tasks', '~> 0.2'
|
8
|
+
|
9
|
+
gem 'rspec', '~> 3.0'
|
10
|
+
gem 'simplecov', '~> 0.20'
|
11
|
+
|
12
|
+
gem 'redcarpet', platform: :mri
|
13
|
+
gem 'kramdown'
|
14
|
+
gem 'yard', '~> 0.9'
|
15
|
+
gem 'yard-spellcheck', require: false
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009-2022 Hal Brodigan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# nokogiri-ext
|
2
|
+
|
3
|
+
[](https://github.com/postmodern/nokogiri-ext/actions/workflows/ruby.yml)
|
4
|
+
[](https://badge.fury.io/rb/fake_io)
|
5
|
+
|
6
|
+
* [Source](https://github.com/postmodern/nokogiri-ext)
|
7
|
+
* [Issues](https://github.com/postmodern/nokogiri-ext/issues)
|
8
|
+
* [Documentation](http://rubydoc.info/gems/fake_io/frames)
|
9
|
+
|
10
|
+
## Description
|
11
|
+
|
12
|
+
nokogiri-ext is a collection of useful extensions to [nokogiri].
|
13
|
+
|
14
|
+
## Features
|
15
|
+
|
16
|
+
* Adds an `==` method to {Nokogiri::XML::Element}, {Nokogiri::XML::Attr},
|
17
|
+
{Nokogiri::XML::Text}, {Nokogiri::XML::Node}.
|
18
|
+
* Adds a `traverse_count` method to {Nokogiri::XML::Document} and
|
19
|
+
{Nokogiri::XML::Node}.
|
20
|
+
* Adds the {Nokogiri::XML::Node#traverse_text} method.
|
21
|
+
|
22
|
+
## Requirements
|
23
|
+
|
24
|
+
* [Ruby] >= 2.6.0
|
25
|
+
* [nokogiri] ~> 1.0
|
26
|
+
|
27
|
+
## Install
|
28
|
+
|
29
|
+
```shell
|
30
|
+
$ gem install nokogiri-ext
|
31
|
+
```
|
32
|
+
|
33
|
+
### gemspec
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem.add_dependency 'nokogiri-ext', '~> 1.0'
|
37
|
+
```
|
38
|
+
|
39
|
+
### Gemfile
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
gem 'nokogiri-ext', '~> 1.0'
|
43
|
+
```
|
44
|
+
|
45
|
+
## Examples
|
46
|
+
|
47
|
+
### equality
|
48
|
+
|
49
|
+
Compare the contents of two XML/HTML elements:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'nokogiri/ext/equality'
|
53
|
+
|
54
|
+
doc1.at('//node') == doc2.at('//node')
|
55
|
+
```
|
56
|
+
|
57
|
+
Comparing the contents of two XML/HTML documents:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
doc1 == doc2
|
61
|
+
```
|
62
|
+
|
63
|
+
### traverse_count
|
64
|
+
|
65
|
+
Count the total number of elements under a XML/HTML element:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'nokogiri/ext/traverse_count'
|
69
|
+
|
70
|
+
doc.at('//node').traverse_count
|
71
|
+
# => 7
|
72
|
+
```
|
73
|
+
|
74
|
+
Count the total number of elements within a XML/HTML document:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
doc.traverse_count
|
78
|
+
# => 42
|
79
|
+
```
|
80
|
+
|
81
|
+
### traverse_text
|
82
|
+
|
83
|
+
Traverses all text nodes in a XML/HTML document or node:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
require 'nokogiri/ext/traverse_text'
|
87
|
+
|
88
|
+
doc.traverse_text do |text|
|
89
|
+
puts text
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
## Copyright
|
94
|
+
|
95
|
+
Copyright (c) 2009-2022 Hal Brodigan
|
96
|
+
|
97
|
+
See {file:LICENSE.txt} for details.
|
98
|
+
|
99
|
+
[Ruby]: https://www.ruby-lang.org/
|
100
|
+
[nokogiri]: https://github.com/sparklemotion/nokogiri#readme
|
data/Rakefile
ADDED
data/gemspec.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
name: nokogiri-ext
|
2
|
+
summary: Useful extensions to nokogiri
|
3
|
+
description: A collection of useful extensions to nokogiri.
|
4
|
+
license: MIT
|
5
|
+
authors: Postmodern
|
6
|
+
email: postmodern.mod3@gmail.com
|
7
|
+
homepage: https://github.com/postmodern/nokogiri-ext#readme
|
8
|
+
has_yard: true
|
9
|
+
|
10
|
+
metadata:
|
11
|
+
documentation_uri: https://rubydoc.info/gems/fake_io
|
12
|
+
source_code_uri: https://github.com/postmodern/nokogiri-ext
|
13
|
+
bug_tracker_uri: https://github.com/postmodern/nokogiri-ext/issues
|
14
|
+
changelog_uri: https://github.com/postmodern/nokogiri-ext/blob/master/ChangeLog.md
|
15
|
+
rubygems_mfa_required: 'true'
|
16
|
+
|
17
|
+
required_ruby_version: ">= 2.6.0"
|
18
|
+
|
19
|
+
dependencies:
|
20
|
+
nokogiri: ~> 1.0
|
21
|
+
|
22
|
+
development_dependencies:
|
23
|
+
bundler: ~> 2.0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Attr < Node
|
6
|
+
|
7
|
+
#
|
8
|
+
# Determines if the attribute is similar to another attribute.
|
9
|
+
#
|
10
|
+
# @param [Nokogiri::XML::Attr] other
|
11
|
+
# The other attribute.
|
12
|
+
#
|
13
|
+
# @return [Boolean]
|
14
|
+
# Specifies if the attribute is similar, in identity or value,
|
15
|
+
# to the other attribute.
|
16
|
+
#
|
17
|
+
# @api public
|
18
|
+
#
|
19
|
+
def ==(other)
|
20
|
+
super(other) && (self.value == other.value)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Element < Node
|
6
|
+
|
7
|
+
#
|
8
|
+
# Determines if the element is similar to another element.
|
9
|
+
#
|
10
|
+
# @param [Nokogiri::XML::Element] other
|
11
|
+
# The other element.
|
12
|
+
#
|
13
|
+
# @return [Boolean]
|
14
|
+
# Specifies whether the element is equal, in identity or value, to
|
15
|
+
# another element.
|
16
|
+
#
|
17
|
+
# @api public
|
18
|
+
#
|
19
|
+
def ==(other)
|
20
|
+
return false unless super(other)
|
21
|
+
return false unless attribute_nodes.length == other.attribute_nodes.length
|
22
|
+
|
23
|
+
(0...attribute_nodes.length).each do |index|
|
24
|
+
attr1 = attribute_nodes[index]
|
25
|
+
attr2 = other.attribute_nodes[index]
|
26
|
+
|
27
|
+
return false unless attr1.similar?(attr2)
|
28
|
+
end
|
29
|
+
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Node
|
6
|
+
|
7
|
+
#
|
8
|
+
# Determines if the node is similar to another node.
|
9
|
+
#
|
10
|
+
# @return [Boolean]
|
11
|
+
# Specifies whether the node is equal, in identity or value, to
|
12
|
+
# another node.
|
13
|
+
#
|
14
|
+
# @api public
|
15
|
+
#
|
16
|
+
def ==(other)
|
17
|
+
return false unless other
|
18
|
+
|
19
|
+
(self.type == other.type) && (self.name == other.name)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Text < CharacterData
|
6
|
+
|
7
|
+
#
|
8
|
+
# Determines if the text node is similar to another text node.
|
9
|
+
#
|
10
|
+
# @param [Nokogiri::XML::Text] other
|
11
|
+
# The other text node.
|
12
|
+
#
|
13
|
+
# @return [Boolean]
|
14
|
+
# Specifies if the text node is similar, in identity or value,
|
15
|
+
# to the other text node.
|
16
|
+
#
|
17
|
+
# @api public
|
18
|
+
#
|
19
|
+
def ==(other)
|
20
|
+
super(other) && (self.content == other.content)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Document < Node
|
6
|
+
|
7
|
+
#
|
8
|
+
# Calculates the sum of all sub-children of the document.
|
9
|
+
#
|
10
|
+
# @return [Integer]
|
11
|
+
# The total number of children and sub-children of the document.
|
12
|
+
# Returns `0` if the document has no root element.
|
13
|
+
#
|
14
|
+
# @api public
|
15
|
+
#
|
16
|
+
def traverse_count
|
17
|
+
if root
|
18
|
+
1 + root.traverse_count
|
19
|
+
else
|
20
|
+
0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Node
|
6
|
+
|
7
|
+
#
|
8
|
+
# Calculates the sum of all children of the node.
|
9
|
+
#
|
10
|
+
# @return [Integer]
|
11
|
+
# The total number of children of the node.
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
#
|
15
|
+
def traverse_count
|
16
|
+
count = 0
|
17
|
+
|
18
|
+
traverse { |node| count += 1 }
|
19
|
+
|
20
|
+
return count - 1
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
class Node
|
6
|
+
|
7
|
+
#
|
8
|
+
# Traverses all text nodes which are children of the node.
|
9
|
+
#
|
10
|
+
# @yield [node]
|
11
|
+
# A block will be passed each text node.
|
12
|
+
#
|
13
|
+
# @yieldparam [Nokogiri::XML::Text] node
|
14
|
+
# A text node.
|
15
|
+
#
|
16
|
+
# @return [Enumerator]
|
17
|
+
# If no block is given, an Enumerator object will be returned.
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
#
|
21
|
+
def traverse_text
|
22
|
+
return enum_for(:traverse_text) unless block_given?
|
23
|
+
|
24
|
+
yield self if text?
|
25
|
+
|
26
|
+
traverse do |node|
|
27
|
+
yield node if node.text?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/nokogiri/ext.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
7
|
+
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
+
|
13
|
+
require 'nokogiri/ext/version'
|
14
|
+
Nokogiri::Ext::VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
23
|
+
gem.metadata = gemspec['metadata'] if gemspec['metadata']
|
24
|
+
|
25
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
26
|
+
|
27
|
+
gem.files = `git ls-files`.split($/)
|
28
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
29
|
+
|
30
|
+
gem.executables = gemspec.fetch('executables') do
|
31
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
32
|
+
end
|
33
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
34
|
+
|
35
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
36
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
37
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
38
|
+
|
39
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
40
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
41
|
+
})
|
42
|
+
|
43
|
+
gem.requirements = gemspec['requirements']
|
44
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
45
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
46
|
+
gem.post_install_message = gemspec['post_install_message']
|
47
|
+
|
48
|
+
split = lambda { |string| string.split(/,\s*/) }
|
49
|
+
|
50
|
+
if gemspec['dependencies']
|
51
|
+
gemspec['dependencies'].each do |name,versions|
|
52
|
+
gem.add_dependency(name,split[versions])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if gemspec['development_dependencies']
|
57
|
+
gemspec['development_dependencies'].each do |name,versions|
|
58
|
+
gem.add_development_dependency(name,split[versions])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'nokogiri/ext/equality'
|
3
|
+
|
4
|
+
describe "nokogiri/ext/equality" do
|
5
|
+
before(:all) do
|
6
|
+
@doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></body></html>})
|
7
|
+
|
8
|
+
@edited_doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></body></html>})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to test if two elements are equal" do
|
12
|
+
elem1 = @doc.at('b')
|
13
|
+
elem2 = @edited_doc.at('b')
|
14
|
+
|
15
|
+
expect(elem1).to eq(elem2)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to test if two elements are not equal" do
|
19
|
+
elem1 = @doc.at('p').children.last
|
20
|
+
elem2 = @edited_doc.at('b')
|
21
|
+
|
22
|
+
expect(elem1).not_to eq(elem2)
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'nokogiri/ext/traverse_count'
|
3
|
+
|
4
|
+
describe "nokogiri/ext/traverse_count" do
|
5
|
+
before(:all) do
|
6
|
+
@doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></body></html>})
|
7
|
+
|
8
|
+
@edited_doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></body></html>})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should provide a count of all sub-children" do
|
12
|
+
expect(@doc.traverse_count).to eq(12)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'nokogiri/ext/traverse_text'
|
3
|
+
|
4
|
+
describe "nokogiri/ext/traverse_text" do
|
5
|
+
before(:all) do
|
6
|
+
@doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></body></html>})
|
7
|
+
|
8
|
+
@edited_doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></body></html>})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to traverse over every text node" do
|
12
|
+
text = []
|
13
|
+
|
14
|
+
@doc.traverse_text { |node| text << node.content }
|
15
|
+
|
16
|
+
expect(text).to eq(['test', 'This is a test', ' html ', 'page', '.'])
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nokogiri-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Postmodern
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description: A collection of useful extensions to nokogiri.
|
42
|
+
email: postmodern.mod3@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- ChangeLog.md
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.md
|
49
|
+
files:
|
50
|
+
- ".document"
|
51
|
+
- ".github/workflows/ruby.yml"
|
52
|
+
- ".gitignore"
|
53
|
+
- ".rspec"
|
54
|
+
- ".yardopts"
|
55
|
+
- ChangeLog.md
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- gemspec.yml
|
61
|
+
- lib/nokogiri/ext.rb
|
62
|
+
- lib/nokogiri/ext/equality.rb
|
63
|
+
- lib/nokogiri/ext/equality/attr.rb
|
64
|
+
- lib/nokogiri/ext/equality/element.rb
|
65
|
+
- lib/nokogiri/ext/equality/node.rb
|
66
|
+
- lib/nokogiri/ext/equality/text.rb
|
67
|
+
- lib/nokogiri/ext/traverse_count.rb
|
68
|
+
- lib/nokogiri/ext/traverse_count/document.rb
|
69
|
+
- lib/nokogiri/ext/traverse_count/node.rb
|
70
|
+
- lib/nokogiri/ext/traverse_text.rb
|
71
|
+
- lib/nokogiri/ext/version.rb
|
72
|
+
- lib/nokogiri/ext/xml.rb
|
73
|
+
- nokogiri-ext.gemspec
|
74
|
+
- spec/equality_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/traverse_count_spec.rb
|
77
|
+
- spec/traverse_text_spec.rb
|
78
|
+
homepage: https://github.com/postmodern/nokogiri-ext#readme
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata:
|
82
|
+
documentation_uri: https://rubydoc.info/gems/fake_io
|
83
|
+
source_code_uri: https://github.com/postmodern/nokogiri-ext
|
84
|
+
bug_tracker_uri: https://github.com/postmodern/nokogiri-ext/issues
|
85
|
+
changelog_uri: https://github.com/postmodern/nokogiri-ext/blob/master/ChangeLog.md
|
86
|
+
rubygems_mfa_required: 'true'
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 2.6.0
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubygems_version: 3.2.22
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Useful extensions to nokogiri
|
106
|
+
test_files: []
|