premailer 1.10.0 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/premailer.rb +1 -0
- data/lib/premailer/adapter/nokogiri.rb +5 -8
- data/lib/premailer/adapter/nokogiri_fast.rb +5 -8
- data/lib/premailer/adapter/nokogumbo.rb +5 -7
- data/lib/premailer/premailer.rb +13 -13
- data/lib/premailer/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c41d00b9329efc665261de336e908985573ae9c
|
4
|
+
data.tar.gz: e1dec81980ea9f8abde0e30c0044937fdf5a7472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761dc0a5f8ec61ad3997aa8a6d2042de955ff81531e02d4bfb4beb27915e98b059f39f2d2428e491c5a998c5de2bac7846ce902472c0c0da014ea70cb8b91d21
|
7
|
+
data.tar.gz: d2e8af67edf061916446e7ba4172f0b6befebd68d6b6c2815acc06f7c10d5a6b10951637ba07eb3f1a7c6bbaf072e1a39b45c102243d54427878c33259f4d7c1
|
data/README.md
CHANGED
@@ -52,12 +52,14 @@ end
|
|
52
52
|
|
53
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
54
|
|
55
|
-
There are three adapters in total (as of premailer 1.
|
55
|
+
There are three adapters in total (as of premailer 1.10.0)
|
56
56
|
|
57
57
|
1. nokogiri (default)
|
58
58
|
2. nokogiri_fast
|
59
59
|
3. nokogumbo
|
60
60
|
|
61
|
+
hpricot adapter removed due to its EOL, please use `~>1.9.0` version if You still need it..
|
62
|
+
|
61
63
|
`NokogiriFast` adapter improves the Algorithmic complexity of the running time by 20x with a slight compensation on memory. To switch to any of these adapters, add the following line. For example, if you want to include the `NokogiriFast` adapter,
|
62
64
|
|
63
65
|
```ruby
|
@@ -66,7 +68,7 @@ Premailer::Adapter.use = :nokogiri_fast
|
|
66
68
|
|
67
69
|
## Ruby Compatibility
|
68
70
|
|
69
|
-
Premailer is tested on Ruby 2.
|
71
|
+
Premailer is tested on Ruby 2.1 and above. JRuby support is close; contributors are welcome. Checkout the latest build status on the [Travis CI dashboard](https://travis-ci.org/#!/premailer/premailer).
|
70
72
|
|
71
73
|
## Premailer-specific CSS
|
72
74
|
|
data/lib/premailer.rb
CHANGED
@@ -77,12 +77,12 @@ class Premailer
|
|
77
77
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
78
78
|
Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
|
79
79
|
if el[html_att].nil? and not merged[css_att].empty?
|
80
|
-
new_html_att = merged[css_att].gsub(/url\(['
|
80
|
+
new_html_att = merged[css_att].gsub(/url\(['"](.*)['"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
|
81
81
|
el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
|
82
82
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
unless @options[:preserve_style_attribute]
|
84
|
+
merged.instance_variable_get("@declarations").tap do |declarations|
|
85
|
+
declarations.delete(css_att)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -91,10 +91,7 @@ class Premailer
|
|
91
91
|
merged.create_shorthand! if @options[:create_shorthands]
|
92
92
|
|
93
93
|
# write the inline STYLE attribute
|
94
|
-
|
95
|
-
attributes = Premailer.escape_string(merged.declarations_to_s).split(/;(?![^(]*\))/).map(&:strip)
|
96
|
-
attributes = attributes.map { |attr| [attr.split(':').first, attr] }.sort_by { |pair| pair.first }.map { |pair| pair[1] }
|
97
|
-
el['style'] = attributes.join('; ') + ";"
|
94
|
+
el['style'] = merged.declarations_to_s
|
98
95
|
end
|
99
96
|
|
100
97
|
doc = write_unmergable_css_rules(doc, @unmergable_rules)
|
@@ -79,12 +79,12 @@ class Premailer
|
|
79
79
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
80
80
|
Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
|
81
81
|
if el[html_att].nil? and not merged[css_att].empty?
|
82
|
-
new_html_att = merged[css_att].gsub(/url\(['
|
82
|
+
new_html_att = merged[css_att].gsub(/url\(['"](.*)['"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
|
83
83
|
el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
|
84
84
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
unless @options[:preserve_style_attribute]
|
86
|
+
merged.instance_variable_get("@declarations").tap do |declarations|
|
87
|
+
declarations.delete(css_att)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -93,10 +93,7 @@ class Premailer
|
|
93
93
|
merged.create_shorthand! if @options[:create_shorthands]
|
94
94
|
|
95
95
|
# write the inline STYLE attribute
|
96
|
-
|
97
|
-
attributes = Premailer.escape_string(merged.declarations_to_s).split(/;(?![^(]*\))/).map(&:strip)
|
98
|
-
attributes = attributes.map { |attr| [attr.split(':').first, attr] }.sort_by { |pair| pair.first }.map { |pair| pair[1] }
|
99
|
-
el['style'] = attributes.join('; ') + ";"
|
96
|
+
el['style'] = merged.declarations_to_s
|
100
97
|
end
|
101
98
|
|
102
99
|
doc = write_unmergable_css_rules(doc, @unmergable_rules)
|
@@ -77,12 +77,12 @@ class Premailer
|
|
77
77
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
78
78
|
Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
|
79
79
|
if el[html_att].nil? and not merged[css_att].empty?
|
80
|
-
new_html_att = merged[css_att].gsub(/url\(['
|
80
|
+
new_html_att = merged[css_att].gsub(/url\(['"](.*)['"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
|
81
81
|
el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
|
82
82
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
unless @options[:preserve_style_attribute]
|
84
|
+
merged.instance_variable_get("@declarations").tap do |declarations|
|
85
|
+
declarations.delete(css_att)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -91,9 +91,7 @@ class Premailer
|
|
91
91
|
merged.create_shorthand! if @options[:create_shorthands]
|
92
92
|
|
93
93
|
# write the inline STYLE attribute
|
94
|
-
|
95
|
-
attributes = attributes.map { |attr| [attr.split(':').first, attr] }.sort_by { |pair| pair.first }.map { |pair| pair[1] }
|
96
|
-
el['style'] = attributes.join('; ') + ";"
|
94
|
+
el['style'] = merged.declarations_to_s
|
97
95
|
end
|
98
96
|
|
99
97
|
doc = write_unmergable_css_rules(doc, @unmergable_rules)
|
data/lib/premailer/premailer.rb
CHANGED
@@ -221,9 +221,9 @@ class Premailer
|
|
221
221
|
@unmergable_rules = nil
|
222
222
|
|
223
223
|
if @options[:base_url]
|
224
|
-
@base_url = URI.parse(@options.delete(:base_url))
|
224
|
+
@base_url = Addressable::URI.parse(@options.delete(:base_url))
|
225
225
|
elsif not @is_local_file
|
226
|
-
@base_url = URI.parse(@html_file)
|
226
|
+
@base_url = Addressable::URI.parse(@html_file)
|
227
227
|
end
|
228
228
|
|
229
229
|
@css_parser = CssParser::Parser.new({
|
@@ -369,7 +369,7 @@ public
|
|
369
369
|
next if href[0,1] =~ /[\#\{\[\<\%]/ # don't bother with anchors or special-looking links
|
370
370
|
|
371
371
|
begin
|
372
|
-
href = URI.parse(href)
|
372
|
+
href = Addressable::URI.parse(href)
|
373
373
|
|
374
374
|
if current_host and href.host != nil and href.host != current_host
|
375
375
|
$stderr.puts "Skipping append_query_string for: #{href.to_s} because host is no good" if @options[:verbose]
|
@@ -389,7 +389,7 @@ public
|
|
389
389
|
end
|
390
390
|
|
391
391
|
el['href'] = href.to_s
|
392
|
-
rescue URI::
|
392
|
+
rescue Addressable::URI::InvalidURIError => e
|
393
393
|
$stderr.puts "Skipping append_query_string for: #{href.to_s} (#{e.message})" if @options[:verbose]
|
394
394
|
next
|
395
395
|
end
|
@@ -415,7 +415,7 @@ public
|
|
415
415
|
#
|
416
416
|
# Returns a document.
|
417
417
|
def convert_inline_links(doc, base_uri) # :nodoc:
|
418
|
-
base_uri = URI.parse(base_uri) unless base_uri.kind_of?(URI)
|
418
|
+
base_uri = Addressable::URI.parse(base_uri) unless base_uri.kind_of?(Addressable::URI)
|
419
419
|
|
420
420
|
append_qs = @options[:link_query_string] || ''
|
421
421
|
escape_attrs = @options[:escape_url_attributes]
|
@@ -434,7 +434,7 @@ public
|
|
434
434
|
|
435
435
|
if tag.attributes[attribute].to_s =~ /^http/i
|
436
436
|
begin
|
437
|
-
merged = URI.parse(tag.attributes[attribute])
|
437
|
+
merged = Addressable::URI.parse(tag.attributes[attribute])
|
438
438
|
rescue; next; end
|
439
439
|
else
|
440
440
|
begin
|
@@ -442,13 +442,13 @@ public
|
|
442
442
|
rescue
|
443
443
|
begin
|
444
444
|
next unless escape_attrs
|
445
|
-
merged = Premailer.resolve_link(URI.escape(tag.attributes[attribute].to_s), base_uri)
|
445
|
+
merged = Premailer.resolve_link(Addressable::URI.escape(tag.attributes[attribute].to_s), base_uri)
|
446
446
|
rescue; end
|
447
447
|
end
|
448
448
|
end
|
449
449
|
|
450
450
|
# make sure 'merged' is a URI
|
451
|
-
merged = URI.parse(merged.to_s) unless merged.kind_of?(URI)
|
451
|
+
merged = Addressable::URI.parse(merged.to_s) unless merged.kind_of?(Addressable::URI)
|
452
452
|
tag[attribute] = merged.to_s
|
453
453
|
end # end of each tag
|
454
454
|
end # end of each attrs
|
@@ -476,12 +476,12 @@ public
|
|
476
476
|
if path =~ /\A(?:(https?|ftp|file):)\/\//i
|
477
477
|
resolved = path
|
478
478
|
Premailer.canonicalize(resolved)
|
479
|
-
elsif base_path.kind_of?(URI)
|
480
|
-
resolved = base_path.
|
479
|
+
elsif base_path.kind_of?(Addressable::URI)
|
480
|
+
resolved = base_path.join(path)
|
481
481
|
Premailer.canonicalize(resolved)
|
482
482
|
elsif base_path.kind_of?(String) and base_path =~ /\A(?:(?:https?|ftp|file):)\/\//i
|
483
|
-
resolved = URI.parse(base_path)
|
484
|
-
resolved = resolved.
|
483
|
+
resolved = Addressable::URI.parse(base_path)
|
484
|
+
resolved = resolved.join(path)
|
485
485
|
Premailer.canonicalize(resolved)
|
486
486
|
else
|
487
487
|
File.expand_path(path, File.dirname(base_path))
|
@@ -500,7 +500,7 @@ public
|
|
500
500
|
|
501
501
|
# from http://www.ruby-forum.com/topic/140101
|
502
502
|
def self.canonicalize(uri) # :nodoc:
|
503
|
-
u = uri.kind_of?(URI) ? uri : URI.parse(uri.to_s)
|
503
|
+
u = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI.parse(uri.to_s)
|
504
504
|
u.normalize!
|
505
505
|
newpath = u.path
|
506
506
|
while newpath.gsub!(%r{([^/]+)/\.\./?}) { |match|
|
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.10.
|
4
|
+
version: 1.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-09 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.4.
|
19
|
+
version: 1.4.10
|
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.4.
|
26
|
+
version: 1.4.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: htmlentities
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
226
|
version: '0'
|
213
227
|
requirements: []
|
214
228
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.
|
229
|
+
rubygems_version: 2.6.8
|
216
230
|
signing_key:
|
217
231
|
specification_version: 4
|
218
232
|
summary: Preflight for HTML e-mail.
|