css_inline 0.11.1 → 0.12.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 +26 -22
- data/ext/css_inline/Cargo.toml +1 -1
- data/ext/css_inline/src/lib.rs +13 -6
- 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: ecc6091cab3a8511eb3e5135f0028488cb11eebcdcc64efaababbe404a154aff
|
4
|
+
data.tar.gz: e0c4874267b3455c13f04321a56c5ff526b903acdc517adafdb4a73731598339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c9d1fd5e9c7a81680e19ff417bdc57f815b22399887cf84441d4f03bf6ccd6ce7f96da6555054fddecc9a396de22f76a2e0705f3b3f030db6863994f5a3e8b3
|
7
|
+
data.tar.gz: c16c50735d1f2dc40691a1c74f9688147818a0d78005549df819044ad6beb0fc11339feb2faf7148c69f78b3dd44108e9cfd604a6904d4ec8953df5ead5f6049
|
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
|
|
@@ -41,6 +41,10 @@ into:
|
|
41
41
|
- Works on Linux, Windows, and macOS
|
42
42
|
- Supports HTML5 & CSS3
|
43
43
|
|
44
|
+
## Playground
|
45
|
+
|
46
|
+
If you'd like to try `css-inline`, you can check the WebAssembly-powered [playground](https://css-inline.org/) to see the results instantly.
|
47
|
+
|
44
48
|
## Installation
|
45
49
|
|
46
50
|
Add this line to your application's `Gemfile`:
|
@@ -100,11 +104,11 @@ You can also skip CSS inlining for an HTML tag by adding the `data-css-inline="i
|
|
100
104
|
|
101
105
|
```html
|
102
106
|
<head>
|
103
|
-
|
107
|
+
<style>h1 { color:blue; }</style>
|
104
108
|
</head>
|
105
109
|
<body>
|
106
|
-
|
107
|
-
|
110
|
+
<!-- The tag below won't receive additional styles -->
|
111
|
+
<h1 data-css-inline="ignore">Big Text</h1>
|
108
112
|
</body>
|
109
113
|
```
|
110
114
|
|
@@ -112,11 +116,11 @@ The `data-css-inline="ignore"` attribute also allows you to skip `link` and `sty
|
|
112
116
|
|
113
117
|
```html
|
114
118
|
<head>
|
115
|
-
|
116
|
-
|
119
|
+
<!-- Styles below are ignored -->
|
120
|
+
<style data-css-inline="ignore">h1 { color:blue; }</style>
|
117
121
|
</head>
|
118
122
|
<body>
|
119
|
-
|
123
|
+
<h1>Big Text</h1>
|
120
124
|
</body>
|
121
125
|
```
|
122
126
|
|
@@ -137,15 +141,15 @@ It consistently outperforms `premailer`, offering speed increases often exceedin
|
|
137
141
|
|
138
142
|
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
143
|
|
140
|
-
| | Size | `css_inline 0.11.
|
144
|
+
| | Size | `css_inline 0.11.2` | `premailer 1.21.0 with Nokogiri 1.15.2` | Difference |
|
141
145
|
|-------------------|---------|---------------------|------------------------------------------------|------------|
|
142
|
-
| Basic usage | 230 B | 8.
|
143
|
-
| Realistic email 1 | 8.58 KB |
|
144
|
-
| Realistic email 2 | 4.3 KB |
|
145
|
-
| GitHub Page | 1.81 MB |
|
146
|
+
| Basic usage | 230 B | 8.27 µs | 433.55 µs | **52.35x** |
|
147
|
+
| Realistic email 1 | 8.58 KB | 159.20 µs | 9.88 ms | **62.10x** |
|
148
|
+
| Realistic email 2 | 4.3 KB | 103.41 µs | Error: Cannot parse 0 calc((100% - 500px) / 2) | - |
|
149
|
+
| GitHub Page | 1.81 MB | 301.66 ms | 3.08 s | **10.24x** |
|
146
150
|
|
147
151
|
Please refer to the `test/bench.rb` file to review the benchmark code.
|
148
|
-
The results displayed above were measured using stable `rustc 1.74.
|
152
|
+
The results displayed above were measured using stable `rustc 1.74.1` on Ruby `3.2.2`.
|
149
153
|
|
150
154
|
## Ruby support
|
151
155
|
|
data/ext/css_inline/Cargo.toml
CHANGED
data/ext/css_inline/src/lib.rs
CHANGED
@@ -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.12.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: 2023-12-
|
11
|
+
date: 2023-12-28 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.10
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: High-performance library for inlining CSS into HTML 'style' attributes
|