oga 2.15 → 3.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 +4 -4
- data/README.md +2 -2
- data/lib/oga/version.rb +1 -1
- data/lib/oga/xml/querying.rb +11 -2
- data/lib/oga/xpath/compiler.rb +24 -4
- data/oga.gemspec +1 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe38fd196a394b8bbef5f09b4149bda6e1cb9f4350946508c1184aa5dee83a4a
|
4
|
+
data.tar.gz: e9d3920e6544029b1d0ca0a0319b5e5cae3fe37b198b0c0c0809cf3b1442e942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc397efa4eaa87451f2769e55634d9bd754e1c9788bb605f71e77dbe72b2f236f0af9d0cc942ab066036c817d1991ab44da03e213c9c0287c9d9199ed8689d0c
|
7
|
+
data.tar.gz: fdc4a670a61b755a0c0aafbb47bba2d10b253a3717794ac395f52a3e1d68fe522ee809b0513895296503d82fafef7d6132517b227610ea62db2f7e11eb38afb0
|
data/README.md
CHANGED
@@ -172,9 +172,9 @@ Querying a document using a namespace:
|
|
172
172
|
|
173
173
|
| Ruby | Required | Recommended |
|
174
174
|
|:---------|:--------------|:------------|
|
175
|
-
| MRI | >=
|
176
|
-
| Rubinius | >= 2.2 | >= 2.2.10 |
|
175
|
+
| MRI | >= 2.3.0 | >= 2.6.0 |
|
177
176
|
| JRuby | >= 1.7 | >= 1.7.12 |
|
177
|
+
| Rubinius | Not supported | |
|
178
178
|
| Maglev | Not supported | |
|
179
179
|
| Topaz | Not supported | |
|
180
180
|
| mruby | Not supported | |
|
data/lib/oga/version.rb
CHANGED
data/lib/oga/xml/querying.rb
CHANGED
@@ -10,6 +10,7 @@ module Oga
|
|
10
10
|
# document = Oga.parse_xml <<-EOF
|
11
11
|
# <people>
|
12
12
|
# <person age="25">Alice</person>
|
13
|
+
# <ns:person xmlns:ns="http://example.net">Bob</ns:person>
|
13
14
|
# </people>
|
14
15
|
# EOF
|
15
16
|
#
|
@@ -25,15 +26,23 @@ module Oga
|
|
25
26
|
#
|
26
27
|
# document.xpath('people/person[@age = $age]', 'age' => 25)
|
27
28
|
#
|
29
|
+
# Using namespace aliases:
|
30
|
+
#
|
31
|
+
# namespaces = {'example' => 'http://example.net'}
|
32
|
+
# document.xpath('people/example:person', namespaces: namespaces)
|
33
|
+
#
|
28
34
|
# @param [String] expression The XPath expression to run.
|
29
35
|
#
|
30
36
|
# @param [Hash] variables Variables to bind. The keys of this Hash should
|
31
37
|
# be String values.
|
32
38
|
#
|
39
|
+
# @param [Hash] namespaces Namespace aliases. The keys of this Hash should
|
40
|
+
# be String values.
|
41
|
+
#
|
33
42
|
# @return [Oga::XML::NodeSet]
|
34
|
-
def xpath(expression, variables = {})
|
43
|
+
def xpath(expression, variables = {}, namespaces: nil)
|
35
44
|
ast = XPath::Parser.parse_with_cache(expression)
|
36
|
-
block = XPath::Compiler.compile_with_cache(ast)
|
45
|
+
block = XPath::Compiler.compile_with_cache(ast, namespaces: namespaces)
|
37
46
|
|
38
47
|
block.call(self, variables)
|
39
48
|
end
|
data/lib/oga/xpath/compiler.rb
CHANGED
@@ -42,12 +42,16 @@ module Oga
|
|
42
42
|
# Compiles and caches an AST.
|
43
43
|
#
|
44
44
|
# @see [#compile]
|
45
|
-
def self.compile_with_cache(ast)
|
46
|
-
|
45
|
+
def self.compile_with_cache(ast, namespaces: nil)
|
46
|
+
cache_key = namespaces ? [ast, namespaces] : ast
|
47
|
+
CACHE.get_or_set(cache_key) { new(namespaces: namespaces).compile(ast) }
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
+
# @param [Hash] namespaces
|
51
|
+
def initialize(namespaces: nil)
|
50
52
|
reset
|
53
|
+
|
54
|
+
@namespaces = namespaces
|
51
55
|
end
|
52
56
|
|
53
57
|
# Resets the internal state.
|
@@ -1385,7 +1389,23 @@ module Oga
|
|
1385
1389
|
end
|
1386
1390
|
|
1387
1391
|
if ns and ns != STAR
|
1388
|
-
|
1392
|
+
if @namespaces
|
1393
|
+
ns_uri = @namespaces[ns]
|
1394
|
+
ns_match =
|
1395
|
+
if ns_uri
|
1396
|
+
input.namespace.and(input.namespace.uri.eq(string(ns_uri)))
|
1397
|
+
else
|
1398
|
+
self.false
|
1399
|
+
end
|
1400
|
+
else
|
1401
|
+
ns_match =
|
1402
|
+
if ns == XML::Element::XMLNS_PREFIX
|
1403
|
+
input
|
1404
|
+
else
|
1405
|
+
input.namespace_name.eq(string(ns))
|
1406
|
+
end
|
1407
|
+
end
|
1408
|
+
|
1389
1409
|
condition = condition ? condition.and(ns_match) : ns_match
|
1390
1410
|
end
|
1391
1411
|
|
data/oga.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '3.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yorick Peterse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -218,15 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
218
|
requirements:
|
219
219
|
- - ">="
|
220
220
|
- !ruby/object:Gem::Version
|
221
|
-
version:
|
221
|
+
version: 2.3.0
|
222
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
223
|
requirements:
|
224
224
|
- - ">="
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
|
-
|
229
|
-
rubygems_version: 2.7.4
|
228
|
+
rubygems_version: 3.0.3
|
230
229
|
signing_key:
|
231
230
|
specification_version: 4
|
232
231
|
summary: Oga is an XML/HTML parser written in Ruby.
|