nokolexbor 0.3.0-x86-mingw32 → 0.3.2-x86-mingw32

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: 59eed5e04583c0f0fa59ccb85f2ed4f642c2e28b29d775f8c2b6c068e49639da
4
- data.tar.gz: 85688453cd6f42494f5c00e65bba66f5ee1cbd66739fe11a3dbb9651ea650e26
3
+ metadata.gz: ab3000358a691830b406aaa6144934f7c92a7c368b19b46d34288ef58e84c080
4
+ data.tar.gz: d9d12df4eab59e9d0ec351bea52a9295eaee9f9066142b5450d5b4557fa98d0b
5
5
  SHA512:
6
- metadata.gz: '0490ef2f994f8481afb5b1f83e0f867b3a983a42706c5437ef7f3c597261d08018fb4fe6370995bf222c042b88d416bb09e8d7d817dae10fb2158a49d318cc8a'
7
- data.tar.gz: c81b0320cf1888bcb2662b8a18533e37e2548e687f43299bef0fd015da840194bb593219906e9ae8197d6257836674eafc0557e6dda1f7fa00e71e5ad4d4ee97
6
+ metadata.gz: 90d08634350f0e3de69b38eee35442e8bcf0948a01b8e49df933f84c5b9adba4dd0c9ecafe9b323de4bdd3a599269b9e88195d65bd2b6d448cdf2f3a9dd2b26e
7
+ data.tar.gz: e9e9d4199625432f0fbd6a353bad90b1c651db903a6edf87b4192056bfc9520bcd5e2373e40f3640d7bbdf124b274ee3da84a931d16856fb9e04d7b3ed55ac10
Binary file
Binary file
Binary file
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.0'
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.0
4
+ version: 0.3.2
5
5
  platform: x86-mingw32
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