premailer-rails 1.9.7 → 1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +26 -0
- data/Gemfile +8 -4
- data/README.md +21 -29
- data/VERSION +1 -1
- data/lib/premailer/rails/css_helper.rb +30 -11
- data/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb +12 -11
- data/lib/premailer/rails/css_loaders/network_loader.rb +1 -1
- data/lib/premailer/rails/css_loaders.rb +0 -1
- data/lib/premailer/rails/customized_premailer.rb +4 -4
- data/lib/premailer/rails/hook.rb +2 -6
- data/lib/premailer/rails.rb +2 -1
- data/premailer-rails.gemspec +1 -2
- data/spec/integration/css_helper_spec.rb +170 -139
- data/spec/integration/delivery_spec.rb +13 -0
- data/spec/integration/hook_spec.rb +36 -11
- data/spec/rails_app/app/assets/config/manifest.js +3 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +3 -0
- data/spec/rails_app/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_app/app/mailers/welcome_mailer.rb +6 -0
- data/spec/rails_app/app/views/layouts/mailer.html.erb +11 -0
- data/spec/rails_app/app/views/welcome_mailer/welcome_email.html.erb +1 -0
- data/spec/rails_app/config/application.rb +13 -0
- data/spec/rails_app/config/boot.rb +5 -0
- data/spec/rails_app/config/environment.rb +2 -0
- data/spec/rails_app/config/environments/test.rb +10 -0
- data/spec/rails_app/config/initializers/assets.rb +1 -0
- data/spec/rails_app/config/routes.rb +3 -0
- data/spec/rails_app/config.ru +5 -0
- data/spec/rails_app/log/.keep +0 -0
- data/spec/rails_app/tmp/.keep +0 -0
- data/spec/spec_helper.rb +3 -8
- data/spec/support/fixtures/message.rb +40 -0
- data/spec/unit/css_loaders/network_loader_spec.rb +1 -1
- data/spec/unit/customized_premailer_spec.rb +32 -40
- metadata +35 -31
- data/lib/premailer/rails/css_loaders/cache_loader.rb +0 -29
- data/spec/integration/hook_registration_spec.rb +0 -11
- data/spec/support/stubs/action_mailer.rb +0 -5
- data/spec/support/stubs/rails.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 13055f85c556422022c71564c81f5816ecffd482e4514c1481212fab2c942eb7
|
4
|
+
data.tar.gz: 8b9093f66f195ac826382329877be7c9b863650c5bcb0c057bae0cc073b8978d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a861465e80d026c7e221b09f0c395be4d4fb26fa3662a233de5ba8295c41f0861b79958f873830fa4bd6333bd21798298155f8cadf1cf7861f08f5348ee3f901
|
7
|
+
data.tar.gz: f4cd1b29b3b1a4ee43fe83971b35b6a43896298ab3c1fec8d4fc91e2fc0d1290b353bba0096e2ae45376e394f6ad00142cf3dda7447a72259c7639c01fbd4231
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -3,11 +3,12 @@ language: ruby
|
|
3
3
|
cache: bundler
|
4
4
|
script: bundle exec rspec
|
5
5
|
rvm:
|
6
|
-
- 2.
|
6
|
+
- 2.6.5
|
7
|
+
- 2.7.0
|
7
8
|
env:
|
8
9
|
matrix:
|
9
|
-
- ACTION_MAILER_VERSION=4
|
10
10
|
- ACTION_MAILER_VERSION=5
|
11
|
+
- ACTION_MAILER_VERSION=6
|
11
12
|
- ACTION_MAILER_VERSION=master
|
12
13
|
matrix:
|
13
14
|
fast_finish: true
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.11.1
|
4
|
+
|
5
|
+
- Check if `Rails.application` is defined (@pabloh, #250)
|
6
|
+
|
7
|
+
## v1.11.0
|
8
|
+
|
9
|
+
- Remove `force_encoding!`
|
10
|
+
|
11
|
+
## v1.10.3
|
12
|
+
|
13
|
+
- Remove upper version constraint for actionmailer
|
14
|
+
|
15
|
+
## v1.10.2
|
16
|
+
|
17
|
+
- Explicitly check for assets_manifest (@derekwheel, #214)
|
18
|
+
|
19
|
+
## v1.10.1
|
20
|
+
|
21
|
+
- Catch error when sprockets can't find asset (@kirs, #209)
|
22
|
+
|
23
|
+
## v1.10.0
|
24
|
+
|
25
|
+
- Drop support for hpricot now that premailer-rails also doesn't support it
|
26
|
+
- Use `Rails.application.assets_manifest` instead of `Rails.application.assets` in Asset Pipeline loader (@kirs, #201)
|
27
|
+
- Introduce `:strategies` config option that allows to control CSS fetching stragies
|
28
|
+
|
3
29
|
## v1.9.7
|
4
30
|
|
5
31
|
- Use `Rails.root` in `FileSystemLoader` (@stanhu, #195)
|
data/Gemfile
CHANGED
@@ -2,16 +2,20 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
5
|
+
rails_version = ENV.fetch('ACTION_MAILER_VERSION', '5')
|
6
6
|
|
7
|
-
if
|
7
|
+
if rails_version == 'master'
|
8
8
|
git 'git://github.com/rails/rails.git' do
|
9
|
-
gem '
|
9
|
+
gem 'rails'
|
10
10
|
end
|
11
|
+
gem 'sprockets-rails', github: 'rails/sprockets-rails'
|
12
|
+
gem 'arel', github: 'rails/arel'
|
11
13
|
else
|
12
|
-
gem '
|
14
|
+
gem 'rails', "~> #{rails_version}"
|
13
15
|
end
|
14
16
|
|
17
|
+
gem 'byebug'
|
18
|
+
|
15
19
|
platforms :rbx do
|
16
20
|
gem 'rubysl'
|
17
21
|
gem 'racc'
|
data/README.md
CHANGED
@@ -39,34 +39,34 @@ styled emails without having to set anything up.
|
|
39
39
|
Whenever premailer-rails processes an email, it collects the URLs of all linked
|
40
40
|
stylesheets (`<link rel="stylesheet" href="css_url">`). Then, for each of these
|
41
41
|
URLs, it tries to get the content through a couple of strategies. As long as
|
42
|
-
a strategy does not return anything, the next one is used. The strategies
|
43
|
-
|
42
|
+
a strategy does not return anything, the next one is used. The strategies
|
43
|
+
available are:
|
44
44
|
|
45
|
-
|
46
|
-
is returned. The cache right now is rather rudimentary. Whenever a CSS file
|
47
|
-
is retrieved, it is stored in memory such that subsequent requests to the
|
48
|
-
same file are faster. The caching is disabled inside Rails in the
|
49
|
-
development environment.
|
50
|
-
|
51
|
-
2. **File System:** If there's a file inside `public/` with the same path as in
|
45
|
+
- `:filesystem`: If there's a file inside `public/` with the same path as in
|
52
46
|
the URL, it is read from disk. E.g. if the URL is
|
53
47
|
`http://cdn.example.com/assets/email.css` the contents of the file located
|
54
48
|
at `public/assets/email.css` gets returned if it exists.
|
55
49
|
|
56
|
-
|
50
|
+
- `:asset_pipeline`: If Rails is available and the asset pipeline is enabled,
|
57
51
|
the file is retrieved through the asset pipeline. E.g. if the URL is
|
58
52
|
`http://cdn.example.com/assets/email-fingerprint123.css`, the file
|
59
53
|
`email.css` is requested from the asset pipeline. That is, the fingerprint
|
60
54
|
and the prefix (in this case `assets` is the prefix) are stripped before
|
61
55
|
requesting it from the asset pipeline.
|
62
56
|
|
63
|
-
|
64
|
-
body is used. This is
|
57
|
+
- `:network`: As a last resort, the URL is simply requested and the response
|
58
|
+
body is used. This is useful when the assets are not bundled in the
|
65
59
|
application and only available on a CDN. On Heroku e.g. you can add assets
|
66
60
|
to your `.slugignore` causing your assets to not be available to the app
|
67
61
|
(and thus resulting in a smaller app) and deploy the assets to a CDN such
|
68
62
|
as S3/CloudFront.
|
69
63
|
|
64
|
+
You can configure which strategies you want to use as well as specify their
|
65
|
+
order. Refer to the *Configuration* section for more on this.
|
66
|
+
|
67
|
+
Note that the retrieved CSS is cached when the gem is running with Rails in
|
68
|
+
production.
|
69
|
+
|
70
70
|
## Installation
|
71
71
|
|
72
72
|
Simply add the gem to your `Gemfile`:
|
@@ -75,20 +75,12 @@ Simply add the gem to your `Gemfile`:
|
|
75
75
|
gem 'premailer-rails'
|
76
76
|
```
|
77
77
|
|
78
|
-
premailer-rails
|
79
|
-
a
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
gem
|
84
|
-
# or
|
85
|
-
gem 'hpricot'
|
86
|
-
```
|
87
|
-
|
88
|
-
If both gems are loaded for some reason, premailer chooses hpricot.
|
89
|
-
|
90
|
-
You can also explicitly configure the apapter as documented
|
91
|
-
[here](https://github.com/premailer/premailer#adapters).
|
78
|
+
premailer-rails and premailer require a gem that is used to parse the email's
|
79
|
+
HTML. For a list of supported gems and how to select which one to use, please
|
80
|
+
refer to the [*Adapter*
|
81
|
+
section](https://github.com/premailer/premailer#adapters) of premailer. Note
|
82
|
+
that there is no hard dependency from either gem so you should add one yourself.
|
83
|
+
Also note that this gem is only tested with [nokogiri].
|
92
84
|
|
93
85
|
## Configuration
|
94
86
|
|
@@ -107,7 +99,8 @@ configs are:
|
|
107
99
|
```ruby
|
108
100
|
{
|
109
101
|
input_encoding: 'UTF-8',
|
110
|
-
generate_text_part: true
|
102
|
+
generate_text_part: true,
|
103
|
+
strategies: [:filesystem, :asset_pipeline, :network]
|
111
104
|
}
|
112
105
|
```
|
113
106
|
|
@@ -185,9 +178,8 @@ premailer-rails is released under the MIT license. See the [license file].
|
|
185
178
|
[premailer]: https://github.com/premailer/premailer
|
186
179
|
[actionmailer]: https://github.com/rails/rails/tree/master/actionmailer
|
187
180
|
[nokogiri]: https://github.com/sparklemotion/nokogiri
|
188
|
-
[hpricot]: https://github.com/hpricot/hpricot
|
189
181
|
|
190
|
-
[premailer documentation]:
|
182
|
+
[premailer documentation]: https://www.rubydoc.info/gems/premailer/Premailer:initialize
|
191
183
|
|
192
184
|
[fphilipe twitter]: https://twitter.com/fphilipe
|
193
185
|
[license file]: LICENSE
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.11.1
|
@@ -5,12 +5,8 @@ class Premailer
|
|
5
5
|
|
6
6
|
FileNotFound = Class.new(StandardError)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
CSSLoaders::FileSystemLoader,
|
11
|
-
CSSLoaders::AssetPipelineLoader,
|
12
|
-
CSSLoaders::NetworkLoader
|
13
|
-
]
|
8
|
+
attr_accessor :cache
|
9
|
+
self.cache = {}
|
14
10
|
|
15
11
|
# Returns all linked CSS files concatenated as string.
|
16
12
|
def css_for_doc(doc)
|
@@ -18,8 +14,10 @@ class Premailer
|
|
18
14
|
end
|
19
15
|
|
20
16
|
def css_for_url(url)
|
21
|
-
|
22
|
-
|
17
|
+
if cache_enabled?
|
18
|
+
load_css_with_cache(url)
|
19
|
+
else
|
20
|
+
load_css(url)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -36,14 +34,35 @@ class Premailer
|
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
37
|
+
def load_css_with_cache(url)
|
38
|
+
self.cache[url] ||= load_css(url)
|
39
|
+
end
|
40
|
+
|
41
|
+
def cache_enabled?
|
42
|
+
defined?(::Rails.env) && ::Rails.env.production?
|
43
|
+
end
|
44
|
+
|
39
45
|
def load_css(url)
|
40
|
-
|
41
|
-
css = strategy.load(url)
|
42
|
-
return css
|
46
|
+
Premailer::Rails.config.fetch(:strategies).each do |strategy|
|
47
|
+
css = find_strategy(strategy).load(url)
|
48
|
+
return css if css
|
43
49
|
end
|
44
50
|
|
45
51
|
raise FileNotFound, %{File with URL "#{url}" could not be loaded by any strategy.}
|
46
52
|
end
|
53
|
+
|
54
|
+
def find_strategy(key)
|
55
|
+
case key
|
56
|
+
when :filesystem
|
57
|
+
CSSLoaders::FileSystemLoader
|
58
|
+
when :asset_pipeline
|
59
|
+
CSSLoaders::AssetPipelineLoader
|
60
|
+
when :network
|
61
|
+
CSSLoaders::NetworkLoader
|
62
|
+
else
|
63
|
+
key
|
64
|
+
end
|
65
|
+
end
|
47
66
|
end
|
48
67
|
end
|
49
68
|
end
|
@@ -5,18 +5,11 @@ class Premailer
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
def load(url)
|
8
|
-
|
9
|
-
file = file_name(url)
|
10
|
-
asset = ::Rails.application.assets.find_asset(file)
|
11
|
-
asset.to_s if asset
|
12
|
-
end
|
13
|
-
end
|
8
|
+
return unless asset_pipeline_present?
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
::Rails.application.respond_to?(:assets) &&
|
19
|
-
::Rails.application.assets
|
10
|
+
file = file_name(url)
|
11
|
+
::Rails.application.assets_manifest.find_sources(file).first
|
12
|
+
rescue Errno::ENOENT, TypeError => _error
|
20
13
|
end
|
21
14
|
|
22
15
|
def file_name(url)
|
@@ -29,6 +22,14 @@ class Premailer
|
|
29
22
|
.sub(/\A#{prefix}/, '')
|
30
23
|
.sub(/-(\h{32}|\h{64})\.css\z/, '.css')
|
31
24
|
end
|
25
|
+
|
26
|
+
def asset_pipeline_present?
|
27
|
+
defined?(::Rails) &&
|
28
|
+
::Rails.respond_to?(:application) &&
|
29
|
+
::Rails.application &&
|
30
|
+
::Rails.application.respond_to?(:assets_manifest) &&
|
31
|
+
::Rails.application.assets_manifest
|
32
|
+
end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -4,10 +4,10 @@ class Premailer
|
|
4
4
|
def initialize(html)
|
5
5
|
# In order to pass the CSS as string to super it is necessary to access
|
6
6
|
# the parsed HTML beforehand. To do so, the adapter needs to be
|
7
|
-
# initialized. The ::Premailer::
|
8
|
-
# suitable
|
9
|
-
#
|
10
|
-
#
|
7
|
+
# initialized. The ::Premailer::Adapter handles the discovery of
|
8
|
+
# a suitable adapter. To make load_html work, an adapter needs to be
|
9
|
+
# included and @options[:with_html_string] needs to be set. For further
|
10
|
+
# information, refer to ::Premailer#initialize.
|
11
11
|
@options = Rails.config.merge(with_html_string: true)
|
12
12
|
Premailer.send(:include, Adapter.find(Adapter.use))
|
13
13
|
doc = load_html(html)
|
data/lib/premailer/rails/hook.rb
CHANGED
@@ -73,10 +73,8 @@ class Premailer
|
|
73
73
|
part = html_part
|
74
74
|
html = premailer.to_inline_css
|
75
75
|
Mail::Part.new do
|
76
|
-
|
77
|
-
content_type "text/html; charset=#{part.charset}"
|
76
|
+
content_type "text/html; charset=#{html.encoding}"
|
78
77
|
body html
|
79
|
-
body_encoding part.body.encoding
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
@@ -85,10 +83,8 @@ class Premailer
|
|
85
83
|
part = html_part
|
86
84
|
text = premailer.to_plain_text
|
87
85
|
Mail::Part.new do
|
88
|
-
|
89
|
-
content_type "text/plain; charset=#{part.charset}"
|
86
|
+
content_type "text/plain; charset=#{text.encoding}"
|
90
87
|
body text
|
91
|
-
body_encoding part.body.encoding
|
92
88
|
end
|
93
89
|
end
|
94
90
|
end
|
data/lib/premailer/rails.rb
CHANGED
data/premailer-rails.gemspec
CHANGED
@@ -22,10 +22,9 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
24
|
s.add_dependency 'premailer', '~> 1.7', '>= 1.7.9'
|
25
|
-
s.add_dependency 'actionmailer', '>= 3'
|
25
|
+
s.add_dependency 'actionmailer', '>= 3'
|
26
26
|
|
27
27
|
s.add_development_dependency 'rspec', '~> 3.3'
|
28
28
|
s.add_development_dependency 'nokogiri'
|
29
|
-
s.add_development_dependency 'hpricot' unless RUBY_PLATFORM == 'java'
|
30
29
|
s.add_development_dependency 'coveralls' if RUBY_ENGINE == 'ruby'
|
31
30
|
end
|