selma 0.0.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +753 -0
- data/Cargo.toml +6 -0
- data/README.md +4 -1
- data/ext/selma/Cargo.toml +3 -3
- data/ext/selma/extconf.rb +0 -2
- data/ext/selma/src/html/element.rs +38 -2
- data/ext/selma/src/html/end_tag.rs +2 -2
- data/ext/selma/src/html/text_chunk.rs +8 -8
- data/ext/selma/src/html.rs +3 -1
- data/ext/selma/src/lib.rs +0 -1
- data/ext/selma/src/rewriter.rs +66 -66
- data/ext/selma/src/sanitizer.rs +21 -25
- data/ext/selma/src/selector.rs +4 -4
- data/lib/selma/version.rb +1 -1
- metadata +5 -20
- data/ext/selma/_util.rb +0 -102
- data/ext/selma/src/wrapped_struct.rs +0 -92
- data/selma.gemspec +0 -41
data/ext/selma/_util.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RUBY_MAJOR, RUBY_MINOR = RUBY_VERSION.split(".").collect(&:to_i)
|
4
|
-
|
5
|
-
PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
|
6
|
-
PACKAGE_EXT_DIR = File.join(PACKAGE_ROOT_DIR, "ext", "selma")
|
7
|
-
|
8
|
-
OS = case os = RbConfig::CONFIG["host_os"].downcase
|
9
|
-
when /linux/
|
10
|
-
# The official ruby-alpine Docker containers pre-build Ruby. As a result,
|
11
|
-
# Ruby doesn't know that it's on a musl-based platform. `ldd` is the
|
12
|
-
# a more reliable way to detect musl.
|
13
|
-
# See https://github.com/skylightio/skylight-ruby/issues/92
|
14
|
-
if ENV["SKYLIGHT_MUSL"] || %x(ldd --version 2>&1).include?("musl")
|
15
|
-
"linux-musl"
|
16
|
-
else
|
17
|
-
"linux"
|
18
|
-
end
|
19
|
-
when /darwin/
|
20
|
-
"darwin"
|
21
|
-
when /freebsd/
|
22
|
-
"freebsd"
|
23
|
-
when /netbsd/
|
24
|
-
"netbsd"
|
25
|
-
when /openbsd/
|
26
|
-
"openbsd"
|
27
|
-
when /sunos|solaris/
|
28
|
-
"solaris"
|
29
|
-
when /mingw|mswin/
|
30
|
-
"windows"
|
31
|
-
else
|
32
|
-
os
|
33
|
-
end
|
34
|
-
|
35
|
-
# Normalize the platform CPU
|
36
|
-
ARCH = case cpu = RbConfig::CONFIG["host_cpu"].downcase
|
37
|
-
when /amd64|x86_64|x64/
|
38
|
-
"x86_64"
|
39
|
-
when /i?86|x86|i86pc/
|
40
|
-
"x86"
|
41
|
-
when /ppc|powerpc/
|
42
|
-
"powerpc"
|
43
|
-
when /^aarch/
|
44
|
-
"aarch"
|
45
|
-
when /^arm/
|
46
|
-
"arm"
|
47
|
-
else
|
48
|
-
cpu
|
49
|
-
end
|
50
|
-
|
51
|
-
def windows?
|
52
|
-
OS == "windows"
|
53
|
-
end
|
54
|
-
|
55
|
-
def solaris?
|
56
|
-
OS == solaries
|
57
|
-
end
|
58
|
-
|
59
|
-
def darwin?
|
60
|
-
OS == "darwin"
|
61
|
-
end
|
62
|
-
|
63
|
-
def macos?
|
64
|
-
darwin? || OS == "macos"
|
65
|
-
end
|
66
|
-
|
67
|
-
def openbsd?
|
68
|
-
OS == "openbsd"
|
69
|
-
end
|
70
|
-
|
71
|
-
def aix?
|
72
|
-
OS == "aix"
|
73
|
-
end
|
74
|
-
|
75
|
-
def nix?
|
76
|
-
!(windows? || solaris? || darwin?)
|
77
|
-
end
|
78
|
-
|
79
|
-
def x86_64?
|
80
|
-
ARCH == "x86_64"
|
81
|
-
end
|
82
|
-
|
83
|
-
def x86?
|
84
|
-
ARCH == "x86"
|
85
|
-
end
|
86
|
-
|
87
|
-
def abs_path(path)
|
88
|
-
File.join(PACKAGE_EXT_DIR, path)
|
89
|
-
end
|
90
|
-
|
91
|
-
def find_header_or_abort(header, *paths)
|
92
|
-
find_header(header, *paths) || abort("#{header} was expected in `#{paths.join(", ")}`, but it is missing.")
|
93
|
-
end
|
94
|
-
|
95
|
-
def find_library_or_abort(lib, func, *paths)
|
96
|
-
find_library(lib, func, *paths) || abort("#{lib} was expected in `#{paths.join(", ")}`, but it is missing.")
|
97
|
-
end
|
98
|
-
|
99
|
-
def concat_flags(*args)
|
100
|
-
args.compact.join(" ")
|
101
|
-
end
|
102
|
-
|
@@ -1,92 +0,0 @@
|
|
1
|
-
use magnus::{error::Error, exception, gc, value::Value, RTypedData, TryConvert, TypedData};
|
2
|
-
use std::{marker::PhantomData, ops::Deref};
|
3
|
-
|
4
|
-
// NOTE: My Rust isn't good enough to know what any of this does,
|
5
|
-
// but it was taken from https://cs.github.com/bytecodealliance/wasmtime-rb/blob/a843e4b4582a945f2c881b8bd3e2b87688ab5509/ext/src/helpers/wrapped_struct.rs#L4
|
6
|
-
|
7
|
-
/// A small wrapper for `RTypedData` that keeps track of the concrete struct
|
8
|
-
/// type, and the underlying [`Value`] for GC purposes.
|
9
|
-
#[derive(Debug)]
|
10
|
-
#[repr(transparent)]
|
11
|
-
pub struct WrappedStruct<T: TypedData> {
|
12
|
-
inner: RTypedData,
|
13
|
-
phantom: PhantomData<T>,
|
14
|
-
}
|
15
|
-
|
16
|
-
impl<T: TypedData> Clone for WrappedStruct<T> {
|
17
|
-
fn clone(&self) -> Self {
|
18
|
-
Self {
|
19
|
-
inner: self.inner,
|
20
|
-
phantom: PhantomData,
|
21
|
-
}
|
22
|
-
}
|
23
|
-
}
|
24
|
-
impl<T: TypedData> Copy for WrappedStruct<T> {}
|
25
|
-
|
26
|
-
impl<T: TypedData> WrappedStruct<T> {
|
27
|
-
/// Gets the underlying struct.
|
28
|
-
pub fn get(&self) -> Result<&T, Error> {
|
29
|
-
self.inner.try_convert()
|
30
|
-
}
|
31
|
-
|
32
|
-
/// Gets the underlying struct with a `'static` lifetime.
|
33
|
-
pub fn get_static(&self) -> Result<&'static T, Error> {
|
34
|
-
self.inner.try_convert()
|
35
|
-
}
|
36
|
-
|
37
|
-
/// Get the Ruby [`Value`] for this struct.
|
38
|
-
pub fn to_value(self) -> Value {
|
39
|
-
self.inner.into()
|
40
|
-
}
|
41
|
-
|
42
|
-
/// Marks the Ruby [`Value`] for GC.
|
43
|
-
pub fn mark(&self) {
|
44
|
-
gc::mark(&self.inner.into());
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
impl<T: TypedData> From<WrappedStruct<T>> for Value {
|
49
|
-
fn from(wrapped_struct: WrappedStruct<T>) -> Self {
|
50
|
-
wrapped_struct.to_value()
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
impl<T: TypedData> Deref for WrappedStruct<T> {
|
55
|
-
type Target = RTypedData;
|
56
|
-
|
57
|
-
fn deref(&self) -> &Self::Target {
|
58
|
-
&self.inner
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
impl<T: TypedData> From<T> for WrappedStruct<T> {
|
63
|
-
fn from(t: T) -> Self {
|
64
|
-
Self {
|
65
|
-
inner: RTypedData::wrap(t),
|
66
|
-
phantom: PhantomData,
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
impl<T> TryConvert for WrappedStruct<T>
|
72
|
-
where
|
73
|
-
T: TypedData,
|
74
|
-
{
|
75
|
-
fn try_convert(val: Value) -> Result<Self, Error> {
|
76
|
-
let inner = RTypedData::from_value(val).ok_or_else(|| {
|
77
|
-
Error::new(
|
78
|
-
exception::type_error(),
|
79
|
-
format!(
|
80
|
-
"no implicit conversion of {} into {}",
|
81
|
-
unsafe { val.classname() },
|
82
|
-
T::class()
|
83
|
-
),
|
84
|
-
)
|
85
|
-
})?;
|
86
|
-
|
87
|
-
Ok(Self {
|
88
|
-
inner,
|
89
|
-
phantom: PhantomData,
|
90
|
-
})
|
91
|
-
}
|
92
|
-
}
|
data/selma.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path("lib", __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require "selma/version"
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = "selma"
|
9
|
-
spec.version = Selma::VERSION
|
10
|
-
spec.authors = ["Garen J. Torikian"]
|
11
|
-
spec.email = ["gjtorikian@gmail.com"]
|
12
|
-
|
13
|
-
spec.summary = "Selma selects and matches HTML nodes using CSS rules. Backed by Rust's lol_html parser."
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.required_ruby_version = "~> 3.1"
|
17
|
-
# https://github.com/rubygems/rubygems/pull/5852#issuecomment-1231118509
|
18
|
-
spec.required_rubygems_version = ">= 3.3.22"
|
19
|
-
|
20
|
-
spec.files = ["LICENSE.txt", "README.md", "selma.gemspec"]
|
21
|
-
spec.files += Dir.glob("lib/**/*.rb")
|
22
|
-
spec.files += Dir.glob("ext/**/*.{rs,toml,lock,rb}")
|
23
|
-
spec.bindir = "exe"
|
24
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
-
|
26
|
-
spec.require_paths = ["lib"]
|
27
|
-
spec.extensions = ["ext/selma/extconf.rb"]
|
28
|
-
|
29
|
-
spec.metadata = {
|
30
|
-
"allowed_push_host" => "https://rubygems.org",
|
31
|
-
"funding_uri" => "https://github.com/sponsors/gjtorikian/",
|
32
|
-
"source_code_uri" => "https://github.com/gjtorikian/selma",
|
33
|
-
"rubygems_mfa_required" => "true",
|
34
|
-
}
|
35
|
-
|
36
|
-
spec.add_dependency("rb_sys", "~> 0.9")
|
37
|
-
|
38
|
-
spec.add_development_dependency("rake", "~> 13.0")
|
39
|
-
spec.add_development_dependency("rake-compiler", "~> 1.2")
|
40
|
-
spec.add_development_dependency("rake-compiler-dock", "~> 1.2")
|
41
|
-
end
|