selma 0.4.6.1 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aef17ad0cd3cc5b7d66af208adc138aa4734c76744d051f88889c9e145bd2373
4
- data.tar.gz: 9b50370bff0ce06af4613c474c3a5f376b5cb1b73c6845c6e3133a56f37f56dc
3
+ metadata.gz: 04f8ef6623b5a28c62d64f3077842e262321580e998e90ba458735e5d7a13395
4
+ data.tar.gz: 132e7e538f36ad7399fb6edb7c09ece5fb16a9bd94da3a3a18339c0ad4057888
5
5
  SHA512:
6
- metadata.gz: c45623b754d466caef138dfc09c091d4c9fb4dbee8d1b1d606cd9275cecc3c05d8a320cee984227dda691182b7790f41ff62f8e11dd2600ca0af31c469972923
7
- data.tar.gz: 2304b49efa07fe47d225c557c5c6d1c1d7d14cb4ab2553700f3ab74af9babc639cb5b52fd20d84c6d74e47d506c9649b8c44f0ba0c5f26853e8eda9e085d6c63
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.100"
519
+ version = "0.9.101"
520
520
  source = "registry+https://github.com/rust-lang/crates.io-index"
521
- checksum = "87f2ba20be84b32fad6b0ce397764bcdd0f2dca4431cf7035f6a6721e5747565"
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.100"
528
+ version = "0.9.101"
529
529
  source = "registry+https://github.com/rust-lang/crates.io-index"
530
- checksum = "7ecae2bdcb118ee721d9a3929f89e8578237fade298dfcf8c928609aa88abc48"
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
- Ok(text_chunk.as_str().to_string())
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
 
@@ -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
- // seems that sometimes lol-html returns blank text / EOLs?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Selma
4
- VERSION = "0.4.6.1"
4
+ VERSION = "0.4.7"
5
5
  end
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.6.1
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-04 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys