premailer 1.22.0 → 1.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -29
- data/lib/premailer/adapter/nokogiri.rb +1 -0
- data/lib/premailer/adapter/rgb_to_hex.rb +8 -7
- data/lib/premailer/html_to_plain_text.rb +1 -1
- data/lib/premailer/premailer.rb +4 -2
- data/lib/premailer/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 893f0a35f19920e5a33bbaefc0c1cd2dd8a8fc2f56fc8f11bf7ed3bca2d4d437
|
4
|
+
data.tar.gz: 7d48ed502bc818064241ea372b4e0bdbffd204a845ff5e36a8da38af94a15202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2098aec27cdabce93e5dd144be10e6b090105970f415fd32e3e5d6a9b7f65decf7d1968563e0ecb7ea88a2d74895ad526dc0fd1f72a6d7e2a9029548884157f
|
7
|
+
data.tar.gz: f70007e030983216f7598f387c909cdb0de5c9192f9fe69049ef7da1f307357b9ae79dc2a533b0d2bd5bdbae60de9d1935162ab47b76d8af0c14fa788108e11f
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
For the best HTML e-mail delivery results, CSS should be inline. This is a
|
6
6
|
huge pain and a simple newsletter becomes un-managable very quickly. This
|
7
|
-
|
7
|
+
gem is a solution.
|
8
8
|
|
9
9
|
* CSS styles are converted to inline style attributes
|
10
10
|
- Checks `style` and `link[rel=stylesheet]` tags and preserves existing inline attributes
|
@@ -12,35 +12,26 @@ script is my solution.
|
|
12
12
|
- Checks links in `href`, `src` and CSS `url('')`
|
13
13
|
* CSS properties are checked against e-mail client capabilities
|
14
14
|
- Based on the Email Standards Project's guides
|
15
|
-
* A [plain text version](
|
15
|
+
* A [plain text version](#plain-text-version) is created (optional)
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
19
|
-
Install the Premailer gem from RubyGems.
|
20
|
-
|
21
19
|
```bash
|
22
20
|
gem install premailer
|
23
21
|
```
|
24
22
|
|
25
|
-
or add it to your `Gemfile` and run `bundle`.
|
26
|
-
|
27
23
|
## Example
|
28
24
|
|
29
25
|
```ruby
|
30
26
|
require 'premailer'
|
31
27
|
|
32
|
-
premailer = Premailer.new('http://example.com/myfile.html', :
|
28
|
+
premailer = Premailer.new('http://example.com/myfile.html', warn_level: Premailer::Warnings::SAFE)
|
33
29
|
|
34
|
-
# Write the plain-text output
|
35
|
-
|
36
|
-
File.open("output.txt", "w") do |fout|
|
37
|
-
fout.puts premailer.to_plain_text
|
38
|
-
end
|
30
|
+
# Write the plain-text output (must come before to_inline_css)
|
31
|
+
File.write "output.txt", premailer.to_plain_text
|
39
32
|
|
40
33
|
# Write the HTML output
|
41
|
-
File.
|
42
|
-
fout.puts premailer.to_inline_css
|
43
|
-
end
|
34
|
+
File.write "output.html", premailer.to_inline_css
|
44
35
|
|
45
36
|
# Output any CSS warnings
|
46
37
|
premailer.warnings.each do |w|
|
@@ -50,17 +41,13 @@ end
|
|
50
41
|
|
51
42
|
## Adapters
|
52
43
|
|
53
|
-
Premailer's default adapter is nokogiri if both nokogiri and nokogumbo are included in the Gemfile list. However, if you want to use a different adapter, you can choose to.
|
54
|
-
|
55
|
-
There are three adapters in total (as of premailer 1.10.0)
|
56
|
-
|
57
44
|
1. nokogiri (default)
|
58
|
-
2. nokogiri_fast
|
45
|
+
2. nokogiri_fast (20x speed, more memory)
|
59
46
|
3. nokogumbo
|
60
47
|
|
61
|
-
hpricot adapter removed
|
48
|
+
(hpricot adapter removed, use `~>1.9.0` version if you need it)
|
62
49
|
|
63
|
-
|
50
|
+
Picking an adapter:
|
64
51
|
|
65
52
|
```ruby
|
66
53
|
Premailer::Adapter.use = :nokogiri_fast
|
@@ -97,22 +84,56 @@ will result in
|
|
97
84
|
<table cellspacing='5' width='500'>
|
98
85
|
```
|
99
86
|
|
100
|
-
##
|
87
|
+
## Plain text version
|
88
|
+
|
89
|
+
Premailer can generate a plain text version of your HTML. Links and images will be inlined.
|
101
90
|
|
102
|
-
|
91
|
+
For example
|
103
92
|
|
104
|
-
|
93
|
+
```html
|
94
|
+
<a href="https://example.com" >
|
95
|
+
<img src="https://github.com/premailer.png" alt="Premailer Logo" />
|
96
|
+
</a>
|
97
|
+
```
|
105
98
|
|
99
|
+
will become
|
100
|
+
|
101
|
+
```text
|
102
|
+
Premailer Logo ( https://example.com )
|
103
|
+
```
|
104
|
+
|
105
|
+
To ignore/omit a section of HTML content from the plain text version, wrap it with the following comments.
|
106
|
+
|
107
|
+
```html
|
108
|
+
<!-- start text/html -->
|
109
|
+
<p>This will be omitted from the plain text version.</p>
|
110
|
+
<p>
|
111
|
+
This is extremely helpful for <strong>removing email headers and footers</strong>
|
112
|
+
that aren't needed in the text version.
|
113
|
+
</p>
|
114
|
+
<!-- end text/html -->
|
115
|
+
```
|
116
|
+
|
117
|
+
## Configuration options
|
118
|
+
|
119
|
+
For example:
|
106
120
|
```ruby
|
107
|
-
|
121
|
+
Premailer.new(
|
122
|
+
html, # html as string
|
123
|
+
with_html_string: true,
|
124
|
+
drop_unmergeable_css_rules: true
|
125
|
+
)
|
108
126
|
```
|
109
127
|
|
110
|
-
[
|
128
|
+
[available options](https://premailer.github.io/premailer/Premailer.html#initialize-instance_method)
|
111
129
|
|
112
130
|
|
113
131
|
## Contributions
|
114
132
|
|
115
|
-
Contributions are most welcome.
|
133
|
+
Contributions are most welcome.
|
134
|
+
Premailer was rotting away in a private SVN repository for too long and could use some TLC.
|
135
|
+
Fork and patch to your heart's content.
|
136
|
+
Please don't increment the version numbers.
|
116
137
|
|
117
138
|
A few areas that are particularly in need of love:
|
118
139
|
|
@@ -129,4 +150,3 @@ and to [Campaign Monitor](https://www.campaignmonitor.com/) for supporting the w
|
|
129
150
|
The source code can be found on [GitHub](https://github.com/premailer/premailer).
|
130
151
|
|
131
152
|
Copyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2017. See [LICENSE.md](https://github.com/premailer/premailer/blob/master/LICENSE.md) for license details.
|
132
|
-
|
@@ -9,13 +9,14 @@ module AdapterHelper
|
|
9
9
|
def is_rgb?(color)
|
10
10
|
pattern = %r{
|
11
11
|
rgb
|
12
|
-
\(\s*
|
13
|
-
(\d{1,3})
|
14
|
-
|
15
|
-
(\d{1,3})
|
16
|
-
|
17
|
-
(\d{1,3})
|
18
|
-
\s*\)
|
12
|
+
\(\s* # literal open, with optional whitespace
|
13
|
+
(\d{1,3}) # capture 1-3 digits
|
14
|
+
(?:\s*,\s*|\s+) # comma or whitespace
|
15
|
+
(\d{1,3}) # capture 1-3 digits
|
16
|
+
(?:\s*,\s*|\s+) # comma or whitespacee
|
17
|
+
(\d{1,3}) # capture 1-3 digits
|
18
|
+
\s*(?:\/\s*\d*\.?\d*%?)? # optional alpha modifier
|
19
|
+
\s*\) # literal close, with optional whitespace
|
19
20
|
}x
|
20
21
|
|
21
22
|
pattern.match(color)
|
@@ -14,7 +14,7 @@ module HtmlToPlainText
|
|
14
14
|
# TODO: add support for DL, OL
|
15
15
|
# TODO: this is not safe and needs a real html parser to work
|
16
16
|
def convert_to_text(html, line_length = 65, from_charset = 'UTF-8')
|
17
|
-
txt = html
|
17
|
+
txt = +html
|
18
18
|
|
19
19
|
# strip text ignored html. Useful for removing
|
20
20
|
# headers and footers that aren't needed in the
|
data/lib/premailer/premailer.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# fout.close
|
16
16
|
#
|
17
17
|
# # Write the plain-text output
|
18
|
-
# fout = File.open("
|
18
|
+
# fout = File.open("output.txt", "w")
|
19
19
|
# fout.puts premailer.to_plain_text
|
20
20
|
# fout.close
|
21
21
|
#
|
@@ -264,7 +264,7 @@ class Premailer
|
|
264
264
|
|
265
265
|
protected
|
266
266
|
def load_css_from_local_file!(path)
|
267
|
-
css_block = ''
|
267
|
+
css_block = +''
|
268
268
|
path.gsub!(/\Afile:/, '')
|
269
269
|
begin
|
270
270
|
File.open(path, "r") do |file|
|
@@ -358,6 +358,7 @@ public
|
|
358
358
|
def append_query_string(doc, qs)
|
359
359
|
return doc if qs.nil?
|
360
360
|
|
361
|
+
qs = +qs
|
361
362
|
qs.to_s.gsub!(/^[\?]*/, '').strip!
|
362
363
|
return doc if qs.empty?
|
363
364
|
|
@@ -473,6 +474,7 @@ public
|
|
473
474
|
|
474
475
|
# @private
|
475
476
|
def self.resolve_link(path, base_path) # :nodoc:
|
477
|
+
path = +path
|
476
478
|
path.strip!
|
477
479
|
resolved = nil
|
478
480
|
if path =~ /\A(?:(https?|ftp|file):)\/\//i
|
data/lib/premailer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: premailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '1.
|
95
|
+
version: '1.16'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '1.
|
102
|
+
version: '1.16'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: redcarpet
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,7 +198,8 @@ licenses:
|
|
198
198
|
- BSD-3-Clause
|
199
199
|
metadata:
|
200
200
|
yard.run: yri
|
201
|
-
|
201
|
+
rubygems_mfa_required: 'true'
|
202
|
+
post_install_message:
|
202
203
|
rdoc_options: []
|
203
204
|
require_paths:
|
204
205
|
- lib
|
@@ -206,15 +207,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
207
|
requirements:
|
207
208
|
- - ">="
|
208
209
|
- !ruby/object:Gem::Version
|
209
|
-
version:
|
210
|
+
version: '3.0'
|
210
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
212
|
requirements:
|
212
213
|
- - ">="
|
213
214
|
- !ruby/object:Gem::Version
|
214
215
|
version: '0'
|
215
216
|
requirements: []
|
216
|
-
rubygems_version: 3.
|
217
|
-
signing_key:
|
217
|
+
rubygems_version: 3.4.10
|
218
|
+
signing_key:
|
218
219
|
specification_version: 4
|
219
220
|
summary: Preflight for HTML e-mail.
|
220
221
|
test_files: []
|