premailer-rails 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +4 -3
- data/README.md +51 -1
- data/VERSION +1 -1
- data/lib/premailer/rails.rb +0 -1
- data/lib/premailer/rails/hook.rb +1 -1
- data/premailer-rails.gemspec +1 -1
- data/spec/spec_helper.rb +10 -8
- data/spec/support/fixtures/message.rb +16 -0
- data/spec/unit/customized_premailer_spec.rb +11 -2
- metadata +3 -4
- data/lib/premailer/rails/nokogiri_fix.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2248a4e7484976c9aa3f9260873dc82927adb6d
|
4
|
+
data.tar.gz: 0a3eb925b80da4498279e90e452931f87ac048d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dadbfdf3c5e22ee924824bfc8ac398957723207fd46e1f245c92da341830514ba64f6b0fe34d0cdf602329960f83f1eaa6134631d639589e714b3230665c19b
|
7
|
+
data.tar.gz: 9866e101c03db3be48bc0c840ec382875f7f7aee0042f9200712ac2eb28eb7665edde74d59df0c366dde132ef91bcbc108a2990ccaa6757c48f8474e6b2424d3
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
@@ -12,6 +12,7 @@ else
|
|
12
12
|
gem 'actionmailer', "~> #{action_mailer_version}"
|
13
13
|
end
|
14
14
|
|
15
|
-
platforms :
|
16
|
-
gem
|
15
|
+
platforms :rbx do
|
16
|
+
gem 'rubysl'
|
17
|
+
gem 'racc'
|
17
18
|
end
|
data/README.md
CHANGED
@@ -30,11 +30,44 @@ Rails. Although premailer-rails has certain Rails specific features, **it also
|
|
30
30
|
works in the absence of Rails** making it compatible with other frameworks such
|
31
31
|
as sinatra.
|
32
32
|
|
33
|
+
## How It Works
|
34
|
+
|
33
35
|
premailer-rails works with actionmailer by registering a delivery hook. This
|
34
36
|
causes all emails that are delivered to be processed by premailer-rails. This
|
35
|
-
means that
|
37
|
+
means that by simply including premailer-rails in your `Gemfile` you'll get
|
36
38
|
styled emails without having to set anything up.
|
37
39
|
|
40
|
+
Whenever premailer-rails processes an email, it collects the URLs of all linked
|
41
|
+
stylesheets (`<link rel="stylesheet" href="css_url">`). Then, for each of these
|
42
|
+
URLs, it tries to get the content through a couple of strategies. As long as
|
43
|
+
a strategy does not return anything, the next one is used. The strategies and
|
44
|
+
their order are as follows:
|
45
|
+
|
46
|
+
1. **Cache:** If there's a file in cache matching that URL, the cache content
|
47
|
+
is returned. The cache right now is rather rudimentary. Whenever a CSS file
|
48
|
+
is retrieved, it is stored in memory such that subsequent requests to the
|
49
|
+
same file are faster. The caching is disabled inside Rails in the
|
50
|
+
development environment.
|
51
|
+
|
52
|
+
2. **File System:** If there's a file inside `public/` with the same path as in
|
53
|
+
the URL, it is read from disk. E.g. if the URL is
|
54
|
+
`http://cdn.example.com/assets/email.css` the contents of the file located
|
55
|
+
at `public/assets/email.css` gets returned if it exists.
|
56
|
+
|
57
|
+
3. **Asset Pipeline:** If Rails is available and the asset pipeline is enabled,
|
58
|
+
the file is retrieved through the asset pipeline. E.g. if the URL is
|
59
|
+
`http://cdn.example.com/assets/email-fingerprint123.css`, the file
|
60
|
+
`email.css` is requested from the asset pipeline. That is, the fingerprint
|
61
|
+
and the prefix (in this case `assets` is the prefix) are stripped before
|
62
|
+
requesting it from the asset pipeline.
|
63
|
+
|
64
|
+
4. **Network:** As a last resort, the URL is simply requested and the response
|
65
|
+
body is used. This is usefull when the assets are not bundled in the
|
66
|
+
application and only available on a CDN. On Heroku e.g. you can add assets
|
67
|
+
to your `.slugignore` causing your assets to not be available to the app
|
68
|
+
(and thus resulting in a smaller app) and deploy the assets to a CDN such
|
69
|
+
as S3/CloudFront.
|
70
|
+
|
38
71
|
## Installation
|
39
72
|
|
40
73
|
Simply add the gem to your `Gemfile`:
|
@@ -99,6 +132,18 @@ class UserMailer < ActionMailer::Base
|
|
99
132
|
end
|
100
133
|
```
|
101
134
|
|
135
|
+
## Small Print
|
136
|
+
|
137
|
+
### Author
|
138
|
+
|
139
|
+
Philipe Fatio ([@fphilipe][fphilipe twitter])
|
140
|
+
|
141
|
+
[![Support via Gittip][tip-image]][tip-link]
|
142
|
+
|
143
|
+
### License
|
144
|
+
|
145
|
+
premailer-rails is released under the MIT license. See the [license file].
|
146
|
+
|
102
147
|
[build-image]: https://travis-ci.org/fphilipe/premailer-rails.png
|
103
148
|
[build-link]: https://travis-ci.org/fphilipe/premailer-rails
|
104
149
|
[gem-image]: https://badge.fury.io/rb/premailer-rails.png
|
@@ -111,6 +156,8 @@ end
|
|
111
156
|
[cov-link]: https://coveralls.io/r/fphilipe/premailer-rails
|
112
157
|
[stats-image]: https://d2weczhvl823v0.cloudfront.net/fphilipe/premailer-rails/trend.png
|
113
158
|
[stats-link]: https://bitdeli.com/
|
159
|
+
[tip-image]: https://rawgithub.com/twolfson/gittip-badge/0.1.0/dist/gittip.png
|
160
|
+
[tip-link]: https://www.gittip.com/fphilipe/
|
114
161
|
|
115
162
|
[premailer]: https://github.com/premailer/premailer
|
116
163
|
[actionmailer]: https://github.com/rails/rails/tree/master/actionmailer
|
@@ -118,3 +165,6 @@ end
|
|
118
165
|
[hpricot]: https://github.com/hpricot/hpricot
|
119
166
|
|
120
167
|
[premailer documentation]: http://rubydoc.info/gems/premailer/1.7.3/Premailer:initialize
|
168
|
+
|
169
|
+
[fphilipe twitter]: https://twitter.com/fphilipe
|
170
|
+
[license file]: LICENSE
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.1
|
data/lib/premailer/rails.rb
CHANGED
data/lib/premailer/rails/hook.rb
CHANGED
data/premailer-rails.gemspec
CHANGED
@@ -26,5 +26,5 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency 'rspec', '>= 3.0.0.beta1'
|
27
27
|
s.add_development_dependency 'nokogiri'
|
28
28
|
s.add_development_dependency 'hpricot' unless RUBY_PLATFORM == 'java'
|
29
|
-
s.add_development_dependency 'coveralls'
|
29
|
+
s.add_development_dependency 'coveralls' if RUBY_ENGINE == 'ruby'
|
30
30
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
if
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
if RUBY_ENGINE == 'ruby'
|
2
|
+
if ENV['CI']
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls::Output.silent = true
|
5
|
+
Coveralls.wear! do
|
6
|
+
add_filter 'spec/'
|
7
|
+
end
|
8
|
+
else
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.start
|
6
11
|
end
|
7
|
-
else
|
8
|
-
require 'simplecov'
|
9
|
-
SimpleCov.start
|
10
12
|
end
|
11
13
|
|
12
14
|
require 'premailer/rails'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'mail'
|
2
4
|
|
3
5
|
module Fixtures
|
@@ -19,6 +21,20 @@ module Fixtures
|
|
19
21
|
</html>
|
20
22
|
HTML
|
21
23
|
|
24
|
+
UNICODE_STRING = '٩(-̮̮̃-̃)۶ ٩(●̮̮̃•̃)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).'
|
25
|
+
|
26
|
+
HTML_PART_WITH_UNICODE = <<-HTML
|
27
|
+
<html>
|
28
|
+
<head>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<p>
|
32
|
+
#{UNICODE_STRING}
|
33
|
+
</p>
|
34
|
+
</body>
|
35
|
+
</html>
|
36
|
+
HTML
|
37
|
+
|
22
38
|
HTML_PART_WITH_CSS = <<-HTML
|
23
39
|
<html>
|
24
40
|
<head>
|
@@ -37,6 +37,15 @@ describe Premailer::Rails::CustomizedPremailer do
|
|
37
37
|
expect(premailer.to_inline_css).to match(regex)
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
context 'when HTML contains unicode' do
|
42
|
+
it 'should not mess those up' do
|
43
|
+
html = Fixtures::Message::HTML_PART_WITH_UNICODE
|
44
|
+
premailer = Premailer::Rails::CustomizedPremailer.new(html)
|
45
|
+
expect(premailer.to_inline_css).to \
|
46
|
+
include(Fixtures::Message::UNICODE_STRING)
|
47
|
+
end
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
@@ -48,13 +57,13 @@ describe Premailer::Rails::CustomizedPremailer do
|
|
48
57
|
end
|
49
58
|
|
50
59
|
it 'should pass on the configs' do
|
51
|
-
Premailer::Rails.config
|
60
|
+
Premailer::Rails.config.merge!(foo: :bar)
|
52
61
|
premailer = Premailer::Rails::CustomizedPremailer.new('some html')
|
53
62
|
expect(premailer.instance_variable_get(:'@options')[:foo]).to eq(:bar)
|
54
63
|
end
|
55
64
|
|
56
65
|
it 'should not allow to override with_html_string' do
|
57
|
-
Premailer::Rails.config
|
66
|
+
Premailer::Rails.config.merge!(with_html_string: false)
|
58
67
|
premailer = Premailer::Rails::CustomizedPremailer.new('some html')
|
59
68
|
options = premailer.instance_variable_get(:'@options')
|
60
69
|
expect(options[:with_html_string]).to eq(true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: premailer-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipe Fatio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: premailer
|
@@ -136,7 +136,6 @@ files:
|
|
136
136
|
- lib/premailer/rails/css_loaders/network_loader.rb
|
137
137
|
- lib/premailer/rails/customized_premailer.rb
|
138
138
|
- lib/premailer/rails/hook.rb
|
139
|
-
- lib/premailer/rails/nokogiri_fix.rb
|
140
139
|
- lib/premailer/rails/version.rb
|
141
140
|
- premailer-rails.gemspec
|
142
141
|
- spec/integration/css_helper_spec.rb
|
@@ -169,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
168
|
version: '0'
|
170
169
|
requirements: []
|
171
170
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.1.11
|
173
172
|
signing_key:
|
174
173
|
specification_version: 4
|
175
174
|
summary: Easily create styled HTML emails in Rails.
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'premailer/adapter/nokogiri'
|
2
|
-
|
3
|
-
Premailer::Adapter::Nokogiri.module_eval do
|
4
|
-
# Patch load_html method to fix character encoding issues.
|
5
|
-
def load_html(html)
|
6
|
-
if RUBY_VERSION.to_f >= 1.9
|
7
|
-
html = html.force_encoding('UTF-8').encode!
|
8
|
-
::Nokogiri::HTML(html) {|c| c.recover }
|
9
|
-
else
|
10
|
-
# :nocov:
|
11
|
-
::Nokogiri::HTML(html, nil, 'UTF-8') {|c| c.recover }
|
12
|
-
# :nocov:
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|