premailer 1.16.0 → 1.23.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/lib/premailer/adapter/nokogiri.rb +12 -13
- data/lib/premailer/adapter/nokogiri_fast.rb +12 -11
- data/lib/premailer/adapter/nokogumbo.rb +11 -8
- data/lib/premailer/adapter/rgb_to_hex.rb +8 -7
- data/lib/premailer/cached_rule_set.rb +12 -0
- data/lib/premailer/premailer.rb +7 -3
- data/lib/premailer/version.rb +1 -1
- data/lib/premailer.rb +1 -0
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea6e9ef14eeb9cdffd7e718f976d9e71e50fb1f154c947c9ee9b97399f1aceeb
|
4
|
+
data.tar.gz: 02d8f609acce2abb421f607e1937e35e4d36f12c609386bef808378f56e9753c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1e580add5528f240e2170bb2aed29171227d35ce8acc31d5c8ceed7ea3f211072f8db8257f9665bef5838c606c9f77a56a792482c3d5f730025a6448374a4bb
|
7
|
+
data.tar.gz: 3afd5c1330b5b1ddff158e77260c0fc87876779e839f5f1beb641ea4c00d424db97c0b5410a566f08ac97a3615cd125c8d9198a77d5edf3ee5959abcc2058440
|
@@ -61,15 +61,21 @@ class Premailer
|
|
61
61
|
doc.search("*[@style]").each do |el|
|
62
62
|
style = el.attributes['style'].to_s
|
63
63
|
|
64
|
-
declarations = []
|
65
|
-
|
66
|
-
rs
|
67
|
-
|
64
|
+
declarations = style.scan(/\[SPEC\=([\d]+)\[(.[^\]\]]*)\]\]/).filter_map do |declaration|
|
65
|
+
rs = Premailer::CachedRuleSet.new(nil, declaration[1].to_s, declaration[0].to_i)
|
66
|
+
rs.expand_shorthand!
|
67
|
+
rs
|
68
|
+
rescue ArgumentError => e
|
69
|
+
raise e if @options[:rule_set_exceptions]
|
68
70
|
end
|
69
71
|
|
70
72
|
# Perform style folding
|
71
73
|
merged = CssParser.merge(declarations)
|
72
|
-
|
74
|
+
begin
|
75
|
+
merged.expand_shorthand!
|
76
|
+
rescue ArgumentError => e
|
77
|
+
raise e if @options[:rule_set_exceptions]
|
78
|
+
end
|
73
79
|
|
74
80
|
# Duplicate CSS attributes as HTML attributes
|
75
81
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
@@ -233,14 +239,7 @@ class Premailer
|
|
233
239
|
thing.gsub! entity, replacement
|
234
240
|
end
|
235
241
|
end
|
236
|
-
|
237
|
-
# However, we really don't want to hardcode this. ASCII-8BIT should be the default, but not the only option.
|
238
|
-
encoding = if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
|
239
|
-
thing = thing.force_encoding(@options[:input_encoding]).encode!
|
240
|
-
@options[:input_encoding]
|
241
|
-
else
|
242
|
-
@options[:input_encoding] || (RUBY_PLATFORM == 'java' ? nil : 'BINARY')
|
243
|
-
end
|
242
|
+
encoding = @options[:input_encoding] || (RUBY_PLATFORM == 'java' ? nil : 'BINARY')
|
244
243
|
doc = if @options[:html_fragment]
|
245
244
|
::Nokogiri::HTML.fragment(thing, encoding)
|
246
245
|
else
|
@@ -67,13 +67,21 @@ class Premailer
|
|
67
67
|
|
68
68
|
declarations = []
|
69
69
|
style.scan(/\[SPEC\=([\d]+)\[(.[^\]\]]*)\]\]/).each do |declaration|
|
70
|
-
|
71
|
-
|
70
|
+
begin
|
71
|
+
rs = CssParser::RuleSet.new(nil, declaration[1].to_s, declaration[0].to_i)
|
72
|
+
declarations << rs
|
73
|
+
rescue ArgumentError => e
|
74
|
+
raise e if @options[:rule_set_exceptions]
|
75
|
+
end
|
72
76
|
end
|
73
77
|
|
74
78
|
# Perform style folding
|
75
79
|
merged = CssParser.merge(declarations)
|
76
|
-
|
80
|
+
begin
|
81
|
+
merged.expand_shorthand!
|
82
|
+
rescue ArgumentError => e
|
83
|
+
raise e if @options[:rule_set_exceptions]
|
84
|
+
end
|
77
85
|
|
78
86
|
# Duplicate CSS attributes as HTML attributes
|
79
87
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
@@ -237,14 +245,7 @@ class Premailer
|
|
237
245
|
thing.gsub! entity, replacement
|
238
246
|
end
|
239
247
|
end
|
240
|
-
|
241
|
-
# However, we really don't want to hardcode this. ASCII-8BIT should be the default, but not the only option.
|
242
|
-
encoding = if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
|
243
|
-
thing = thing.force_encoding(@options[:input_encoding]).encode!
|
244
|
-
@options[:input_encoding]
|
245
|
-
else
|
246
|
-
@options[:input_encoding] || (RUBY_PLATFORM == 'java' ? nil : 'BINARY')
|
247
|
-
end
|
248
|
+
encoding = @options[:input_encoding] || (RUBY_PLATFORM == 'java' ? nil : 'BINARY')
|
248
249
|
doc = if @options[:html_fragment]
|
249
250
|
::Nokogiri::HTML.fragment(thing, encoding)
|
250
251
|
else
|
@@ -61,13 +61,21 @@ class Premailer
|
|
61
61
|
|
62
62
|
declarations = []
|
63
63
|
style.scan(/\[SPEC\=([\d]+)\[(.[^\]\]]*)\]\]/).each do |declaration|
|
64
|
-
|
65
|
-
|
64
|
+
begin
|
65
|
+
rs = CssParser::RuleSet.new(nil, declaration[1].to_s, declaration[0].to_i)
|
66
|
+
declarations << rs
|
67
|
+
rescue ArgumentError => e
|
68
|
+
raise e if @options[:rule_set_exceptions]
|
69
|
+
end
|
66
70
|
end
|
67
71
|
|
68
72
|
# Perform style folding
|
69
73
|
merged = CssParser.merge(declarations)
|
70
|
-
|
74
|
+
begin
|
75
|
+
merged.expand_shorthand!
|
76
|
+
rescue ArgumentError => e
|
77
|
+
raise e if @options[:rule_set_exceptions]
|
78
|
+
end
|
71
79
|
|
72
80
|
# Duplicate CSS attributes as HTML attributes
|
73
81
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
@@ -231,11 +239,6 @@ class Premailer
|
|
231
239
|
thing.gsub! entity, replacement
|
232
240
|
end
|
233
241
|
end
|
234
|
-
# Default encoding is ASCII-8BIT (binary) per http://groups.google.com/group/nokogiri-talk/msg/0b81ef0dc180dc74
|
235
|
-
# However, we really don't want to hardcode this. ASCII-8BIT should be the default, but not the only option.
|
236
|
-
if thing.is_a?(String) and RUBY_VERSION =~ /1.9/
|
237
|
-
thing = thing.force_encoding(@options[:input_encoding]).encode!
|
238
|
-
end
|
239
242
|
doc = if @options[:html_fragment]
|
240
243
|
::Nokogiri::HTML5.fragment(thing)
|
241
244
|
else
|
@@ -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)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Premailer
|
2
|
+
class CachedRuleSet < CssParser::RuleSet
|
3
|
+
# we call this early to find errors but css-parser calls it in .merge again
|
4
|
+
# so to prevent slowdown and bugs we refuse to run it twice on the same ruleset
|
5
|
+
# ideally should be upstreamed into css-parser
|
6
|
+
def expand_shorthand!
|
7
|
+
super unless @expand_shorthand
|
8
|
+
ensure
|
9
|
+
@expand_shorthand = true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/premailer/premailer.rb
CHANGED
@@ -168,7 +168,8 @@ class Premailer
|
|
168
168
|
# @option options [Boolean] :preserve_reset Whether to preserve styles associated with the MailChimp reset code. Default is true.
|
169
169
|
# @option options [Boolean] :with_html_string Whether the html param should be treated as a raw string. Default is false.
|
170
170
|
# @option options [Boolean] :verbose Whether to print errors and warnings to <tt>$stderr</tt>. Default is false.
|
171
|
-
# @option options [Boolean] :io_exceptions Throws exceptions on I/O errors.
|
171
|
+
# @option options [Boolean] :io_exceptions Throws exceptions on I/O errors. Default is false.
|
172
|
+
# @option options [Boolean] :rule_set_exceptions Throws exceptions on invalid values in CSS Parser rule sets. Default is true.
|
172
173
|
# @option options [Boolean] :include_link_tags Whether to include css from <tt>link rel=stylesheet</tt> tags. Default is true.
|
173
174
|
# @option options [Boolean] :include_style_tags Whether to include css from <tt>style</tt> tags. Default is true.
|
174
175
|
# @option options [String] :input_encoding Manually specify the source documents encoding. This is a good idea. Default is ASCII-8BIT.
|
@@ -200,6 +201,7 @@ class Premailer
|
|
200
201
|
:verbose => false,
|
201
202
|
:debug => false,
|
202
203
|
:io_exceptions => false,
|
204
|
+
:rule_set_exceptions => true,
|
203
205
|
:include_link_tags => true,
|
204
206
|
:include_style_tags => true,
|
205
207
|
:input_encoding => 'ASCII-8BIT',
|
@@ -233,7 +235,8 @@ class Premailer
|
|
233
235
|
@css_parser = CssParser::Parser.new({
|
234
236
|
:absolute_paths => true,
|
235
237
|
:import => true,
|
236
|
-
:io_exceptions => @options[:io_exceptions]
|
238
|
+
:io_exceptions => @options[:io_exceptions],
|
239
|
+
:rule_set_exceptions => @options[:rule_set_exceptions]
|
237
240
|
})
|
238
241
|
|
239
242
|
@adapter_class = Adapter.find @options[:adapter]
|
@@ -504,7 +507,8 @@ public
|
|
504
507
|
|
505
508
|
# Check <tt>CLIENT_SUPPORT_FILE</tt> for any CSS warnings
|
506
509
|
def check_client_support # :nodoc:
|
507
|
-
|
510
|
+
kwargs = Psych::VERSION >= '4' ? { aliases: true } : {}
|
511
|
+
@client_support ||= Psych.load(File.open(CLIENT_SUPPORT_FILE), **kwargs)
|
508
512
|
|
509
513
|
warnings = []
|
510
514
|
properties = []
|
data/lib/premailer/version.rb
CHANGED
data/lib/premailer.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.23.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-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.12.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.12.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: htmlentities
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/premailer/adapter/nokogiri_fast.rb
|
188
188
|
- lib/premailer/adapter/nokogumbo.rb
|
189
189
|
- lib/premailer/adapter/rgb_to_hex.rb
|
190
|
+
- lib/premailer/cached_rule_set.rb
|
190
191
|
- lib/premailer/executor.rb
|
191
192
|
- lib/premailer/html_to_plain_text.rb
|
192
193
|
- lib/premailer/premailer.rb
|
@@ -197,7 +198,8 @@ licenses:
|
|
197
198
|
- BSD-3-Clause
|
198
199
|
metadata:
|
199
200
|
yard.run: yri
|
200
|
-
|
201
|
+
rubygems_mfa_required: 'true'
|
202
|
+
post_install_message:
|
201
203
|
rdoc_options: []
|
202
204
|
require_paths:
|
203
205
|
- lib
|
@@ -205,15 +207,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
207
|
requirements:
|
206
208
|
- - ">="
|
207
209
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
210
|
+
version: '3.0'
|
209
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
212
|
requirements:
|
211
213
|
- - ">="
|
212
214
|
- !ruby/object:Gem::Version
|
213
215
|
version: '0'
|
214
216
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
216
|
-
signing_key:
|
217
|
+
rubygems_version: 3.4.10
|
218
|
+
signing_key:
|
217
219
|
specification_version: 4
|
218
220
|
summary: Preflight for HTML e-mail.
|
219
221
|
test_files: []
|