sawzall 0.1.0.pre2-x86_64-linux
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/lib/sawzall/3.2/sawzall.so +0 -0
- data/lib/sawzall/3.4/sawzall.so +0 -0
- data/lib/sawzall/extension.rb +15 -0
- data/lib/sawzall/version.rb +5 -0
- data/lib/sawzall.rb +184 -0
- data/sawzall.gemspec +46 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 52c393775e4ec6d53f6457b76bf926a2766649cd6c49321615b7207d056f1f2d
|
4
|
+
data.tar.gz: 195152a13c2046602bbf4f5e7f4499d0fd6549e9f63060f25bb4bb712af32ece
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39ae9d75e4c0aefcb976df8c04be54c6f34eb029ef12e653b354c57bf5378deca1ef41c74332f2dea31c5cb69aa8aa50246fb568984af272ca6d2c47182950d5
|
7
|
+
data.tar.gz: 9bec2ea88ca835402a6b752cb77f73e59eeb3a6c2ecf825ddcf1386f11e18c808fc634a97c2404925fef74728ebc2f44986a4fcd6c529b8cfa6e038a2c98f3e9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 David Cornu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Sawzall
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sawzall`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
15
|
+
```
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sawzall.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
Binary file
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adapted from https://github.com/gjtorikian/commonmarker/blob/c12e5cbce128fe1863b7290a2403b7b247d79d2e/lib/commonmarker/extension.rb
|
4
|
+
begin
|
5
|
+
# native precompiled gems package shared libraries in <gem_dir>/lib/sawzall/<ruby_version>
|
6
|
+
# load the precompiled extension file
|
7
|
+
ruby_version = /\d+\.\d+/.match(RUBY_VERSION)
|
8
|
+
require_relative "#{ruby_version}/sawzall"
|
9
|
+
rescue LoadError
|
10
|
+
# fall back to the extension compiled upon installation.
|
11
|
+
# use "require" instead of "require_relative" because non-native gems will place C extension files
|
12
|
+
# in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
|
13
|
+
# is in $LOAD_PATH but not necessarily relative to this file (see nokogiri#2300)
|
14
|
+
require "sawzall/sawzall"
|
15
|
+
end
|
data/lib/sawzall.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "sawzall/version"
|
4
|
+
require_relative "sawzall/extension"
|
5
|
+
|
6
|
+
module Sawzall
|
7
|
+
# Parses the given string as an HTML fragment
|
8
|
+
#
|
9
|
+
# @!method self.parse_fragment(html)
|
10
|
+
# @param html [String]
|
11
|
+
# @return [Sawzall::Document]
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Sawzall
|
15
|
+
# .parse_fragment("<h1 id='title'>Page Title</h1>")
|
16
|
+
# .select("h1")
|
17
|
+
# .first
|
18
|
+
# .attr("id") #=> "title"
|
19
|
+
|
20
|
+
# Parses the given string as a complete HTML document
|
21
|
+
#
|
22
|
+
# @!method self.parse_document(html)
|
23
|
+
# @param html [String]
|
24
|
+
# @return [Sawzall::Document]
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# html = <<~HTML
|
28
|
+
# <!doctype html>
|
29
|
+
# <html>
|
30
|
+
# <head>
|
31
|
+
# <title>Page Title</title>
|
32
|
+
# </head>
|
33
|
+
# <body>
|
34
|
+
# <h1>Heading</h1>
|
35
|
+
# </body>
|
36
|
+
# </html>
|
37
|
+
# HTML
|
38
|
+
#
|
39
|
+
# Sawzall
|
40
|
+
# .parse_document(html)
|
41
|
+
# .select("head title")
|
42
|
+
# .first
|
43
|
+
# .text #=> "Page Title"
|
44
|
+
|
45
|
+
# @!parse
|
46
|
+
# class Document
|
47
|
+
# # Returns the elements that match the given [CSS selector][mdn]
|
48
|
+
# #
|
49
|
+
# # [mdn]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors
|
50
|
+
# #
|
51
|
+
# # @example
|
52
|
+
# # doc = Sawzall.parse_fragment(<<~HTML)
|
53
|
+
# # <h1>Heading</h1>
|
54
|
+
# # <p>Paragraph 1</p>
|
55
|
+
# # <p>Paragraph 2</p>
|
56
|
+
# # HTML
|
57
|
+
# # matches = doc.select("p")
|
58
|
+
# # matches.map(&:text) #=> ["Paragraph 1", "Paragraph 2"]
|
59
|
+
# #
|
60
|
+
# # @!method select(css_selector)
|
61
|
+
# # @param css_selector [String]
|
62
|
+
# # @raise [ArgumentError] if the CSS selector is invalid
|
63
|
+
# # @return [Array<Sawzall::Element>]
|
64
|
+
#
|
65
|
+
# # Returns the document's root element
|
66
|
+
# #
|
67
|
+
# # @example
|
68
|
+
# # doc = Sawzall.parse_fragment("<h1>Heading</h1>")
|
69
|
+
# # doc.root_element.name #=> "html"
|
70
|
+
# # doc.root_element.child_elements.map(&:name) #=> ["h1"]
|
71
|
+
# #
|
72
|
+
# # @!method root_element
|
73
|
+
# # @return [Sawzall::Element]
|
74
|
+
# end
|
75
|
+
|
76
|
+
# @!parse
|
77
|
+
# class Element
|
78
|
+
# # Returns the element's name in lowercase
|
79
|
+
# #
|
80
|
+
# # @example
|
81
|
+
# # doc = Sawzall.parse_fragment("<p>Paragraph</p>")
|
82
|
+
# # doc.select("p").first.name #=> "p"
|
83
|
+
# #
|
84
|
+
# # @!method name
|
85
|
+
# # @return [String]
|
86
|
+
#
|
87
|
+
# # Returns the element's outer HTML
|
88
|
+
# #
|
89
|
+
# # @example
|
90
|
+
# # doc = Sawzall.parse_fragment(<<~HTML)
|
91
|
+
# # <section>
|
92
|
+
# # <h1>Heading</h1>
|
93
|
+
# # </section>
|
94
|
+
# # HTML
|
95
|
+
# # section = doc.select("section").first
|
96
|
+
# # section.html #=> "<section>\n<h1>Heading</h1>\n</section>"
|
97
|
+
# #
|
98
|
+
# # @!method html
|
99
|
+
# # @return [String]
|
100
|
+
#
|
101
|
+
# # Returns the element's inner HTML
|
102
|
+
# #
|
103
|
+
# # @example
|
104
|
+
# # doc = Sawzall.parse_fragment(<<~HTML)
|
105
|
+
# # <section>
|
106
|
+
# # <h1>Heading</h1>
|
107
|
+
# # </section>
|
108
|
+
# # HTML
|
109
|
+
# # section = doc.select("section").first
|
110
|
+
# # section.inner_html #=> "\n<h1>Heading</h1>\n"
|
111
|
+
# #
|
112
|
+
# # @!method inner_html
|
113
|
+
# # @return [String]
|
114
|
+
#
|
115
|
+
# # Returns the given attribute's value or `nil`
|
116
|
+
# #
|
117
|
+
# # @example
|
118
|
+
# # doc = Sawzall.parse_fragment("<h1 id='title'>Heading</h1>")
|
119
|
+
# # h1 = doc.select("h1").first
|
120
|
+
# # h1.attr("id") #=> "title"
|
121
|
+
# # h1.attr("class") #=> nil
|
122
|
+
# #
|
123
|
+
# # @!method attr(attribute)
|
124
|
+
# # @param attribute [String]
|
125
|
+
# # @return [String, Nil]
|
126
|
+
#
|
127
|
+
# # Returns the child elements that match the given CSS selector
|
128
|
+
# #
|
129
|
+
# # https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors
|
130
|
+
# #
|
131
|
+
# # @example
|
132
|
+
# # doc = Sawzall.parse_fragment(<<~HTML)
|
133
|
+
# # <div class="container">
|
134
|
+
# # <div>inner div 1</div>
|
135
|
+
# # <div>inner div 2</div>
|
136
|
+
# # </div>
|
137
|
+
# # HTML
|
138
|
+
# # container = doc.select(".container").first
|
139
|
+
# # matches = container.select("div")
|
140
|
+
# # matches.map(&:text) #=> ["inner div 1", "inner div 2"]
|
141
|
+
# #
|
142
|
+
# # @!method select(css_selector)
|
143
|
+
# # @param css_selector [String]
|
144
|
+
# # @raise [ArgumentError] if the CSS selector is invalid
|
145
|
+
# # @return [Array<Sawzall::Element>]
|
146
|
+
#
|
147
|
+
# # Returns the element's child elements
|
148
|
+
# #
|
149
|
+
# # @example
|
150
|
+
# # doc = Sawzall.parse_fragment(<<~HTML)
|
151
|
+
# # <div id="parent">
|
152
|
+
# # <div id="child1">
|
153
|
+
# # <div id="grandchild1"></div>
|
154
|
+
# # </div>
|
155
|
+
# # <div id="child2"></div>
|
156
|
+
# # </div>
|
157
|
+
# # HTML
|
158
|
+
# # parent = doc.select("#parent").first
|
159
|
+
# # parent
|
160
|
+
# # .child_elements
|
161
|
+
# # .map { it.attr("id") } #=> ["child1", "child2"]
|
162
|
+
# #
|
163
|
+
# # @!method child_elements
|
164
|
+
# # @return [Array<Sawzall::Element>]
|
165
|
+
#
|
166
|
+
# # Returns the element's text content using a very simplified version of the
|
167
|
+
# # `innerText` algorithm.
|
168
|
+
# #
|
169
|
+
# # https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
|
170
|
+
# #
|
171
|
+
# # @example
|
172
|
+
# # doc = Sawzall.parse_fragment(<<~HTML)
|
173
|
+
# # <ul>
|
174
|
+
# # <li>First item</li>
|
175
|
+
# # <li>Second item</li>
|
176
|
+
# # </ul>
|
177
|
+
# # HTML
|
178
|
+
# # ul = doc.select("ul").first
|
179
|
+
# # ul.text #=> "First item\nSecond item"
|
180
|
+
# #
|
181
|
+
# # @!method text
|
182
|
+
# # @return [String]
|
183
|
+
# end
|
184
|
+
end
|
data/sawzall.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/sawzall/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sawzall"
|
7
|
+
spec.version = Sawzall::VERSION
|
8
|
+
spec.authors = ["David Cornu"]
|
9
|
+
spec.email = ["me@davidcornu.com"]
|
10
|
+
|
11
|
+
spec.summary = "HTML parsing and querying with CSS selectors."
|
12
|
+
spec.description = <<~TXT
|
13
|
+
Sawzall wraps the Rust scraper library (https://github.com/rust-scraper/scraper)
|
14
|
+
to make it easy to parse HTML documents and query them with CSS selectors.
|
15
|
+
TXT
|
16
|
+
spec.homepage = "https://github.com/davidcornu/sawzall"
|
17
|
+
spec.license = "MIT"
|
18
|
+
spec.required_ruby_version = ">= 3.1.0"
|
19
|
+
spec.required_rubygems_version = ">= 3.3.11"
|
20
|
+
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
23
|
+
spec.metadata["documentation_uri"] = "https://davidcornu.github.io/sawzall/"
|
24
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
gemspec = File.basename(__FILE__)
|
28
|
+
spec.files = [
|
29
|
+
gemspec,
|
30
|
+
"README.md",
|
31
|
+
"LICENSE.txt",
|
32
|
+
"Cargo.lock",
|
33
|
+
"Cargo.toml"
|
34
|
+
]
|
35
|
+
spec.files += Dir.glob([
|
36
|
+
"ext/**/*.{rs,toml,lock,rb}",
|
37
|
+
"lib/**/*.rb",
|
38
|
+
])
|
39
|
+
|
40
|
+
spec.bindir = "exe"
|
41
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
42
|
+
spec.require_paths = ["lib"]
|
43
|
+
spec.extensions = ["ext/sawzall/extconf.rb"]
|
44
|
+
|
45
|
+
spec.add_dependency "rb_sys", "~> 0.9.111"
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sawzall
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre2
|
5
|
+
platform: x86_64-linux
|
6
|
+
authors:
|
7
|
+
- David Cornu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Sawzall wraps the Rust scraper library (https://github.com/rust-scraper/scraper)
|
15
|
+
to make it easy to parse HTML documents and query them with CSS selectors.
|
16
|
+
email:
|
17
|
+
- me@davidcornu.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- lib/sawzall.rb
|
25
|
+
- lib/sawzall/3.2/sawzall.so
|
26
|
+
- lib/sawzall/3.4/sawzall.so
|
27
|
+
- lib/sawzall/extension.rb
|
28
|
+
- lib/sawzall/version.rb
|
29
|
+
- sawzall.gemspec
|
30
|
+
homepage: https://github.com/davidcornu/sawzall
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/davidcornu/sawzall
|
35
|
+
source_code_uri: https://github.com/davidcornu/sawzall
|
36
|
+
documentation_uri: https://davidcornu.github.io/sawzall/
|
37
|
+
rubygems_mfa_required: 'true'
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.2'
|
47
|
+
- - "<"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.5.dev
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.11
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.5.23
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: HTML parsing and querying with CSS selectors.
|
60
|
+
test_files: []
|