premailer-rails 1.8.2 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -10
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -1
- data/README.md +6 -11
- data/VERSION +1 -1
- data/example/Gemfile +1 -3
- data/example/config.ru +1 -1
- data/example/config/application.rb +1 -0
- data/example/config/boot.rb +1 -2
- data/example/config/environments/development.rb +4 -0
- data/example/config/environments/production.rb +9 -0
- data/example/config/initializers/assets.rb +2 -0
- data/lib/premailer/rails/css_helper.rb +15 -9
- data/lib/premailer/rails/css_loaders/asset_pipeline_loader.rb +3 -1
- data/lib/premailer/rails/css_loaders/cache_loader.rb +12 -4
- data/lib/premailer/rails/css_loaders/network_loader.rb +0 -4
- data/lib/premailer/rails/customized_premailer.rb +2 -2
- data/premailer-rails.gemspec +2 -2
- data/spec/integration/css_helper_spec.rb +25 -24
- metadata +24 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a6895871c0ec4e4443e1a1d6bf22d9239756659
|
4
|
+
data.tar.gz: 9143e6f08bc542eb428ac14433bf1b0fb7d5851b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a72305f6009dee21b9b29dbc06cd4619012606e7b10dc0949abdc45854763aebce9fb5f6c08b0ba50934cdc8cf5c2a03df01f1658f4efbae0c07065695ffbae
|
7
|
+
data.tar.gz: ce3df301bb6e8a81d46c6ae51bf7d3bc8af5ba9360b60b51b43bb8f68d5f6c75100625e96fc941057f428a9ae1d051580d7f546bdf3e45d71ee8552d40b09aad
|
data/.travis.yml
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
2
|
-
before_install:
|
3
|
-
- gem install bundler
|
4
3
|
cache: bundler
|
5
4
|
script: "bundle exec rspec"
|
6
5
|
rvm:
|
7
|
-
- 2.1.0
|
8
|
-
- 2.0.0
|
9
6
|
- 1.9.3
|
7
|
+
- 2.2.2
|
10
8
|
- ruby-head
|
11
9
|
- jruby-19mode
|
12
|
-
- rbx-2
|
13
10
|
env:
|
14
|
-
- "ACTION_MAILER_VERSION=3.
|
15
|
-
- "ACTION_MAILER_VERSION=
|
16
|
-
- "ACTION_MAILER_VERSION=
|
17
|
-
- "ACTION_MAILER_VERSION=head"
|
11
|
+
- "ACTION_MAILER_VERSION=3.2"
|
12
|
+
- "ACTION_MAILER_VERSION=4.0"
|
13
|
+
- "ACTION_MAILER_VERSION=master"
|
18
14
|
matrix:
|
19
15
|
allow_failures:
|
20
|
-
- env: "ACTION_MAILER_VERSION=
|
16
|
+
- env: "ACTION_MAILER_VERSION=master"
|
21
17
|
- rvm: ruby-head
|
18
|
+
- rvm: rbx-2
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.9.0
|
4
|
+
|
5
|
+
- Improved CSS loading and caching.
|
6
|
+
- Fixed incompatibility with newer rails and sprockets versions.
|
7
|
+
|
3
8
|
## v1.8.2
|
4
9
|
|
5
10
|
- `Premailer::Rails::CSSLoaders::NetworkLoader` is more resilient and works even
|
6
11
|
if the Rails asset host is set without a URI scheme. (panthomakos)
|
12
|
+
- Remove stylesheet links from the HTML that have been processed.
|
7
13
|
|
8
14
|
## v1.8.1
|
9
15
|
|
data/Gemfile
CHANGED
@@ -4,7 +4,7 @@ gemspec
|
|
4
4
|
|
5
5
|
action_mailer_version = ENV.fetch('ACTION_MAILER_VERSION', '4.0')
|
6
6
|
|
7
|
-
if action_mailer_version == '
|
7
|
+
if action_mailer_version == 'master'
|
8
8
|
git 'git://github.com/rails/rails.git' do
|
9
9
|
gem 'actionmailer'
|
10
10
|
end
|
@@ -16,3 +16,5 @@ platforms :rbx do
|
|
16
16
|
gem 'rubysl'
|
17
17
|
gem 'racc'
|
18
18
|
end
|
19
|
+
|
20
|
+
gem 'tins', '< 1.7' if RUBY_VERSION.split('.').first.to_i < 2
|
data/README.md
CHANGED
@@ -7,7 +7,6 @@ CSS styled emails without the hassle.
|
|
7
7
|
[![Dependency Status][deps-image]][deps-link]
|
8
8
|
[![Code Climate][gpa-image]][gpa-link]
|
9
9
|
[![Coverage Status][cov-image]][cov-link]
|
10
|
-
[![Bitdeli Badge][stats-image]][stats-link]
|
11
10
|
|
12
11
|
## Introduction
|
13
12
|
|
@@ -148,25 +147,21 @@ transformed into a string, causing `'false'` to become truethy.
|
|
148
147
|
|
149
148
|
Philipe Fatio ([@fphilipe][fphilipe twitter])
|
150
149
|
|
151
|
-
[![Support via Gittip][tip-image]][tip-link]
|
152
|
-
|
153
150
|
### License
|
154
151
|
|
155
152
|
premailer-rails is released under the MIT license. See the [license file].
|
156
153
|
|
157
|
-
[build-image]: https://travis-ci.org/fphilipe/premailer-rails.
|
154
|
+
[build-image]: https://travis-ci.org/fphilipe/premailer-rails.svg
|
158
155
|
[build-link]: https://travis-ci.org/fphilipe/premailer-rails
|
159
|
-
[gem-image]: https://badge.fury.io/rb/premailer-rails.
|
156
|
+
[gem-image]: https://badge.fury.io/rb/premailer-rails.svg
|
160
157
|
[gem-link]: https://rubygems.org/gems/premailer-rails
|
161
|
-
[deps-image]: https://gemnasium.com/fphilipe/premailer-rails.
|
158
|
+
[deps-image]: https://gemnasium.com/fphilipe/premailer-rails.svg
|
162
159
|
[deps-link]: https://gemnasium.com/fphilipe/premailer-rails
|
163
|
-
[gpa-image]: https://codeclimate.com/github/fphilipe/premailer-rails.
|
160
|
+
[gpa-image]: https://codeclimate.com/github/fphilipe/premailer-rails.svg
|
164
161
|
[gpa-link]: https://codeclimate.com/github/fphilipe/premailer-rails
|
165
|
-
[cov-image]: https://coveralls.io/repos/fphilipe/premailer-rails/badge.
|
162
|
+
[cov-image]: https://coveralls.io/repos/fphilipe/premailer-rails/badge.svg
|
166
163
|
[cov-link]: https://coveralls.io/r/fphilipe/premailer-rails
|
167
|
-
[
|
168
|
-
[stats-link]: https://bitdeli.com/
|
169
|
-
[tip-image]: https://rawgithub.com/twolfson/gittip-badge/0.1.0/dist/gittip.png
|
164
|
+
[tip-image]: https://rawgithub.com/twolfson/gittip-badge/0.1.0/dist/gittip.svg
|
170
165
|
[tip-link]: https://www.gittip.com/fphilipe/
|
171
166
|
|
172
167
|
[premailer]: https://github.com/premailer/premailer
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.9.0
|
data/example/Gemfile
CHANGED
data/example/config.ru
CHANGED
data/example/config/boot.rb
CHANGED
@@ -2,4 +2,8 @@ Rails.application.configure do
|
|
2
2
|
config.cache_classes = false
|
3
3
|
config.eager_load = false
|
4
4
|
config.consider_all_requests_local = true
|
5
|
+
config.action_controller.perform_caching = false
|
6
|
+
config.assets.debug = true
|
7
|
+
config.assets.digest = true
|
8
|
+
config.assets.raise_runtime_errors = true
|
5
9
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
config.eager_load = true
|
4
|
+
config.consider_all_requests_local = false
|
5
|
+
config.action_controller.perform_caching = true
|
6
|
+
config.assets.compile = false
|
7
|
+
config.assets.digest = true
|
8
|
+
config.log_level = :info
|
9
|
+
end
|
@@ -3,8 +3,7 @@ class Premailer
|
|
3
3
|
module CSSHelper
|
4
4
|
extend self
|
5
5
|
|
6
|
-
|
7
|
-
attr :cache
|
6
|
+
FileNotFound = Class.new(StandardError)
|
8
7
|
|
9
8
|
STRATEGIES = [
|
10
9
|
CSSLoaders::CacheLoader,
|
@@ -15,24 +14,31 @@ class Premailer
|
|
15
14
|
|
16
15
|
# Returns all linked CSS files concatenated as string.
|
17
16
|
def css_for_doc(doc)
|
18
|
-
|
19
|
-
|
17
|
+
css_urls_in_doc(doc).map { |url| css_for_url(url) }.join("\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
def css_for_url(url)
|
21
|
+
load_css(url).tap do |content|
|
22
|
+
CSSLoaders::CacheLoader.store(url, content)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
private
|
23
27
|
|
24
28
|
def css_urls_in_doc(doc)
|
25
29
|
doc.search('link[@rel="stylesheet"]').map do |link|
|
30
|
+
link.remove
|
26
31
|
link.attributes['href'].to_s
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
30
35
|
def load_css(url)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
STRATEGIES.each do |strategy|
|
37
|
+
css = strategy.load(url)
|
38
|
+
return css.force_encoding('UTF-8') if css
|
39
|
+
end
|
40
|
+
|
41
|
+
raise FileNotFound, %{File with URL "#{url}" could not be loaded by any strategy.}
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -4,14 +4,22 @@ class Premailer
|
|
4
4
|
module CacheLoader
|
5
5
|
extend self
|
6
6
|
|
7
|
+
@cache = {}
|
8
|
+
|
7
9
|
def load(url)
|
8
|
-
unless development_env?
|
9
|
-
|
10
|
-
|
10
|
+
@cache[url] unless development_env?
|
11
|
+
end
|
12
|
+
|
13
|
+
def store(url, content)
|
14
|
+
@cache[url] ||= content unless development_env?
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear!
|
18
|
+
@cache = {}
|
11
19
|
end
|
12
20
|
|
13
21
|
def development_env?
|
14
|
-
defined?(::Rails)
|
22
|
+
defined?(::Rails) && ::Rails.env.development?
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
@@ -11,9 +11,9 @@ class Premailer
|
|
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)
|
14
|
-
|
15
14
|
options = @options.merge(css_string: CSSHelper.css_for_doc(doc))
|
16
|
-
|
15
|
+
|
16
|
+
super(doc.to_s, options)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/premailer-rails.gemspec
CHANGED
@@ -16,14 +16,14 @@ Gem::Specification.new do |s|
|
|
16
16
|
premailer will inline the included CSS.}
|
17
17
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {
|
19
|
+
s.test_files = `git ls-files -- {example,spec}/*`.split("\n")
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
23
|
s.add_dependency 'premailer', '~> 1.7', '>= 1.7.9'
|
24
24
|
s.add_dependency 'actionmailer', '>= 3', '< 5'
|
25
25
|
|
26
|
-
s.add_development_dependency 'rspec', '~> 3.
|
26
|
+
s.add_development_dependency 'rspec', '~> 3.3'
|
27
27
|
s.add_development_dependency 'nokogiri'
|
28
28
|
s.add_development_dependency 'hpricot' unless RUBY_PLATFORM == 'java'
|
29
29
|
s.add_development_dependency 'coveralls' if RUBY_ENGINE == 'ruby'
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe Premailer::Rails::CSSHelper do
|
4
4
|
# Reset the CSS cache:
|
5
5
|
after do
|
6
|
-
Premailer::Rails::
|
6
|
+
Premailer::Rails::CSSLoaders::CacheLoader.clear!
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
Premailer::Rails::CSSHelper.
|
9
|
+
def css_for_url(path)
|
10
|
+
Premailer::Rails::CSSHelper.css_for_url(path)
|
11
11
|
end
|
12
12
|
|
13
13
|
def css_for_doc(doc)
|
@@ -28,11 +28,11 @@ describe Premailer::Rails::CSSHelper do
|
|
28
28
|
|
29
29
|
it 'returns the content of both files concatenated' do
|
30
30
|
allow(Premailer::Rails::CSSHelper).to \
|
31
|
-
receive(:
|
31
|
+
receive(:css_for_url)
|
32
32
|
.with('http://example.com/stylesheets/base.css')
|
33
33
|
.and_return('content of base.css')
|
34
34
|
allow(Premailer::Rails::CSSHelper).to \
|
35
|
-
receive(:
|
35
|
+
receive(:css_for_url)
|
36
36
|
.with('http://example.com/stylesheets/font.css')
|
37
37
|
.and_return('content of font.css')
|
38
38
|
|
@@ -41,44 +41,45 @@ describe Premailer::Rails::CSSHelper do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe '#
|
44
|
+
describe '#css_for_url' do
|
45
45
|
context 'when path is a url' do
|
46
46
|
it 'loads the CSS at the local path' do
|
47
47
|
expect_file('public/stylesheets/base.css')
|
48
48
|
|
49
|
-
|
49
|
+
css_for_url('http://example.com/stylesheets/base.css?test')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
context 'when path is a relative url' do
|
54
54
|
it 'loads the CSS at the local path' do
|
55
55
|
expect_file('public/stylesheets/base.css')
|
56
|
-
|
56
|
+
css_for_url('/stylesheets/base.css?test')
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'when file is cached' do
|
61
61
|
it 'returns the cached value' do
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
Premailer::Rails::CSSLoaders::CacheLoader.store(
|
63
|
+
'http://example.com/stylesheets/base.css',
|
64
|
+
'content of base.css'
|
65
|
+
)
|
65
66
|
|
66
|
-
expect(
|
67
|
+
expect(css_for_url('http://example.com/stylesheets/base.css')).to \
|
67
68
|
eq('content of base.css')
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
72
|
context 'when in development mode' do
|
72
73
|
it 'does not return cached values' do
|
73
|
-
|
74
|
-
|
75
|
-
cache['http://example.com/stylesheets/base.css'] =
|
74
|
+
Premailer::Rails::CSSLoaders::CacheLoader.store(
|
75
|
+
'http://example.com/stylesheets/base.css',
|
76
76
|
'cached content of base.css'
|
77
|
+
)
|
77
78
|
content = 'new content of base.css'
|
78
79
|
expect_file('public/stylesheets/base.css', content)
|
79
80
|
allow(Rails.env).to receive(:development?).and_return(true)
|
80
81
|
|
81
|
-
expect(
|
82
|
+
expect(css_for_url('http://example.com/stylesheets/base.css')).to eq(content)
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
@@ -92,7 +93,7 @@ describe Premailer::Rails::CSSHelper do
|
|
92
93
|
path = '/assets/email-digest.css'
|
93
94
|
content = 'read from file'
|
94
95
|
expect_file("public#{path}", content)
|
95
|
-
expect(
|
96
|
+
expect(css_for_url(path)).to eq(content)
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
@@ -102,7 +103,7 @@ describe Premailer::Rails::CSSHelper do
|
|
102
103
|
.with('base.css')
|
103
104
|
.and_return(double(to_s: 'content of base.css'))
|
104
105
|
|
105
|
-
expect(
|
106
|
+
expect(css_for_url('http://example.com/assets/base.css')).to \
|
106
107
|
eq('content of base.css')
|
107
108
|
end
|
108
109
|
|
@@ -112,7 +113,7 @@ describe Premailer::Rails::CSSHelper do
|
|
112
113
|
.with('base.css')
|
113
114
|
.and_return(double(to_s: 'content of base.css'))
|
114
115
|
|
115
|
-
expect(
|
116
|
+
expect(css_for_url(
|
116
117
|
'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
|
117
118
|
)).to eq('content of base.css')
|
118
119
|
end
|
@@ -137,30 +138,30 @@ describe Premailer::Rails::CSSHelper do
|
|
137
138
|
end
|
138
139
|
|
139
140
|
it 'requests the file' do
|
140
|
-
expect(
|
141
|
+
expect(css_for_url(url)).to eq('content of base.css')
|
141
142
|
end
|
142
143
|
|
143
144
|
context 'when file url does not include the host' do
|
144
145
|
it 'requests the file using the asset host as host' do
|
145
|
-
expect(
|
146
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
146
147
|
end
|
147
148
|
|
148
149
|
context 'and the asset host uses protocol relative scheme' do
|
149
150
|
let(:asset_host) { '//assets.example.com' }
|
150
151
|
|
151
152
|
it 'requests the file using http as the scheme' do
|
152
|
-
expect(
|
153
|
+
expect(css_for_url(path)).to eq('content of base.css')
|
153
154
|
end
|
154
155
|
end
|
155
156
|
end
|
156
|
-
|
157
|
+
end
|
157
158
|
end
|
158
159
|
|
159
160
|
context 'when static stylesheets are used' do
|
160
161
|
it 'returns the content of the static file' do
|
161
162
|
content = 'content of base.css'
|
162
163
|
expect_file('public/stylesheets/base.css', content)
|
163
|
-
loaded_content =
|
164
|
+
loaded_content = css_for_url('http://example.com/stylesheets/base.css')
|
164
165
|
expect(loaded_content).to eq(content)
|
165
166
|
end
|
166
167
|
end
|
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.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipe Fatio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: premailer
|
@@ -56,14 +56,14 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 3.
|
59
|
+
version: '3.3'
|
60
60
|
type: :development
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 3.
|
66
|
+
version: '3.3'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: nokogiri
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,8 @@ files:
|
|
139
139
|
- example/config/boot.rb
|
140
140
|
- example/config/environment.rb
|
141
141
|
- example/config/environments/development.rb
|
142
|
+
- example/config/environments/production.rb
|
143
|
+
- example/config/initializers/assets.rb
|
142
144
|
- example/config/routes.rb
|
143
145
|
- example/config/secrets.yml
|
144
146
|
- example/test/mailers/previews/example_mailer_preview.rb
|
@@ -185,11 +187,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
187
|
version: '0'
|
186
188
|
requirements: []
|
187
189
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.5.1
|
189
191
|
signing_key:
|
190
192
|
specification_version: 4
|
191
193
|
summary: Easily create styled HTML emails in Rails.
|
192
194
|
test_files:
|
195
|
+
- example/Gemfile
|
196
|
+
- example/README.md
|
197
|
+
- example/Rakefile
|
198
|
+
- example/app/assets/stylesheets/email.css
|
199
|
+
- example/app/mailers/example_mailer.rb
|
200
|
+
- example/app/views/example_mailer/test_message.html.erb
|
201
|
+
- example/config.ru
|
202
|
+
- example/config/application.rb
|
203
|
+
- example/config/boot.rb
|
204
|
+
- example/config/environment.rb
|
205
|
+
- example/config/environments/development.rb
|
206
|
+
- example/config/environments/production.rb
|
207
|
+
- example/config/initializers/assets.rb
|
208
|
+
- example/config/routes.rb
|
209
|
+
- example/config/secrets.yml
|
210
|
+
- example/test/mailers/previews/example_mailer_preview.rb
|
193
211
|
- spec/integration/css_helper_spec.rb
|
194
212
|
- spec/integration/hook_registration_spec.rb
|
195
213
|
- spec/integration/hook_spec.rb
|
@@ -202,3 +220,4 @@ test_files:
|
|
202
220
|
- spec/unit/css_loaders/network_loader_spec.rb
|
203
221
|
- spec/unit/customized_premailer_spec.rb
|
204
222
|
- spec/unit/premailer_rails_spec.rb
|
223
|
+
has_rdoc:
|