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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09809a9591606c3dbed1284ec8fa5dc37f1c6b10ae079b48dd3a756029dada53'
4
- data.tar.gz: 5ac65c917043c3e51b0cfcb3c8fe0d341a4aeb7e3c39a52c7e3c1d3b68c4c37d
3
+ metadata.gz: fe38fd196a394b8bbef5f09b4149bda6e1cb9f4350946508c1184aa5dee83a4a
4
+ data.tar.gz: e9d3920e6544029b1d0ca0a0319b5e5cae3fe37b198b0c0c0809cf3b1442e942
5
5
  SHA512:
6
- metadata.gz: 541756a494f6a5de668a73dbb7d28999242689cfecbb475d6940edcc0a5428a99ab6f432d0d729d2fdc1bc9e68244f0f15557e70e46d0f4a0ed2aa02671d6b9d
7
- data.tar.gz: 9375adf05e90a223fd4f0d00ca251f2b917552c58261ab2d3838fc5a339815657bc60344b322a4415a40d72cc8b410b89ff14a869a8ad5810652660c0c69f314
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 | >= 1.9.3 | >= 2.1.2 |
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 | |
@@ -1,3 +1,3 @@
1
1
  module Oga
2
- VERSION = '2.15'
2
+ VERSION = '3.0'
3
3
  end # Oga
@@ -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
@@ -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
- CACHE.get_or_set(ast) { new.compile(ast) }
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
- def initialize
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
- ns_match = input.namespace_name.eq(string(ns))
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
 
@@ -29,8 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.extensions = ['ext/c/extconf.rb']
30
30
  end
31
31
 
32
- s.has_rdoc = 'yard'
33
- s.required_ruby_version = '>= 1.9.3'
32
+ s.required_ruby_version = '>= 2.3.0'
34
33
 
35
34
  s.add_dependency 'ast'
36
35
  s.add_dependency 'ruby-ll', '~> 2.1'
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: '2.15'
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: 2018-04-11 00:00:00.000000000 Z
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: 1.9.3
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
- rubyforge_project:
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.