sawzall 0.1.0.pre

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.
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/sawzall"]
7
+ resolver = "2"
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).
@@ -0,0 +1,15 @@
1
+ [package]
2
+ name = "sawzall"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["David Cornu <me@davidcornu.com>"]
6
+ license = "MIT"
7
+ publish = false
8
+
9
+ [lib]
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ ego-tree = "0.10.0"
14
+ magnus = { version = "0.7.1" }
15
+ scraper = { version = "0.23.1", features = ["atomic"] }
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("sawzall/sawzall")
@@ -0,0 +1,196 @@
1
+ use ego_tree::iter::Edge;
2
+ use scraper::{ElementRef, Node};
3
+ use std::{collections::HashSet, sync::LazyLock};
4
+
5
+ /// Set of block-level elements extracted from [MDN][1]
6
+ ///
7
+ /// [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
8
+ const BLOCK_LEVEL_ELEMENTS: [&'static str; 33] = [
9
+ "address",
10
+ "article",
11
+ "aside",
12
+ "blockquote",
13
+ "dd",
14
+ "details",
15
+ "dialog",
16
+ "div",
17
+ "dl",
18
+ "dt",
19
+ "fieldset",
20
+ "figcaption",
21
+ "figure",
22
+ "footer",
23
+ "form",
24
+ "h1",
25
+ "h2",
26
+ "h3",
27
+ "h4",
28
+ "h5",
29
+ "h6",
30
+ "header",
31
+ "hgroup",
32
+ "hr",
33
+ "li",
34
+ "main",
35
+ "nav",
36
+ "ol",
37
+ "p",
38
+ "pre",
39
+ "section",
40
+ "table",
41
+ "ul",
42
+ ];
43
+
44
+ static BLOCK_LEVEL_ELEMENTS_SET: LazyLock<HashSet<&'static str>> =
45
+ LazyLock::new(|| BLOCK_LEVEL_ELEMENTS.iter().map(|s| *s).collect());
46
+
47
+ fn is_block_element(name: &str) -> bool {
48
+ BLOCK_LEVEL_ELEMENTS_SET.contains(&name)
49
+ }
50
+
51
+ enum Item<'a> {
52
+ Text(&'a str),
53
+ Newlines(usize),
54
+ }
55
+
56
+ /// Converts HTML to plain text using a subset of the [`HTMLElement.innerText`][1]
57
+ /// algorithm ([WHATWG spec][2], [Chromium source][3]).
58
+ ///
59
+ /// While the output should be acceptable for documents containing text, no effort
60
+ /// was made to support more complex elements (e.g. tables, images, videos, etc...)
61
+ /// which have no reasonable use case for the kinds of inputs expected to be handled
62
+ /// (e.g. RSS entry titles and summaries)
63
+ ///
64
+ /// [1]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
65
+ /// [2]: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
66
+ /// [3]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/element_inner_text.cc;l=262;drc=eca6a1b4c221dc66cf40d0d1ee8eff3f3028ce26?q=innerText&ss=chromium
67
+ pub(crate) fn html_to_plain(element: ElementRef) -> String {
68
+ let mut item_iter = element
69
+ .traverse()
70
+ .filter_map(|edge| match edge {
71
+ Edge::Open(node) => match node.value() {
72
+ Node::Text(text) if !text.trim().is_empty() => Some(Item::Text(text)),
73
+ Node::Element(element) => match element.name() {
74
+ "br" => Some(Item::Newlines(1)),
75
+ "p" => Some(Item::Newlines(2)),
76
+ name if is_block_element(name) => Some(Item::Newlines(1)),
77
+ _ => None,
78
+ },
79
+ _ => None,
80
+ },
81
+ Edge::Close(node) => match node.value() {
82
+ Node::Element(element) => match element.name() {
83
+ "p" => Some(Item::Newlines(2)),
84
+ name if is_block_element(name) => Some(Item::Newlines(1)),
85
+ _ => None,
86
+ },
87
+ _ => None,
88
+ },
89
+ })
90
+ .peekable();
91
+
92
+ let mut output = String::new();
93
+
94
+ while let Some(item) = item_iter.next() {
95
+ match item {
96
+ Item::Text(text) => {
97
+ output.push_str(text);
98
+ }
99
+ Item::Newlines(count) => {
100
+ let mut max = count;
101
+
102
+ // Combine all subsequent newlines into one, using the maximum value
103
+ while let Some(Item::Newlines(next_count)) = item_iter.peek() {
104
+ max = max.max(*next_count);
105
+ item_iter.next();
106
+ }
107
+
108
+ // Don't insert newlines if we're at the beginning or the end
109
+ if !(output.is_empty() || item_iter.peek().is_none()) {
110
+ output.push_str(&"\n".repeat(max));
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ output
117
+ }
118
+
119
+ #[cfg(test)]
120
+ mod tests {
121
+ fn html_to_plain(input: &str) -> String {
122
+ let doc = scraper::Html::parse_fragment(input);
123
+ super::html_to_plain(doc.root_element())
124
+ }
125
+
126
+ #[test]
127
+ fn test_html_to_plain() {
128
+ assert_eq!("", html_to_plain(""));
129
+
130
+ assert_eq!(
131
+ "this is just text",
132
+ html_to_plain("this is just text"),
133
+ "regular text is returned as-is"
134
+ );
135
+
136
+ assert_eq!(
137
+ "this is a single paragraph",
138
+ html_to_plain("<p>this is a single paragraph</p>"),
139
+ "single paragraphs do not get leading and trailing newlines"
140
+ );
141
+
142
+ assert_eq!(
143
+ "this is a single div",
144
+ html_to_plain("<div>this is a single div</div>"),
145
+ "single block elements do not get leading and trailing newlines"
146
+ );
147
+
148
+ assert_eq!(
149
+ "text like <html> is correctly unescaped",
150
+ html_to_plain("<h1>text like &lt;html&gt; is correctly unescaped</h1>"),
151
+ "html-escaped text is correctly unescaped"
152
+ );
153
+
154
+ assert_eq!(
155
+ "this bold text is special",
156
+ html_to_plain("<p>this <em>bold</em> text is <span>special</span></p>"),
157
+ "inline elements don't introduce newlines"
158
+ );
159
+
160
+ assert_eq!(
161
+ "some deeply nested text",
162
+ html_to_plain("<header><div><h1>some deeply nested text</h1></div></header>"),
163
+ "subsequent block elements do not introduce duplicate newlines"
164
+ );
165
+
166
+ assert_eq!(
167
+ "line one\nline two",
168
+ html_to_plain("line one<br>line two"),
169
+ "<br> introduces a single newline"
170
+ );
171
+
172
+ assert_eq!(
173
+ "paragraph one\n\nparagraph two",
174
+ html_to_plain("<p>paragraph one</p><p>paragraph two</p>"),
175
+ "paragraphs are separated by two newlines"
176
+ );
177
+
178
+ assert_eq!(
179
+ "paragraph one\n\nparagraph two\n\nparagraph three",
180
+ html_to_plain("<p>paragraph one</p><p>paragraph two</p><p>paragraph three</p>"),
181
+ "paragraphs not at the beginning or end are wrapped in two newlines"
182
+ );
183
+
184
+ assert_eq!(
185
+ "malformed input\n🙌",
186
+ html_to_plain("<h1>malformed input</br><ul>🙌"),
187
+ "malformed input is handled"
188
+ );
189
+
190
+ assert_eq!(
191
+ "Hello, world\n\nThis is an HTML fragment",
192
+ html_to_plain("<h1>Hello, world</h1>\n<p>This is an HTML fragment</p>"),
193
+ "empty lines are ignored"
194
+ );
195
+ }
196
+ }
@@ -0,0 +1,149 @@
1
+ mod html_to_plain;
2
+
3
+ use ego_tree::NodeId;
4
+ use magnus::{function, method, prelude::*, Error, RArray, Ruby};
5
+ use scraper::{ElementRef, Html, Selector};
6
+ use std::sync::{Arc, Mutex};
7
+
8
+ #[magnus::init]
9
+ fn init(ruby: &Ruby) -> Result<(), Error> {
10
+ let module = ruby.define_module("Sawzall")?;
11
+ module.define_singleton_method("parse_fragment", function!(parse_fragment, 1))?;
12
+ module.define_singleton_method("parse_document", function!(parse_document, 1))?;
13
+
14
+ let document_class = module.define_class("Document", ruby.class_object())?;
15
+ document_class.define_method("select", method!(Document::select, 1))?;
16
+ document_class.define_method("root_element", method!(Document::root_element, 0))?;
17
+
18
+ let element_class = module.define_class("Element", ruby.class_object())?;
19
+ element_class.define_method("name", method!(Element::name, 0))?;
20
+ element_class.define_method("html", method!(Element::html, 0))?;
21
+ element_class.define_method("inner_html", method!(Element::inner_html, 0))?;
22
+ element_class.define_method("attr", method!(Element::attr, 1))?;
23
+ element_class.define_method("select", method!(Element::select, 1))?;
24
+ element_class.define_method("child_elements", method!(Element::child_elements, 0))?;
25
+ element_class.define_method("text", method!(Element::text, 0))?;
26
+
27
+ Ok(())
28
+ }
29
+
30
+ fn parse_fragment(fragment: String) -> Document {
31
+ Document::new(Html::parse_fragment(&fragment))
32
+ }
33
+
34
+ fn parse_document(document: String) -> Document {
35
+ Document::new(Html::parse_document(&document))
36
+ }
37
+
38
+ #[derive(Clone)]
39
+ #[magnus::wrap(class = "Sawzall::Document", free_immediately)]
40
+ struct Document(Arc<Mutex<Html>>);
41
+
42
+ impl Document {
43
+ fn new(html: Html) -> Self {
44
+ Self(Arc::new(Mutex::new(html)))
45
+ }
46
+
47
+ fn with_locked_html<U, F>(&self, f: F) -> U
48
+ where
49
+ F: FnOnce(&Html) -> U,
50
+ {
51
+ let html = self.0.lock().expect("failed to lock mutex");
52
+
53
+ f(&html)
54
+ }
55
+
56
+ fn select(&self, css_selector: String) -> Result<RArray, Error> {
57
+ self.with_locked_html(|html| select(css_selector, self.clone(), html.root_element()))
58
+ }
59
+
60
+ fn root_element(&self) -> Element {
61
+ self.with_locked_html(|html| Element {
62
+ id: html.root_element().id(),
63
+ document: self.clone(),
64
+ })
65
+ }
66
+ }
67
+
68
+ fn select(
69
+ css_selector: String,
70
+ document: Document,
71
+ element_ref: ElementRef,
72
+ ) -> Result<RArray, Error> {
73
+ let ruby = Ruby::get().expect("called from non-ruby thread");
74
+
75
+ let selector = Selector::parse(&css_selector).map_err(|e| {
76
+ Error::new(
77
+ ruby.exception_arg_error(),
78
+ format!("failed to parse selector {css_selector:?}\n{e}"),
79
+ )
80
+ })?;
81
+
82
+ Ok(element_ref
83
+ .select(&selector)
84
+ .map(|matching_element_ref| Element {
85
+ id: matching_element_ref.id(),
86
+ document: document.clone(),
87
+ })
88
+ .collect())
89
+ }
90
+
91
+ #[magnus::wrap(class = "Sawzall::Element", free_immediately)]
92
+ struct Element {
93
+ id: NodeId,
94
+ document: Document,
95
+ }
96
+
97
+ impl Element {
98
+ fn with_element_ref<U, F>(&self, f: F) -> U
99
+ where
100
+ F: FnOnce(ElementRef) -> U,
101
+ {
102
+ let html = self.document.0.lock().expect("failed to lock mutex");
103
+ let element_ref = html
104
+ .tree
105
+ .get(self.id)
106
+ .and_then(ElementRef::wrap)
107
+ .expect("node with id {self.id} must be an element in the tree");
108
+
109
+ f(element_ref)
110
+ }
111
+
112
+ fn name(&self) -> String {
113
+ self.with_element_ref(|element_ref| element_ref.value().name().to_string())
114
+ }
115
+
116
+ fn html(&self) -> String {
117
+ self.with_element_ref(|element_ref| element_ref.html())
118
+ }
119
+
120
+ fn inner_html(&self) -> String {
121
+ self.with_element_ref(|element_ref| element_ref.inner_html())
122
+ }
123
+
124
+ fn attr(&self, attribute: String) -> Option<String> {
125
+ self.with_element_ref(|element_ref| element_ref.attr(&attribute).map(ToString::to_string))
126
+ }
127
+
128
+ fn select(&self, css_selector: String) -> Result<RArray, Error> {
129
+ self.with_element_ref(|element_ref| {
130
+ select(css_selector, self.document.clone(), element_ref)
131
+ })
132
+ }
133
+
134
+ fn child_elements(&self) -> RArray {
135
+ self.with_element_ref(|element_ref| {
136
+ element_ref
137
+ .child_elements()
138
+ .map(|child_element_ref| Element {
139
+ id: child_element_ref.id(),
140
+ document: self.document.clone(),
141
+ })
142
+ .collect()
143
+ })
144
+ }
145
+
146
+ fn text(&self) -> String {
147
+ self.with_element_ref(html_to_plain::html_to_plain)
148
+ }
149
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sawzall
4
+ VERSION = "0.1.0.pre"
5
+ 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/sawzall"
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,45 @@
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["rubygems_mfa_required"] = "true"
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ gemspec = File.basename(__FILE__)
27
+ spec.files = [
28
+ gemspec,
29
+ "README.md",
30
+ "LICENSE.txt",
31
+ "Cargo.lock",
32
+ "Cargo.toml"
33
+ ]
34
+ spec.files += Dir.glob([
35
+ "ext/**/*.{rs,toml,lock,rb}",
36
+ "lib/**/*.rb",
37
+ ])
38
+
39
+ spec.bindir = "exe"
40
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
41
+ spec.require_paths = ["lib"]
42
+ spec.extensions = ["ext/sawzall/extconf.rb"]
43
+
44
+ spec.add_dependency "rb_sys", "~> 0.9.91"
45
+ end