selma 0.4.6.1 → 0.4.7
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 +4 -4
- data/Cargo.lock +4 -4
- data/ext/selma/src/html/text_chunk.rs +32 -2
- data/ext/selma/src/rewriter.rs +2 -1
- data/lib/selma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04f8ef6623b5a28c62d64f3077842e262321580e998e90ba458735e5d7a13395
|
4
|
+
data.tar.gz: 132e7e538f36ad7399fb6edb7c09ece5fb16a9bd94da3a3a18339c0ad4057888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a3709aed3c7793b4010174866d4866bedd848cd2e2ca1553dff603e21790c8982d79a0ba72b6c2c5668639da76efd745aff2fbfe496442bbbb5c14cdf0a431
|
7
|
+
data.tar.gz: 86a393c4df2090cdba7f75001ebb81f9262c3f65e9fc897bc5d6fa6a8147e3f37e97118f7787fac22acd86baa241ba3b934e42062df1888e774c768cf3a24729
|
data/Cargo.lock
CHANGED
@@ -516,18 +516,18 @@ dependencies = [
|
|
516
516
|
|
517
517
|
[[package]]
|
518
518
|
name = "rb-sys"
|
519
|
-
version = "0.9.
|
519
|
+
version = "0.9.101"
|
520
520
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
521
|
-
checksum = "
|
521
|
+
checksum = "1ba2704ccfa7875c91792c57a9aa7c3caac524d3036c122e36eeddad6f6e7c6f"
|
522
522
|
dependencies = [
|
523
523
|
"rb-sys-build",
|
524
524
|
]
|
525
525
|
|
526
526
|
[[package]]
|
527
527
|
name = "rb-sys-build"
|
528
|
-
version = "0.9.
|
528
|
+
version = "0.9.101"
|
529
529
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
530
|
-
checksum = "
|
530
|
+
checksum = "c73585ec80c217b7a81257ca9bb89b191b5e452ec4b9106dc4c2e4e96a822242"
|
531
531
|
dependencies = [
|
532
532
|
"bindgen",
|
533
533
|
"lazy_static",
|
@@ -6,6 +6,26 @@ use magnus::{exception, method, Error, Module, RClass, Symbol, Value};
|
|
6
6
|
|
7
7
|
struct HTMLTextChunk {
|
8
8
|
text_chunk: NativeRefWrap<TextChunk<'static>>,
|
9
|
+
buffer: String,
|
10
|
+
}
|
11
|
+
|
12
|
+
macro_rules! clone_buffer_if_not_empty {
|
13
|
+
($binding:expr, $buffer:expr) => {
|
14
|
+
if !$binding.buffer.is_empty() {
|
15
|
+
$buffer.clone_from(&$binding.buffer);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
// if this is the first time we're processing this text chunk (buffer is empty),
|
21
|
+
// we carry on. Otherwise, we need to use the buffer text, not the text chunk,
|
22
|
+
// because lol-html is not designed in such a way to keep track of text chunks.
|
23
|
+
macro_rules! set_text_chunk_to_buffer {
|
24
|
+
($text_chunk:expr, $buffer:expr) => {
|
25
|
+
if !$buffer.is_empty() {
|
26
|
+
$text_chunk.set_str($buffer);
|
27
|
+
}
|
28
|
+
};
|
9
29
|
}
|
10
30
|
|
11
31
|
#[magnus::wrap(class = "Selma::HTML::TextChunk")]
|
@@ -18,6 +38,7 @@ impl SelmaHTMLTextChunk {
|
|
18
38
|
pub fn new(ref_wrap: NativeRefWrap<TextChunk<'static>>) -> Self {
|
19
39
|
Self(RefCell::new(HTMLTextChunk {
|
20
40
|
text_chunk: ref_wrap,
|
41
|
+
buffer: String::new(),
|
21
42
|
}))
|
22
43
|
}
|
23
44
|
|
@@ -96,16 +117,25 @@ impl SelmaHTMLTextChunk {
|
|
96
117
|
|
97
118
|
fn replace(&self, args: &[Value]) -> Result<String, Error> {
|
98
119
|
let mut binding = self.0.borrow_mut();
|
120
|
+
let mut buffer = String::new();
|
121
|
+
|
122
|
+
clone_buffer_if_not_empty!(binding, buffer);
|
123
|
+
|
99
124
|
let text_chunk = binding.text_chunk.get_mut().unwrap();
|
100
125
|
|
126
|
+
set_text_chunk_to_buffer!(text_chunk, buffer);
|
127
|
+
|
101
128
|
let (text_str, content_type) = match crate::scan_text_args(args) {
|
102
129
|
Ok((text_str, content_type)) => (text_str, content_type),
|
103
130
|
Err(err) => return Err(err),
|
104
131
|
};
|
105
|
-
|
106
132
|
text_chunk.replace(&text_str, content_type);
|
107
133
|
|
108
|
-
|
134
|
+
text_chunk.set_str(text_str.clone());
|
135
|
+
|
136
|
+
binding.buffer = text_chunk.as_str().to_string();
|
137
|
+
|
138
|
+
Ok(text_str)
|
109
139
|
}
|
110
140
|
}
|
111
141
|
|
data/ext/selma/src/rewriter.rs
CHANGED
@@ -540,7 +540,8 @@ impl SelmaRewriter {
|
|
540
540
|
// prevents missing `handle_text_chunk` function
|
541
541
|
let content = text_chunk.as_str();
|
542
542
|
|
543
|
-
//
|
543
|
+
// lol-html sometimes returns blank text if
|
544
|
+
// last_in_text_node() is true
|
544
545
|
if content.is_empty() {
|
545
546
|
return Ok(());
|
546
547
|
}
|
data/lib/selma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|