nokolexbor 0.6.0 → 0.6.2

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: eddfccec75e5089344c81814159f243d5c46e1d747d7cb2351a8efcdc554e46e
4
- data.tar.gz: 1112c8ee0d902e2ef382f582a39e306a5a908ca03bb5b5bc6837e361663552fe
3
+ metadata.gz: 5095dc8ed38a170bab48cc78e7a7e4475657b3066cb114a46eab1d9f4ed25c36
4
+ data.tar.gz: c2a00a4ebc644dda81e0b010166063a5ad975ad7e2410739c69af2246cce560f
5
5
  SHA512:
6
- metadata.gz: 66ad9e8663b0f072a308b01e98314622fc2b920d0c3523c8fb8faa81555bf86cb45bd2c7dc230aeaf6333c6964c59d508eb97162ab88db4130eab07412297db4
7
- data.tar.gz: 60255a5d4f8beefa0b51e37480138f6c52fa0fa4f414585409f3a71cfb00ee489a734ed93a6d34689c9601d70b1101af2ab831e4c6c207e069a441c66491d668
6
+ metadata.gz: 07df8df17e08dbe9293b6f0e1f878ee70d787f3370c33a00bcf0ca71dee007a708ecf4a7b069039cb05d95e93cd741654a3bdb8a11833804f2b9f63dd5d9fb4b
7
+ data.tar.gz: 31addbc3877af1b1d814cb720c17e8130d98280d35831794e135e259b790de0c719236004c202649092366323a7e82a9175003be0116ac0267639d15fd186081
@@ -24,7 +24,20 @@ def which(cmd)
24
24
  return nil
25
25
  end
26
26
 
27
+ if !find_executable('cmake')
28
+ abort "ERROR: CMake is required to build Lexbor."
29
+ end
30
+
27
31
  cmake_flags = [ ENV["CMAKE_FLAGS"] ]
32
+
33
+ cmake_version_full = `cmake --version`
34
+ unless cmake_version_full.empty?
35
+ cmake_version = cmake_version_full[/cmake version ([0-9\.]+)/, 1]
36
+ if Gem::Version.new(cmake_version) >= Gem::Version.new('4.0')
37
+ cmake_flags << "-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
38
+ end
39
+ end
40
+
28
41
  cmake_flags << "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
29
42
  # Set system name explicitly when cross-compiling
30
43
  cmake_flags << "-DCMAKE_SYSTEM_NAME=Windows -DWIN32=1" if windows?
@@ -116,10 +129,6 @@ LEXBOR_DIR = File.join(CWD, '..', '..', 'vendor', 'lexbor')
116
129
  EXT_DIR = File.join(CWD, '..', '..', 'ext', 'nokolexbor')
117
130
  INSTALL_DIR = File.join(LEXBOR_DIR, 'dist')
118
131
 
119
- if !find_executable('cmake')
120
- abort "ERROR: CMake is required to build Lexbor."
121
- end
122
-
123
132
  Dir.chdir(LEXBOR_DIR) do
124
133
  # Patch lexbor
125
134
  Dir['../../patches/*-lexbor-*.patch'].each do |patch_file|
@@ -22,26 +22,9 @@ const rb_data_type_t nl_document_type = {
22
22
  RUBY_TYPED_FREE_IMMEDIATELY,
23
23
  };
24
24
 
25
- /**
26
- * call-seq:
27
- * parse(string_or_io) -> Document
28
- *
29
- * Parse HTML into a {Document}.
30
- *
31
- * @param string_or_io [String, #read]
32
- * The HTML to be parsed. It may be a String, or any object that
33
- * responds to #read such as an IO, or StringIO.
34
- */
35
25
  static VALUE
36
- nl_document_parse(VALUE self, VALUE rb_string_or_io)
26
+ nl_document_parse_native(VALUE self, VALUE rb_html)
37
27
  {
38
- VALUE id_read = rb_intern("read");
39
- VALUE rb_html;
40
- if (rb_respond_to(rb_string_or_io, id_read)) {
41
- rb_html = rb_funcall(rb_string_or_io, id_read, 0);
42
- } else {
43
- rb_html = rb_string_or_io;
44
- }
45
28
  const char *html_c = StringValuePtr(rb_html);
46
29
  size_t html_len = RSTRING_LEN(rb_html);
47
30
 
@@ -74,7 +57,7 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
74
57
  static VALUE
75
58
  nl_document_new(VALUE self)
76
59
  {
77
- return nl_document_parse(self, rb_str_new("", 0));
60
+ return nl_document_parse_native(self, rb_str_new("", 0));
78
61
  }
79
62
 
80
63
  lxb_dom_document_t *
@@ -136,7 +119,7 @@ void Init_nl_document(void)
136
119
  {
137
120
  cNokolexborDocument = rb_define_class_under(mNokolexbor, "Document", cNokolexborNode);
138
121
  rb_define_singleton_method(cNokolexborDocument, "new", nl_document_new, 0);
139
- rb_define_singleton_method(cNokolexborDocument, "parse", nl_document_parse, 1);
122
+ rb_define_singleton_method(cNokolexborDocument, "parse_native", nl_document_parse_native, 1);
140
123
  rb_define_method(cNokolexborDocument, "title", nl_document_get_title, 0);
141
124
  rb_define_method(cNokolexborDocument, "title=", nl_document_set_title, 1);
142
125
  rb_define_method(cNokolexborDocument, "root", nl_document_root, 0);
@@ -141,6 +141,26 @@ module Nokolexbor
141
141
  end
142
142
  end
143
143
 
144
+ # Parse HTML into a {Document}.
145
+ #
146
+ # @param string_or_io [String, #read]
147
+ # The HTML to be parsed. It may be a String, or any object that
148
+ # responds to #read such as an IO, or StringIO.
149
+ #
150
+ # @return [Document]
151
+ def self.parse(string_or_io)
152
+ html = string_or_io
153
+ if string_or_io.respond_to?(:read)
154
+ html = string_or_io.read
155
+ end
156
+
157
+ if html.respond_to?(:encoding) && html.encoding != Encoding::UTF_8
158
+ html = html.encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
159
+ end
160
+
161
+ parse_native(html)
162
+ end
163
+
144
164
  private
145
165
 
146
166
  IMPLIED_XPATH_CONTEXTS = ["//"].freeze # :nodoc:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nokolexbor
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.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.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yicheng Zhou
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-31 00:00:00.000000000 Z
11
+ date: 2025-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -523,7 +523,7 @@ licenses:
523
523
  - MIT
524
524
  metadata:
525
525
  msys2_mingw_dependencies: cmake
526
- post_install_message:
526
+ post_install_message:
527
527
  rdoc_options: []
528
528
  require_paths:
529
529
  - lib
@@ -539,7 +539,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
539
539
  version: '0'
540
540
  requirements: []
541
541
  rubygems_version: 3.0.3.1
542
- signing_key:
542
+ signing_key:
543
543
  specification_version: 4
544
544
  summary: High-performance HTML5 parser, with support for both CSS selectors and XPath.
545
545
  test_files: []