premailer-rails 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/VERSION +1 -1
- data/lib/premailer/rails/css_helper.rb +2 -5
- data/lib/premailer/rails/css_loaders.rb +13 -15
- data/spec/lib/css_helper_spec.rb +44 -41
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c14b05b4d57365b47366c6c56d7080ed7610bb0e
|
4
|
+
data.tar.gz: 3bb5ba65597cc2fe6d40fc053785683ad0e08d69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af255aab35b0a2ebbbe9fc554d45bbf190878531ba2faef489cc88dcc4d1b40031713da7a21f8cdbbc1cdc49fdd8e96ca32ac2a3f439f40af4602fc3874c4bbc
|
7
|
+
data.tar.gz: 7aed5714d084a540a096da8df6606894d68616dbcfe1de3fb9bdcaee3eeb61624c2f1377064a850c10c6e454926ef8fda3815fc8aaca635f1398b5bd4e8c2046
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.5.1
|
4
|
+
|
5
|
+
- Prefer precompiled assets over asset pipeline
|
6
|
+
|
7
|
+
- Improve construction of file URL when requesting from CDN
|
8
|
+
|
9
|
+
- No longer use open-uri
|
10
|
+
|
11
|
+
- Remove gzip unzipping after requesting file
|
12
|
+
|
3
13
|
## v1.5.0
|
4
14
|
|
5
15
|
- No longer support ruby 1.8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.1
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'zlib'
|
3
|
-
|
4
1
|
class Premailer
|
5
2
|
module Rails
|
6
3
|
module CSSHelper
|
@@ -11,8 +8,8 @@ class Premailer
|
|
11
8
|
|
12
9
|
STRATEGIES = [
|
13
10
|
CSSLoaders::CacheLoader,
|
14
|
-
CSSLoaders::
|
15
|
-
CSSLoaders::
|
11
|
+
CSSLoaders::FileSystemLoader,
|
12
|
+
CSSLoaders::AssetPipelineLoader
|
16
13
|
]
|
17
14
|
|
18
15
|
# Returns all linked CSS files concatenated as string.
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'zlib'
|
3
|
+
|
1
4
|
class Premailer
|
2
5
|
module Rails
|
3
6
|
module CSSLoaders
|
@@ -22,7 +25,7 @@ class Premailer
|
|
22
25
|
if asset = ::Rails.application.assets.find_asset(file)
|
23
26
|
asset.to_s
|
24
27
|
else
|
25
|
-
|
28
|
+
Net::HTTP.get(uri_for_path(path))
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
@@ -37,19 +40,13 @@ class Premailer
|
|
37
40
|
.sub(/-\h{32}\.css$/, '.css')
|
38
41
|
end
|
39
42
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
begin
|
49
|
-
Zlib::GzipReader.new(response).read
|
50
|
-
rescue Zlib::GzipFile::Error, Zlib::Error
|
51
|
-
response.rewind
|
52
|
-
response.read
|
43
|
+
def uri_for_path(path)
|
44
|
+
URI(path).tap do |uri|
|
45
|
+
scheme, host =
|
46
|
+
::Rails.configuration.action_controller.asset_host.split(%r{:?//})
|
47
|
+
scheme = 'http' if scheme.blank?
|
48
|
+
uri.scheme ||= scheme
|
49
|
+
uri.host ||= host
|
53
50
|
end
|
54
51
|
end
|
55
52
|
end
|
@@ -59,7 +56,8 @@ class Premailer
|
|
59
56
|
extend self
|
60
57
|
|
61
58
|
def load(path)
|
62
|
-
|
59
|
+
file_path = "#{::Rails.root}/public#{path}"
|
60
|
+
File.read(file_path) if File.exist?(file_path)
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
data/spec/lib/css_helper_spec.rb
CHANGED
@@ -12,6 +12,11 @@ describe Premailer::Rails::CSSHelper do
|
|
12
12
|
Premailer::Rails::CSSHelper.css_for_doc(doc)
|
13
13
|
end
|
14
14
|
|
15
|
+
def expect_file(path, content=nil)
|
16
|
+
File.stubs(:exist?).with(path).returns(true)
|
17
|
+
File.expects(:read).with(path).returns(content)
|
18
|
+
end
|
19
|
+
|
15
20
|
describe '#css_for_doc' do
|
16
21
|
let(:html) { Fixtures::HTML.with_css_links(*files) }
|
17
22
|
let(:doc) { Nokogiri(html) }
|
@@ -37,7 +42,7 @@ describe Premailer::Rails::CSSHelper do
|
|
37
42
|
describe '#load_css' do
|
38
43
|
context 'when path is a url' do
|
39
44
|
it 'should load the CSS at the local path' do
|
40
|
-
|
45
|
+
expect_file('RAILS_ROOT/public/stylesheets/base.css')
|
41
46
|
|
42
47
|
load_css('http://example.com/stylesheets/base.css?test')
|
43
48
|
end
|
@@ -45,8 +50,7 @@ describe Premailer::Rails::CSSHelper do
|
|
45
50
|
|
46
51
|
context 'when path is a relative url' do
|
47
52
|
it 'should load the CSS at the local path' do
|
48
|
-
|
49
|
-
|
53
|
+
expect_file('RAILS_ROOT/public/stylesheets/base.css')
|
50
54
|
load_css('/stylesheets/base.css?test')
|
51
55
|
end
|
52
56
|
end
|
@@ -67,13 +71,11 @@ describe Premailer::Rails::CSSHelper do
|
|
67
71
|
cache =
|
68
72
|
Premailer::Rails::CSSHelper.send(:instance_variable_get, '@cache')
|
69
73
|
cache['/stylesheets/base.css'] = 'cached content of base.css'
|
70
|
-
|
71
|
-
|
72
|
-
.returns('new content of base.css')
|
74
|
+
content = 'new content of base.css'
|
75
|
+
expect_file('RAILS_ROOT/public/stylesheets/base.css', content)
|
73
76
|
Rails.env.stubs(:development?).returns(true)
|
74
77
|
|
75
|
-
load_css('http://example.com/stylesheets/base.css')
|
76
|
-
.should == 'new content of base.css'
|
78
|
+
load_css('http://example.com/stylesheets/base.css').should == content
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -87,6 +89,15 @@ describe Premailer::Rails::CSSHelper do
|
|
87
89
|
)
|
88
90
|
}
|
89
91
|
|
92
|
+
context 'and a precompiled file exists' do
|
93
|
+
it 'should return that file' do
|
94
|
+
path = '/assets/email-digest.css'
|
95
|
+
content = 'read from file'
|
96
|
+
expect_file("RAILS_ROOT/public#{path}", content)
|
97
|
+
load_css(path).should == content
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
90
101
|
it 'should return the content of the file compiled by Rails' do
|
91
102
|
Rails.application.assets
|
92
103
|
.expects(:find_asset)
|
@@ -109,52 +120,44 @@ describe Premailer::Rails::CSSHelper do
|
|
109
120
|
end
|
110
121
|
|
111
122
|
context 'when asset can not be found' do
|
112
|
-
|
123
|
+
let(:response) { 'content of base.css' }
|
124
|
+
let(:path) { '/assets/base-089e35bd5d84297b8d31ad552e433275.css' }
|
125
|
+
let(:url) { "http://assets.example.com#{path}" }
|
126
|
+
let(:asset_host) { 'http://assets.example.com' }
|
127
|
+
|
128
|
+
before do
|
113
129
|
Rails.application.assets.stubs(:find_asset).returns(nil)
|
114
130
|
Rails.configuration.stubs(:action_controller).returns(
|
115
|
-
stub(asset_host:
|
116
|
-
)
|
117
|
-
Rails.configuration.stubs(:assets).returns(
|
118
|
-
stub(
|
119
|
-
enabled: true,
|
120
|
-
prefix: '/assets',
|
121
|
-
digests: {
|
122
|
-
'base.css' => 'base-089e35bd5d84297b8d31ad552e433275.css'
|
123
|
-
}
|
124
|
-
)
|
131
|
+
stub(asset_host: asset_host)
|
125
132
|
)
|
126
|
-
|
127
|
-
|
128
|
-
let(:url) {
|
129
|
-
'http://example.com/assets/base-089e35bd5d84297b8d31ad552e433275.css'
|
130
|
-
}
|
133
|
+
Net::HTTP.stubs(:get).with { |uri| uri.to_s == url }.returns(response)
|
134
|
+
end
|
131
135
|
|
132
136
|
it 'should request the file' do
|
133
|
-
|
134
|
-
|
135
|
-
load_css(
|
136
|
-
'http://example.com/assets/base.css'
|
137
|
-
).should == 'content of base.css'
|
137
|
+
load_css(url).should == 'content of base.css'
|
138
138
|
end
|
139
139
|
|
140
|
-
|
141
|
-
|
140
|
+
context 'when file url does not include the host' do
|
141
|
+
it 'should request the file using the asset host as host' do
|
142
|
+
load_css(path).should == 'content of base.css'
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'and the asset host uses protocol relative scheme' do
|
146
|
+
let(:asset_host) { '//assets.example.com' }
|
142
147
|
|
143
|
-
|
144
|
-
|
145
|
-
|
148
|
+
it 'should request the file using http as the scheme' do
|
149
|
+
load_css(path).should == 'content of base.css'
|
150
|
+
end
|
151
|
+
end
|
146
152
|
end
|
147
|
-
|
153
|
+
end
|
148
154
|
end
|
149
155
|
|
150
156
|
context 'when static stylesheets are used' do
|
151
157
|
it 'should return the content of the static file' do
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
load_css('http://example.com/stylesheets/base.css')
|
157
|
-
.should == 'content of base.css'
|
158
|
+
content = 'content of base.css'
|
159
|
+
expect_file('RAILS_ROOT/public/stylesheets/base.css', content)
|
160
|
+
load_css('http://example.com/stylesheets/base.css').should == content
|
158
161
|
end
|
159
162
|
end
|
160
163
|
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.5.
|
4
|
+
version: 1.5.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-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: premailer
|