premailer 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e05556033aa604e7c14baa5250b5d7d5baf90e1e
4
- data.tar.gz: 302aff11e259bce3d183f3ec57c387da51ad67a8
3
+ metadata.gz: 4df1d858e475536189c6e91cb30d72194cf8d88b
4
+ data.tar.gz: 39daad276db1125fc182e4da80ce8635debe9959
5
5
  SHA512:
6
- metadata.gz: 78658bc3655cf3eae6f2c11e1bd2cd9974b1eda62518818620e84d222429cbe6bab8e2f827962342059c19df7179d26e534d54f169b3c6adcc6c564473b88594
7
- data.tar.gz: 981be77ba31ab22cb7199c8b885a75be53d28c79f1c8e1c9a38d0dd29d2a74763236c9824ebfbc16464b18c1f485d0f26e1fa4ea4865ca4997ee3bf851c19e6e
6
+ metadata.gz: 335cb3dc57599aba6fe75eba289a250abed56b9180ffc11feb129a0b90f49d9845f92d475329dfc2ba9ec9623e69f295bc844af35a66ca790914988e0f733620
7
+ data.tar.gz: d7401533fdfda12a308377cf6719e38461aafdf4c7f9b3c0eedef3998e8ef27c2126671e077d20e70aea82bb1dec3ee492b4b60545b5590e921bfb4a85628407
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Premailer License
2
2
 
3
- Copyright (c) 2007-2012, Alex Dunae. All rights reserved.
3
+ Copyright (c) 2007-2017, Alex Dunae. All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
6
 
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  ## What is this?
4
4
 
5
- For the best HTML e-mail delivery results, CSS should be inline. This is a
6
- huge pain and a simple newsletter becomes un-managable very quickly. This
5
+ For the best HTML e-mail delivery results, CSS should be inline. This is a
6
+ huge pain and a simple newsletter becomes un-managable very quickly. This
7
7
  script is my solution.
8
8
 
9
9
  * CSS styles are converted to inline style attributes
@@ -14,10 +14,6 @@ script is my solution.
14
14
  - Based on the Email Standards Project's guides
15
15
  * A plain text version is created (optional)
16
16
 
17
- ## Premailer 2.0 is coming
18
-
19
- I'm looking for input on a version 2.0 update to Premailer. Please visit the [Premailer 2.0 Planning Page](https://github.com/premailer/premailer/wiki/New-Premailer-2.0-Planning) and give me your feedback.
20
-
21
17
  ## Installation
22
18
 
23
19
  Install the Premailer gem from RubyGems.
@@ -31,7 +27,6 @@ or add it to your `Gemfile` and run `bundle`.
31
27
  ## Example
32
28
 
33
29
  ```ruby
34
- require 'rubygems' # optional for Ruby 1.9 or above.
35
30
  require 'premailer'
36
31
 
37
32
  premailer = Premailer.new('http://example.com/myfile.html', :warn_level => Premailer::Warnings::SAFE)
@@ -53,9 +48,26 @@ premailer.warnings.each do |w|
53
48
  end
54
49
  ```
55
50
 
51
+ ## Adapters
52
+
53
+ Premailer's default adapter is nokogiri if both nokogiri and hpricot are included in the Gemfile list. However, if you want to use a different adapter, you can choose to.
54
+
55
+ There are four adapters in total (as of premailer 1.9.1)
56
+
57
+ 1. nokogiri (default)
58
+ 2. nokogiri_fast
59
+ 3. nokogumbo
60
+ 4. hpricot (deprecated and will be removed in future premailer releases)
61
+
62
+ `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,
63
+
64
+ ```ruby
65
+ Premailer::Adapter.use = :nokogiri_fast
66
+ ```
67
+
56
68
  ## Ruby Compatibility
57
69
 
58
- Premailer is tested on Ruby 1.8.7, Ruby 1.9.2, Ruby 1.9.3, and Ruby 2.x.0 . It also works on REE. JRuby support is close; contributors are welcome. Checkout the latest build status on the [Travis CI dashboard](https://travis-ci.org/#!/premailer/premailer).
70
+ Premailer is tested on Ruby 2.x.0. JRuby support is close; contributors are welcome. Checkout the latest build status on the [Travis CI dashboard](https://travis-ci.org/#!/premailer/premailer).
59
71
 
60
72
  ## Premailer-specific CSS
61
73
 
@@ -77,7 +89,7 @@ For example
77
89
  table { -premailer-cellspacing: 5; -premailer-width: 500; }
78
90
  ```
79
91
 
80
- will result in
92
+ will result in
81
93
 
82
94
  ```html
83
95
  <table cellspacing='5' width='500'>
@@ -99,9 +111,7 @@ Thanks to [all the wonderful contributors](https://github.com/premailer/premaile
99
111
  Thanks to [Greenhood + Company](http://www.greenhood.com/) for sponsoring some of the 1.5.6 updates,
100
112
  and to [Campaign Monitor](https://www.campaignmonitor.com/) for supporting the web interface.
101
113
 
102
- The web interface can be found at [premailer.dialect.ca](http://premailer.dialect.ca).
103
-
104
- The source code can be found on [GitHub](https://github.com/alexdunae/premailer).
114
+ The source code can be found on [GitHub](https://github.com/premailer/premailer).
105
115
 
106
- Copyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2012. See [LICENSE.md](https://github.com/alexdunae/premailer/blob/master/LICENSE.md) for license details.
116
+ Copyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2017. See [LICENSE.md](https://github.com/alexdunae/premailer/blob/master/LICENSE.md) for license details.
107
117
 
@@ -5,5 +5,6 @@ require 'cgi'
5
5
  require 'css_parser'
6
6
 
7
7
  require 'premailer/adapter'
8
+ require 'premailer/adapter/rgb_to_hex'
8
9
  require 'premailer/html_to_plain_text'
9
10
  require 'premailer/premailer'
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  class Premailer
4
2
  # Manages the adapter classes. Currently supports:
5
3
  #
@@ -4,6 +4,8 @@ class Premailer
4
4
  module Adapter
5
5
  # Hpricot adapter
6
6
  module Hpricot
7
+ include AdapterHelper::RgbToHex
8
+
7
9
  def self.included(base)
8
10
  warn <<eos
9
11
  [DEPRECATED] Premailer's Hpricot adapter will be removed with the next major \
@@ -87,9 +89,14 @@ eos
87
89
  # Duplicate CSS attributes as HTML attributes
88
90
  if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
89
91
  Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
90
- el[html_att] = merged[css_att].gsub(/url\('(.*)'\)/,'\1').gsub(/;$|\s*!important/, '').strip if el[html_att].nil? and not merged[css_att].empty?
92
+ if el[html_att].nil? and not merged[css_att].empty?
93
+ new_html_att = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
94
+ el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
95
+ end
91
96
  merged.instance_variable_get("@declarations").tap do |declarations|
92
- declarations.delete(css_att)
97
+ unless @options[:preserve_style_attribute]
98
+ declarations.delete(css_att)
99
+ end
93
100
  end
94
101
  end
95
102
  end
@@ -5,6 +5,7 @@ class Premailer
5
5
  # Nokogiri adapter
6
6
  module Nokogiri
7
7
 
8
+ include AdapterHelper::RgbToHex
8
9
  # Merge CSS into the HTML document.
9
10
  #
10
11
  # @return [String] an HTML.
@@ -75,9 +76,14 @@ class Premailer
75
76
  # Duplicate CSS attributes as HTML attributes
76
77
  if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
77
78
  Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
78
- el[html_att] = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip if el[html_att].nil? and not merged[css_att].empty?
79
+ if el[html_att].nil? and not merged[css_att].empty?
80
+ new_html_att = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
81
+ el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
82
+ end
79
83
  merged.instance_variable_get("@declarations").tap do |declarations|
80
- declarations.delete(css_att)
84
+ unless @options[:preserve_style_attribute]
85
+ declarations.delete(css_att)
86
+ end
81
87
  end
82
88
  end
83
89
  end
@@ -5,6 +5,7 @@ class Premailer
5
5
  # NokogiriFast adapter
6
6
  module NokogiriFast
7
7
 
8
+ include AdapterHelper::RgbToHex
8
9
  # Merge CSS into the HTML document.
9
10
  #
10
11
  # @return [String] an HTML.
@@ -77,9 +78,14 @@ class Premailer
77
78
  # Duplicate CSS attributes as HTML attributes
78
79
  if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
79
80
  Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
80
- el[html_att] = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip if el[html_att].nil? and not merged[css_att].empty?
81
+ if el[html_att].nil? and not merged[css_att].empty?
82
+ new_html_att = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
83
+ el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
84
+ end
81
85
  merged.instance_variable_get("@declarations").tap do |declarations|
82
- declarations.delete(css_att)
86
+ unless @options[:preserve_style_attribute]
87
+ declarations.delete(css_att)
88
+ end
83
89
  end
84
90
  end
85
91
  end
@@ -241,12 +247,12 @@ class Premailer
241
247
  doc
242
248
  end
243
249
 
244
- private
250
+ private
245
251
 
246
252
  # For very large documents, it is useful to trade off some memory for performance.
247
253
  # We can build an index of the nodes so we can quickly select by id/class/tagname
248
- # instead of search the tree again and again.
249
- #
254
+ # instead of search the tree again and again.
255
+ #
250
256
  # @param page The Nokogiri HTML document to index.
251
257
  # @return [index, set_of_all_nodes, descendants] The index is a hash from key to set of nodes.
252
258
  # The "descendants" is a hash mapping a node to the set of its descendant nodes.
@@ -311,7 +317,7 @@ class Premailer
311
317
 
312
318
  # @param index An index hash returned by make_index
313
319
  # @param base The base set of nodes within which the given spec is to be matched.
314
- # @param intersection_selector A CSS intersection selector string of the form
320
+ # @param intersection_selector A CSS intersection selector string of the form
315
321
  # "hello.world" or "#blue.diamond". This should not contain spaces.
316
322
  # @return Set of nodes matching the given spec that are present in the base set.
317
323
  def narrow_down_nodes(index, base, intersection_selector)
@@ -5,6 +5,7 @@ class Premailer
5
5
  # Nokogiri adapter
6
6
  module Nokogumbo
7
7
 
8
+ include AdapterHelper::RgbToHex
8
9
  # Merge CSS into the HTML document.
9
10
  #
10
11
  # @return [String] an HTML.
@@ -75,9 +76,14 @@ class Premailer
75
76
  # Duplicate CSS attributes as HTML attributes
76
77
  if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
77
78
  Premailer::RELATED_ATTRIBUTES[el.name].each do |css_att, html_att|
78
- el[html_att] = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip if el[html_att].nil? and not merged[css_att].empty?
79
+ if el[html_att].nil? and not merged[css_att].empty?
80
+ new_html_att = merged[css_att].gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip
81
+ el[html_att] = css_att.end_with?('color') && @options[:rgb_to_hex_attributes] ? ensure_hex(new_html_att) : new_html_att
82
+ end
79
83
  merged.instance_variable_get("@declarations").tap do |declarations|
80
- declarations.delete(css_att)
84
+ unless @options[:preserve_style_attribute]
85
+ declarations.delete(css_att)
86
+ end
81
87
  end
82
88
  end
83
89
  end
@@ -0,0 +1,33 @@
1
+ # RGB helper for adapters, currently only nokogiri supported
2
+
3
+ module AdapterHelper
4
+ module RgbToHex
5
+ def to_hex(str)
6
+ str.to_i.to_s(16).rjust(2, '0').upcase
7
+ end
8
+
9
+ def is_rgb?(color)
10
+ pattern = %r{
11
+ rgb
12
+ \(\s* # literal open, with optional whitespace
13
+ (\d{1,3}) # capture 1-3 digits
14
+ \s*,\s* # comma, with optional whitespace
15
+ (\d{1,3}) # capture 1-3 digits
16
+ \s*,\s* # comma, with optional whitespace
17
+ (\d{1,3}) # capture 1-3 digits
18
+ \s*\) # literal close, with optional whitespace
19
+ }x
20
+
21
+ pattern.match(color)
22
+ end
23
+
24
+ def ensure_hex(color)
25
+ match_data = is_rgb?(color)
26
+ if match_data
27
+ "#{to_hex(match_data[1])}#{to_hex(match_data[2])}#{to_hex(match_data[3])}"
28
+ else
29
+ color
30
+ end
31
+ end
32
+ end
33
+ end
@@ -156,7 +156,9 @@ class Premailer
156
156
  # @option options [String] :base_url Used to calculate absolute URLs for local files.
157
157
  # @option options [Array(String)] :css Manually specify CSS stylesheets.
158
158
  # @option options [Boolean] :css_to_attributes Copy related CSS attributes into HTML attributes (e.g. background-color to bgcolor)
159
+ # @option options [Boolean] :preserve_style_attribute Preserve original style attribute
159
160
  # @option options [String] :css_string Pass CSS as a string
161
+ # @option options [Boolean] :rgb_to_hex_attributes Convert RBG to Hex colors, default false
160
162
  # @option options [Boolean] :remove_ids Remove ID attributes whenever possible and convert IDs used as anchors to hashed to avoid collisions in webmail programs. Default is false.
161
163
  # @option options [Boolean] :remove_classes Remove class attributes. Default is false.
162
164
  # @option options [Boolean] :remove_comments Remove html comments. Default is false.
@@ -180,6 +182,7 @@ class Premailer
180
182
  :line_length => 65,
181
183
  :link_query_string => nil,
182
184
  :base_url => nil,
185
+ :rgb_to_hex_attributes => true,
183
186
  :remove_classes => false,
184
187
  :remove_ids => false,
185
188
  :remove_comments => false,
@@ -187,6 +190,7 @@ class Premailer
187
190
  :reset_contenteditable => true,
188
191
  :css => [],
189
192
  :css_to_attributes => true,
193
+ :preserve_style_attribute => false,
190
194
  :with_html_string => false,
191
195
  :css_string => nil,
192
196
  :preserve_styles => false,
@@ -1,4 +1,4 @@
1
1
  class Premailer
2
2
  # Premailer version.
3
- VERSION = '1.9.1'.freeze
3
+ VERSION = '1.9.2'.freeze
4
4
  end
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.9.1
4
+ version: 1.9.2
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-01-15 00:00:00.000000000 Z
11
+ date: 2017-02-03 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.5
19
+ version: 1.4.8
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.5
26
+ version: 1.4.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: htmlentities
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +207,7 @@ files:
207
207
  - lib/premailer/adapter/nokogiri.rb
208
208
  - lib/premailer/adapter/nokogiri_fast.rb
209
209
  - lib/premailer/adapter/nokogumbo.rb
210
+ - lib/premailer/adapter/rgb_to_hex.rb
210
211
  - lib/premailer/executor.rb
211
212
  - lib/premailer/html_to_plain_text.rb
212
213
  - lib/premailer/premailer.rb
@@ -232,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
233
  version: '0'
233
234
  requirements: []
234
235
  rubyforge_project:
235
- rubygems_version: 2.5.1
236
+ rubygems_version: 2.6.8
236
237
  signing_key:
237
238
  specification_version: 4
238
239
  summary: Preflight for HTML e-mail.