premailer 1.8.0 → 1.8.1

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: bd6a0eccd0fddd3ad53178ee0b715c3d1b770491
4
- data.tar.gz: 5768d084e017e213f46ae790ecc6003f9eb82573
3
+ metadata.gz: 780d807660eab934f32306d9ca689dab41f37a09
4
+ data.tar.gz: a250c50348de81e092ca35ac0092d09c952e0606
5
5
  SHA512:
6
- metadata.gz: bc9b3bb5aa1ca359b15a45aec3f51b7ae9375483353f76d6a2ace0463a7b5d857721f10b3149f08adbf586cb6f2007271900933afdaac6d95d5e2bc625cc2c5b
7
- data.tar.gz: 2939cfd440e8f10c2bba6f685bc0f538930b0c97532ff2f1cc3ccbe96ba22c4137821c918a80690693bf5aa0c6afbe3353204cbb01afc30f099466b952e0c20d
6
+ metadata.gz: b00c9baf702aff645325d6b10a71c98def9de70752b11e15f79f0d4218ae73a307a6ff826571148bafb335f477a4b3e909b97ec05ff6d6aa06c15325dd39e19d
7
+ data.tar.gz: b7305f4db9b442bbd2944fe05fdfcb823b963888a1d75156465be8505d934c6f7748d4cd28976ee9829f3ed0493358d005d1080d4f41927f5a980f0be2dcc91c
@@ -5,5 +5,19 @@ rvm:
5
5
  - 1.9.2
6
6
  - 1.9.3
7
7
  - 2.0.0
8
- - jruby
9
- - ree
8
+ - ree
9
+ gemfile:
10
+ - Gemfile
11
+ - gemfiles/ruby187.gemfile
12
+ matrix:
13
+ exclude:
14
+ - rvm: 1.8.7
15
+ gemfile: Gemfile
16
+ - rvm: 1.9.2
17
+ gemfile: gemfiles/ruby187.gemfile
18
+ - rvm: 1.9.3
19
+ gemfile: gemfiles/ruby187.gemfile
20
+ - rvm: 2.0.0
21
+ gemfile: gemfiles/ruby187.gemfile
22
+ - rvm: ree
23
+ gemfile: Gemfile
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Premailer README
1
+ # Premailer README [![Build Status](https://travis-ci.org/premailer/premailer.png?branch=master)](https://travis-ci.org/premailer/premailer)
2
2
 
3
3
  ## What is this?
4
4
 
@@ -16,7 +16,7 @@ script is my solution.
16
16
 
17
17
  ## Premailer 2.0 is coming
18
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/alexdunae/premailer/wiki/Premailer-2.0-Planning) and give me your feedback.
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
20
 
21
21
  ## Installation
22
22
 
@@ -54,7 +54,7 @@ end
54
54
 
55
55
  ## Ruby Compatibility
56
56
 
57
- Premailer is tested on Ruby 1.8.7, Ruby 1.9.2 and Ruby 1.9.3 . It also works on REE. JRuby support is close; contributors are welcome. Checkout the latest build status on the [Travis CI dashboard](http://travis-ci.org/#!/alexdunae/premailer).
57
+ Premailer is tested on Ruby 1.8.7, Ruby 1.9.2, Ruby 1.9.3, and Ruby 2.0.0 . It also works on REE. JRuby support is close; contributors are welcome. Checkout the latest build status on the [Travis CI dashboard](http://travis-ci.org/#!/premailer/premailer).
58
58
 
59
59
  ## Premailer-specific CSS
60
60
 
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'css_parser', :git => 'git://github.com/premailer/css_parser.git'
4
+ gem 'webmock', :group => [:development, :test]
5
+
6
+
7
+ gemspec :name => 'ruby187'
8
+
9
+ gem "ripper", :group => :development, :platforms => :mri_18
10
+
11
+ gem "coveralls", :require => false, :platforms => [:mri_19, :mri_20], :group => :development
@@ -0,0 +1,31 @@
1
+ GEM_ROOT = File.dirname(File.dirname(__FILE__)).freeze unless defined?(GEM_ROOT)
2
+
3
+ lib_path = File.expand_path('lib', GEM_ROOT)
4
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include? lib_path
5
+
6
+ require 'premailer/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "premailer"
10
+ s.version = Premailer::VERSION.dup
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+ s.summary = "Preflight for HTML e-mail."
13
+ s.email = "code@dunae.ca"
14
+ s.homepage = "http://premailer.dialect.ca/"
15
+ s.description = "Improve the rendering of HTML emails by making CSS inline, converting links and warning about unsupported code."
16
+ s.has_rdoc = true
17
+ s.author = "Alex Dunae"
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ s.add_dependency('css_parser', '>= 1.3.5')
22
+ s.add_dependency('htmlentities', '>= 4.0.0')
23
+ s.add_development_dependency "bundler", "~> 1.3"
24
+ s.add_development_dependency('rake', ['~> 0.8', '!= 0.9.0'])
25
+ s.add_development_dependency('hpricot', '>= 0.8.3')
26
+ s.add_development_dependency('nokogiri', '~> 1.5.10')
27
+ s.add_development_dependency('yard', '~> 0.8.7')
28
+ s.add_development_dependency('redcarpet', '~> 2.3.0')
29
+ s.add_development_dependency "yard-redcarpet-ext", "~> 0.0.3"
30
+ end
31
+
@@ -121,9 +121,9 @@ class Premailer
121
121
  @processed_doc = doc
122
122
  if is_xhtml?
123
123
  # we don't want to encode carriage returns
124
- @processed_doc.to_xhtml(:encoding => nil).gsub(/&\#(xD|13);/i, "\r")
124
+ @processed_doc.to_xhtml(:encoding => @options[:output_encoding]).gsub(/&\#(xD|13);/i, "\r")
125
125
  else
126
- @processed_doc.to_html
126
+ @processed_doc.to_html(:encoding => @options[:output_encoding])
127
127
  end
128
128
  end
129
129
 
@@ -186,10 +186,10 @@ class Premailer
186
186
  # TODO: duplicate options
187
187
  if @options[:with_html_string] or @options[:inline] or input.respond_to?(:read)
188
188
  thing = input
189
- elsif @is_local_file
189
+ elsif @is_local_file
190
190
  @base_dir = File.dirname(input)
191
191
  thing = File.open(input, 'r')
192
- else
192
+ else
193
193
  thing = open(input)
194
194
  end
195
195
 
@@ -202,15 +202,8 @@ class Premailer
202
202
 
203
203
  # Handle HTML entities
204
204
  if @options[:replace_html_entities] == true and thing.is_a?(String)
205
- if RUBY_VERSION =~ /1.9/
206
- html_entity_ruby_version = "1.9"
207
- elsif RUBY_VERSION =~ /1.8/
208
- html_entity_ruby_version = "1.8"
209
- end
210
- if html_entity_ruby_version
211
- HTML_ENTITIES[html_entity_ruby_version].map do |entity, replacement|
212
- thing.gsub! entity, replacement
213
- end
205
+ HTML_ENTITIES.map do |entity, replacement|
206
+ thing.gsub! entity, replacement
214
207
  end
215
208
  end
216
209
  # Default encoding is ASCII-8BIT (binary) per http://groups.google.com/group/nokogiri-talk/msg/0b81ef0dc180dc74
@@ -52,6 +52,10 @@ opts = OptionParser.new do |opts|
52
52
  options[:line_length] = v
53
53
  end
54
54
 
55
+ opts.on("-e", "--entities", "Output HTML entities instead of UTF-8 when using Nokogiri") do |v|
56
+ options[:output_encoding] = "US-ASCII"
57
+ end
58
+
55
59
  opts.on("-d", "--io-exceptions", "Abort on I/O errors") do |v|
56
60
  options[:io_exceptions] = v
57
61
  end
@@ -45,38 +45,17 @@ class Premailer
45
45
  # list of HTMLEntities to fix
46
46
  # source: http://stackoverflow.com/questions/2812781/how-to-convert-webpage-apostrophe-8217-to-ascii-39-in-ruby-1-
47
47
  HTML_ENTITIES = {
48
- "1.8" => {
49
- "\342\200\231" => "'",
50
- "\342\200\246" => "...",
51
- "\342\200\176" => "'",
52
- "\342\200\177" => "'",
53
- "\342\200\230" => "'",
54
- "\342\200\231" => "'",
55
- "\342\200\232" => ',',
56
- "\342\200\233" => "'",
57
- "\342\200\234" => '"',
58
- "\342\200\235" => '"',
59
- "\342\200\041" => '-',
60
- "\342\200\174" => '-',
61
- "\342\200\220" => '-',
62
- "\342\200\223" => '-',
63
- "\342\200\224" => '--',
64
- "\342\200\225" => '--',
65
- "\342\200\042" => '--'
66
- },
67
- "1.9" => {
68
- "’" => "'",
69
- "…" => "...",
70
- "‘" => "'",
71
- "‚" => ',',
72
- "‛" => "'",
73
- "“" => '"',
74
- "”" => '"',
75
- "‐" => '-',
76
- "–" => '-',
77
- "—" => '--',
78
- "―" => '--'
79
- }
48
+ "’" => "'",
49
+ "…" => "...",
50
+ "‘" => "'",
51
+ "‚" => ',',
52
+ "‛" => "'",
53
+ "“" => '"',
54
+ "”" => '"',
55
+ "‐" => '-',
56
+ "–" => '-',
57
+ "—" => '--',
58
+ "―" => '--'
80
59
  }
81
60
 
82
61
  # list of CSS attributes that can be rendered as HTML attributes
@@ -185,7 +164,9 @@ class Premailer
185
164
  # @option options [Boolean] :include_style_tags Whether to include css from <tt>style</tt> tags. Default is true.
186
165
  # @option options [String] :input_encoding Manually specify the source documents encoding. This is a good idea. Default is ASCII-8BIT.
187
166
  # @option options [Boolean] :replace_html_entities Convert HTML entities to actual characters. Default is false.
167
+ # @option options [Boolean] :escape_url_attributes URL Escapes href, src, and background attributes on elements. Default is true.
188
168
  # @option options [Symbol] :adapter Which HTML parser to use, either <tt>:nokogiri</tt> or <tt>:hpricot</tt>. Default is <tt>:hpricot</tt>.
169
+ # @option options [String] :output_encoding Output encoding option for Nokogiri adapter. Should be set to "US-ASCII" to output HTML entities instead of Unicode characters.
189
170
  def initialize(html, options = {})
190
171
  @options = {:warn_level => Warnings::SAFE,
191
172
  :line_length => 65,
@@ -207,7 +188,9 @@ class Premailer
207
188
  :include_link_tags => true,
208
189
  :include_style_tags => true,
209
190
  :input_encoding => 'ASCII-8BIT',
191
+ :output_encoding => nil,
210
192
  :replace_html_entities => false,
193
+ :escape_url_attributes => true,
211
194
  :adapter => Adapter.use,
212
195
  }.merge(options)
213
196
 
@@ -416,6 +399,7 @@ public
416
399
  base_uri = URI.parse(base_uri) unless base_uri.kind_of?(URI)
417
400
 
418
401
  append_qs = @options[:link_query_string] || ''
402
+ escape_attrs = @options[:escape_url_attributes]
419
403
 
420
404
  ['href', 'src', 'background'].each do |attribute|
421
405
  tags = doc.search("*[@#{attribute}]")
@@ -438,6 +422,7 @@ public
438
422
  merged = Premailer.resolve_link(tag.attributes[attribute].to_s, base_uri)
439
423
  rescue
440
424
  begin
425
+ next unless escape_attrs
441
426
  merged = Premailer.resolve_link(URI.escape(tag.attributes[attribute].to_s), base_uri)
442
427
  rescue; end
443
428
  end
@@ -1,4 +1,4 @@
1
1
  class Premailer
2
2
  # Premailer version.
3
- VERSION = '1.8.0'.freeze
3
+ VERSION = '1.8.1'.freeze
4
4
  end
@@ -17,9 +17,7 @@
17
17
  @import "noimport.css" print;
18
18
  </style>
19
19
  <style type="text/css">
20
- @media only screen and (max-device-width: 480px) {
21
- #iphone { display: block; }
22
- }
20
+ #iphone { display: block; }
23
21
  </style>
24
22
  </head>
25
23
  <body>
@@ -20,8 +20,7 @@ class Premailer::TestCase < Test::Unit::TestCase
20
20
  end
21
21
  end
22
22
 
23
- stub_request(:get, /my\.example\.com\:8080\/*/)
24
- .to_return(:status => 200, :body => "", :headers => {})
23
+ stub_request(:get, /my\.example\.com\:8080\/*/).to_return(:status => 200, :body => "", :headers => {})
25
24
  end
26
25
 
27
26
  def default_test; end
@@ -119,7 +119,7 @@ END_HTML
119
119
 
120
120
  # should be preserved as unmergeable
121
121
 
122
- assert_match /red !important/i, premailer.processed_doc.at('body style').inner_html
122
+ assert_match /color: red/i, premailer.processed_doc.at('body style').inner_html
123
123
 
124
124
  assert_match /a:hover/i, premailer.processed_doc.at('style').inner_html
125
125
 
@@ -136,8 +136,9 @@ END_HTML
136
136
  premailer = Premailer.new(html, :with_html_string => true, :verbose => true)
137
137
  premailer.to_inline_css
138
138
 
139
- assert_match /a\:hover[\s]*\{[\s]*color\:[\s]*red[\s]*!important;[\s]*\}/i, premailer.processed_doc.at('body style').inner_html
140
-
139
+ # blue should be inlined
140
+ assert_no_match /a\:hover[\s]*\{[\s]*color\:[\s]*blue[\s]*;[\s]*\}/i, premailer.processed_doc.at('body style').inner_html
141
+ # red should remain in <style> block
141
142
  assert_match /a\:hover[\s]*\{[\s]*color\:[\s]*red;[\s]*\}/i, premailer.processed_doc.at('body style').inner_html
142
143
  end
143
144
 
@@ -171,9 +172,9 @@ END_HTML
171
172
 
172
173
  assert_equal "color: blue", premailer.processed_doc.at('a').attributes['style'].to_s,
173
174
  "#{adapter}: Failed to inline the default style"
174
- assert_match /@media \(min-width:500px\) {.*?a {.*?color: red;.*?}.*?}/m, style_tag_contents,
175
+ assert_match /@media \(min-width:500px\) \{.*?a {.*?color: red;.*?\}.*?\}/m, style_tag_contents,
175
176
  "#{adapter}: Failed to add media query with no type to style"
176
- assert_match /@media screen and \(orientation: portrait\) {.*?a {.*?color: green;.*?}.*?}/m, style_tag_contents,
177
+ assert_match /@media screen and \(orientation: portrait\) \{.*?a \{.*?color: green;.*?\}.*?\}/m, style_tag_contents,
177
178
  "#{adapter}: Failed to add media query with type to style"
178
179
  end
179
180
 
@@ -151,6 +151,23 @@ END_HTML
151
151
  end
152
152
  end
153
153
 
154
+ def test_initialize_no_escape_attributes_option
155
+ html = <<END_HTML
156
+ <html> <body>
157
+ <a id="google" href="http://google.com">Google</a>
158
+ <a id="noescape" href="{{link_url}}">Link</a>
159
+ </body> </html>
160
+ END_HTML
161
+
162
+ [:nokogiri, :hpricot].each do |adapter|
163
+ pm = Premailer.new(html, :with_html_string => true, :adapter => adapter, :escape_url_attributes => false)
164
+ pm.to_inline_css
165
+ doc = pm.processed_doc
166
+ assert_equal doc.at('#google')['href'], 'http://google.com'
167
+ assert_equal doc.at('#noescape')['href'], '{{link_url}}'
168
+ end
169
+ end
170
+
154
171
  def test_remove_ids
155
172
  html = <<END_HTML
156
173
  <html> <head> <style type="text/css"> #remove { color:blue; } </style> </head>
metadata CHANGED
@@ -1,145 +1,145 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: premailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.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: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.3.5
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
26
  version: 1.3.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: htmlentities
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 4.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 4.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.8'
62
- - - "!="
62
+ - - '!='
63
63
  - !ruby/object:Gem::Version
64
64
  version: 0.9.0
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - "~>"
69
+ - - ~>
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0.8'
72
- - - "!="
72
+ - - '!='
73
73
  - !ruby/object:Gem::Version
74
74
  version: 0.9.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: hpricot
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - '>='
80
80
  - !ruby/object:Gem::Version
81
81
  version: 0.8.3
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - '>='
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.8.3
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: nokogiri
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">="
93
+ - - '>='
94
94
  - !ruby/object:Gem::Version
95
95
  version: 1.4.4
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
102
  version: 1.4.4
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: yard
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: 0.8.7
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ~>
115
115
  - !ruby/object:Gem::Version
116
116
  version: 0.8.7
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: redcarpet
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - "~>"
121
+ - - ~>
122
122
  - !ruby/object:Gem::Version
123
123
  version: '3.0'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - "~>"
128
+ - - ~>
129
129
  - !ruby/object:Gem::Version
130
130
  version: '3.0'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: yard-redcarpet-ext
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - "~>"
135
+ - - ~>
136
136
  - !ruby/object:Gem::Version
137
137
  version: 0.0.3
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - "~>"
142
+ - - ~>
143
143
  - !ruby/object:Gem::Version
144
144
  version: 0.0.3
145
145
  description: Improve the rendering of HTML emails by making CSS inline, converting
@@ -150,14 +150,16 @@ executables:
150
150
  extensions: []
151
151
  extra_rdoc_files: []
152
152
  files:
153
- - ".gitignore"
154
- - ".jrubyrc"
155
- - ".travis.yml"
156
- - ".yardopts"
153
+ - .gitignore
154
+ - .jrubyrc
155
+ - .travis.yml
156
+ - .yardopts
157
157
  - Gemfile
158
158
  - LICENSE.md
159
159
  - README.md
160
160
  - bin/premailer
161
+ - gemfiles/ruby187.gemfile
162
+ - gemfiles/ruby187.gemspec
161
163
  - init.rb
162
164
  - lib/premailer.rb
163
165
  - lib/premailer/adapter.rb
@@ -204,17 +206,17 @@ require_paths:
204
206
  - lib
205
207
  required_ruby_version: !ruby/object:Gem::Requirement
206
208
  requirements:
207
- - - ">="
209
+ - - '>='
208
210
  - !ruby/object:Gem::Version
209
211
  version: '0'
210
212
  required_rubygems_version: !ruby/object:Gem::Requirement
211
213
  requirements:
212
- - - ">="
214
+ - - '>='
213
215
  - !ruby/object:Gem::Version
214
216
  version: '0'
215
217
  requirements: []
216
218
  rubyforge_project:
217
- rubygems_version: 2.2.0
219
+ rubygems_version: 2.0.3
218
220
  signing_key:
219
221
  specification_version: 4
220
222
  summary: Preflight for HTML e-mail.