nokolexbor 0.3.1-x64-mingw-ucrt → 0.3.2-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26df5e2b997ed24918e747bbfb76a364d46a641becb773f9ded960e26a9982ac
4
- data.tar.gz: b0ccf1180dc8fd0240d987672c2a3ff01da4e363883734e326e4ce9d17800013
3
+ metadata.gz: 84dbcded2e705c7a97e6e2409e504aaa8d88f668a9a951e9d116bd80fa6187c3
4
+ data.tar.gz: 5bf9ec35839e7736e75815e5f45f0d8f516c6b8a6ab69ba17e1a29caff8e3686
5
5
  SHA512:
6
- metadata.gz: 69c121521730467e671e7b16952bf68a6bc2629e6db220f6c28b65e809ffd61fbdbcf27329fbb40920dfd4d1537b892148ee929341ef7243f95dd1d025f19644
7
- data.tar.gz: 6b8c4a60b7636e3137dccfb7acc83bd5f89888986d1fa9d0b85e57e17de32c2d93be74da2f113030d3a561bda13be4ea7b9e37b7c5abdf4d83fd1cce68fd27f0
6
+ metadata.gz: dc908e49de45ba73f0a488a8e287231bfdc25447ce1fa8d543220effdc59c9e906b3bc621959b8d0acbaf70f5a302f9039cc8baf65b4db73f1260339662f5c56
7
+ data.tar.gz: f321b363e12b9b7c30fb7fe4d8e1e581a643a2c15f6bad122bef70a6b7540eb61535a87d9ae17a1442fb4eadca0ed286365d1125ec07edccdb3472550d0fab4a
Binary file
@@ -93,5 +93,9 @@ module Nokolexbor
93
93
  head.prepend_child(element)
94
94
  end
95
95
  end
96
+
97
+ private
98
+
99
+ IMPLIED_XPATH_CONTEXTS = ["//"].freeze # :nodoc:
96
100
  end
97
101
  end
@@ -192,6 +192,16 @@ module Nokolexbor
192
192
  at_css_impl(args.join(', '))
193
193
  end
194
194
 
195
+ def nokogiri_css(*args)
196
+ rules, handler, ns, _ = extract_params(args)
197
+
198
+ nokogiri_css_internal(self, rules, handler, ns)
199
+ end
200
+
201
+ def nokogiri_at_css(*args)
202
+ nokogiri_css(*args).first
203
+ end
204
+
195
205
  def xpath(*args)
196
206
  paths, handler, ns, binds = extract_params(args)
197
207
 
@@ -299,6 +309,10 @@ module Nokolexbor
299
309
 
300
310
  private
301
311
 
312
+ def nokogiri_css_internal(node, rules, handler, ns)
313
+ xpath_internal(node, css_rules_to_xpath(rules, ns), handler, ns, nil)
314
+ end
315
+
302
316
  def xpath_internal(node, paths, handler, ns, binds)
303
317
  # document = node.document
304
318
  # return NodeSet.new(document) unless document
@@ -326,6 +340,34 @@ module Nokolexbor
326
340
  ctx.evaluate(path, handler)
327
341
  end
328
342
 
343
+ def css_rules_to_xpath(rules, ns)
344
+ rules.map { |rule| xpath_query_from_css_rule(rule, ns) }
345
+ end
346
+
347
+ def ensure_nokogiri
348
+ unless defined?(Nokogiri) && defined?(Nokogiri::CSS)
349
+ require 'nokogiri'
350
+ end
351
+ rescue LoadError
352
+ fail('nokogiri_css and nokogiri_at_css require Nokogiri to be installed')
353
+ end
354
+
355
+ def xpath_query_from_css_rule(rule, ns)
356
+ ensure_nokogiri
357
+ if defined? Nokogiri::CSS::XPathVisitor::BuiltinsConfig
358
+ visitor = Nokogiri::CSS::XPathVisitor.new(
359
+ builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::OPTIMAL,
360
+ doctype: :html4,
361
+ )
362
+ else
363
+ visitor = Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins.new
364
+ end
365
+ self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
366
+ Nokogiri::CSS.xpath_for(rule.to_s, { prefix: implied_xpath_context, ns: ns,
367
+ visitor: visitor, })
368
+ end.join(" | ")
369
+ end
370
+
329
371
  def extract_params(params)
330
372
  handler = params.find do |param|
331
373
  ![Hash, String, Symbol].include?(param.class)
@@ -344,5 +386,7 @@ module Nokolexbor
344
386
 
345
387
  [params, handler, ns, binds]
346
388
  end
389
+
390
+ IMPLIED_XPATH_CONTEXTS = [".//"].freeze
347
391
  end
348
- end
392
+ end
@@ -126,6 +126,23 @@ module Nokolexbor
126
126
  end
127
127
  end
128
128
  end
129
+
130
+ def nokogiri_css(*args)
131
+ rules, handler, ns, _ = extract_params(args)
132
+ paths = css_rules_to_xpath(rules, ns)
133
+
134
+ NodeSet.new(@document) do |set|
135
+ each do |node|
136
+ node.send(:xpath_internal, node, paths, handler, ns, nil).each do |inner_node|
137
+ set << inner_node
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ private
144
+
145
+ IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
129
146
 
130
147
  end
131
148
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nokolexbor
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokolexbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Yicheng Zhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-31 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler