css_inline 0.11.2 → 0.13.0
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/README.md +42 -26
- data/ext/css_inline/Cargo.toml +1 -1
- data/ext/css_inline/src/lib.rs +15 -8
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 341c8140008fc97311b7c05e23becedbfde8a2bb212cab1602f4fcf4b12d90aa
|
|
4
|
+
data.tar.gz: cbcb902ad4446aac95f369258cced29a9729fd19772f001e1faa1dd72641d324
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6ea53abccd62a28badf56f9298f54307fbff3609a46e6d79bdbf7e5a65171b92ae5d38363e426cda70e1e932117d983c6a302735d41fc82ad40ffb84948f15b
|
|
7
|
+
data.tar.gz: 7ada5bffbc4961928a6fe48e70e8bb3f73419cd86bc46315bca86ae55efb3c04ec046888b4eb9c98f4a20f80158d5d9387f28cf25fc20a916dea54c7e83c04e9
|
data/README.md
CHANGED
|
@@ -13,12 +13,12 @@ For instance, the library transforms HTML like this:
|
|
|
13
13
|
|
|
14
14
|
```html
|
|
15
15
|
<html>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
<head>
|
|
17
|
+
<style>h1 { color:blue; }</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<h1>Big Text</h1>
|
|
21
|
+
</body>
|
|
22
22
|
</html>
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -26,10 +26,10 @@ into:
|
|
|
26
26
|
|
|
27
27
|
```html
|
|
28
28
|
<html>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
<head></head>
|
|
30
|
+
<body>
|
|
31
|
+
<h1 style="color:blue;">Big Text</h1>
|
|
32
|
+
</body>
|
|
33
33
|
</html>
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -40,6 +40,11 @@ into:
|
|
|
40
40
|
- Can process multiple documents in parallel
|
|
41
41
|
- Works on Linux, Windows, and macOS
|
|
42
42
|
- Supports HTML5 & CSS3
|
|
43
|
+
- Tested on Ruby 2.7 and 3.2.
|
|
44
|
+
|
|
45
|
+
## Playground
|
|
46
|
+
|
|
47
|
+
If you'd like to try `css-inline`, you can check the WebAssembly-powered [playground](https://css-inline.org/) to see the results instantly.
|
|
43
48
|
|
|
44
49
|
## Installation
|
|
45
50
|
|
|
@@ -100,11 +105,11 @@ You can also skip CSS inlining for an HTML tag by adding the `data-css-inline="i
|
|
|
100
105
|
|
|
101
106
|
```html
|
|
102
107
|
<head>
|
|
103
|
-
|
|
108
|
+
<style>h1 { color:blue; }</style>
|
|
104
109
|
</head>
|
|
105
110
|
<body>
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
<!-- The tag below won't receive additional styles -->
|
|
112
|
+
<h1 data-css-inline="ignore">Big Text</h1>
|
|
108
113
|
</body>
|
|
109
114
|
```
|
|
110
115
|
|
|
@@ -112,14 +117,29 @@ The `data-css-inline="ignore"` attribute also allows you to skip `link` and `sty
|
|
|
112
117
|
|
|
113
118
|
```html
|
|
114
119
|
<head>
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
<!-- Styles below are ignored -->
|
|
121
|
+
<style data-css-inline="ignore">h1 { color:blue; }</style>
|
|
117
122
|
</head>
|
|
118
123
|
<body>
|
|
119
|
-
|
|
124
|
+
<h1>Big Text</h1>
|
|
120
125
|
</body>
|
|
121
126
|
```
|
|
122
127
|
|
|
128
|
+
Alternatively, you may keep `style` from being removed by using the `data-css-inline="keep"` attribute.
|
|
129
|
+
This is useful if you want to keep `@media` queries for responsive emails in separate `style` tags:
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<head>
|
|
133
|
+
<!-- Styles below are not removed -->
|
|
134
|
+
<style data-css-inline="keep">h1 { color:blue; }</style>
|
|
135
|
+
</head>
|
|
136
|
+
<body>
|
|
137
|
+
<h1>Big Text</h1>
|
|
138
|
+
</body>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Such tags will be kept in the resulting HTML even if the `keep_style_tags` option is set to `false`.
|
|
142
|
+
|
|
123
143
|
If you'd like to load stylesheets from your filesystem, use the `file://` scheme:
|
|
124
144
|
|
|
125
145
|
```ruby
|
|
@@ -137,19 +157,15 @@ It consistently outperforms `premailer`, offering speed increases often exceedin
|
|
|
137
157
|
|
|
138
158
|
The table below provides a detailed comparison between `css_inline` and `premailer` when inlining CSS into an HTML document (like in the Usage section above):
|
|
139
159
|
|
|
140
|
-
| | Size | `css_inline 0.
|
|
160
|
+
| | Size | `css_inline 0.13.0` | `premailer 1.21.0 with Nokogiri 1.15.2` | Difference |
|
|
141
161
|
|-------------------|---------|---------------------|------------------------------------------------|------------|
|
|
142
|
-
| Basic usage | 230 B |
|
|
143
|
-
| Realistic email 1 | 8.58 KB |
|
|
144
|
-
| Realistic email 2 | 4.3 KB |
|
|
145
|
-
| GitHub Page | 1.81 MB |
|
|
162
|
+
| Basic usage | 230 B | 7.79 µs | 417.56 µs | **53.57x** |
|
|
163
|
+
| Realistic email 1 | 8.58 KB | 149.56 µs | 9.73 ms | **65.07x** |
|
|
164
|
+
| Realistic email 2 | 4.3 KB | 93.19 µs | Error: Cannot parse 0 calc((100% - 500px) / 2) | - |
|
|
165
|
+
| GitHub Page | 1.81 MB | 237.03 ms | 3.02 s | **12.78x** |
|
|
146
166
|
|
|
147
167
|
Please refer to the `test/bench.rb` file to review the benchmark code.
|
|
148
|
-
The results displayed above were measured using stable `rustc 1.
|
|
149
|
-
|
|
150
|
-
## Ruby support
|
|
151
|
-
|
|
152
|
-
`css_inline` supports Ruby 2.7 and 3.2.
|
|
168
|
+
The results displayed above were measured using stable `rustc 1.75.0` on Ruby `3.2.2`.
|
|
153
169
|
|
|
154
170
|
## Further reading
|
|
155
171
|
|
data/ext/css_inline/Cargo.toml
CHANGED
data/ext/css_inline/src/lib.rs
CHANGED
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
rust_2018_compatibility,
|
|
26
26
|
rust_2021_compatibility
|
|
27
27
|
)]
|
|
28
|
-
#[allow(clippy::module_name_repetitions)]
|
|
29
28
|
use css_inline as rust_inline;
|
|
30
29
|
use magnus::{
|
|
31
30
|
class, define_module, function, method,
|
|
@@ -34,7 +33,7 @@ use magnus::{
|
|
|
34
33
|
RHash, Value,
|
|
35
34
|
};
|
|
36
35
|
use rayon::prelude::*;
|
|
37
|
-
use std::borrow::Cow;
|
|
36
|
+
use std::{borrow::Cow, sync::Arc};
|
|
38
37
|
|
|
39
38
|
type RubyResult<T> = Result<T, magnus::Error>;
|
|
40
39
|
|
|
@@ -76,6 +75,7 @@ fn parse_options<Req>(
|
|
|
76
75
|
load_remote_stylesheets: kwargs.4.unwrap_or(true),
|
|
77
76
|
extra_css: kwargs.5.map(Cow::Owned),
|
|
78
77
|
preallocate_node_capacity: kwargs.6.unwrap_or(32),
|
|
78
|
+
resolver: Arc::new(rust_inline::DefaultStylesheetResolver),
|
|
79
79
|
})
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -92,9 +92,10 @@ impl From<InlineErrorWrapper> for magnus::Error {
|
|
|
92
92
|
rust_inline::InlineError::IO(error) => {
|
|
93
93
|
magnus::Error::new(magnus::exception::arg_error(), error.to_string())
|
|
94
94
|
}
|
|
95
|
-
rust_inline::InlineError::Network
|
|
96
|
-
magnus::
|
|
97
|
-
|
|
95
|
+
rust_inline::InlineError::Network { error, location } => magnus::Error::new(
|
|
96
|
+
magnus::exception::arg_error(),
|
|
97
|
+
format!("{error}: {location}"),
|
|
98
|
+
),
|
|
98
99
|
rust_inline::InlineError::ParseError(message) => {
|
|
99
100
|
magnus::Error::new(magnus::exception::arg_error(), message.to_string())
|
|
100
101
|
}
|
|
@@ -105,17 +106,23 @@ impl From<InlineErrorWrapper> for magnus::Error {
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
struct UrlError
|
|
109
|
+
struct UrlError {
|
|
110
|
+
error: rust_inline::ParseError,
|
|
111
|
+
url: String,
|
|
112
|
+
}
|
|
109
113
|
|
|
110
114
|
impl From<UrlError> for magnus::Error {
|
|
111
115
|
fn from(error: UrlError) -> magnus::Error {
|
|
112
|
-
magnus::Error::new(
|
|
116
|
+
magnus::Error::new(
|
|
117
|
+
magnus::exception::arg_error(),
|
|
118
|
+
format!("{}: {}", error.error, error.url),
|
|
119
|
+
)
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
fn parse_url(url: Option<String>) -> RubyResult<Option<rust_inline::Url>> {
|
|
117
124
|
Ok(if let Some(url) = url {
|
|
118
|
-
Some(rust_inline::Url::parse(url.as_str()).map_err(UrlError)?)
|
|
125
|
+
Some(rust_inline::Url::parse(url.as_str()).map_err(|error| UrlError { error, url })?)
|
|
119
126
|
} else {
|
|
120
127
|
None
|
|
121
128
|
})
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: css_inline
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dygalo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-01-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake-compiler
|
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
124
124
|
version: 3.3.26
|
|
125
125
|
requirements:
|
|
126
126
|
- Rust >= 1.65
|
|
127
|
-
rubygems_version: 3.4.
|
|
127
|
+
rubygems_version: 3.4.19
|
|
128
128
|
signing_key:
|
|
129
129
|
specification_version: 4
|
|
130
130
|
summary: High-performance library for inlining CSS into HTML 'style' attributes
|