premailer-rails 1.8.1 → 1.8.2

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: 7d3ecd8b9d9f55c3039cad6467d7de1fc2676565
4
- data.tar.gz: 985538b2930d3bae69fe75b9415af3f4d4f411eb
3
+ metadata.gz: 7ef9ec48ca64d88fcd427db297397c18a20f6711
4
+ data.tar.gz: f6c87f62f912f57f0d5f302138abd6160a65d99d
5
5
  SHA512:
6
- metadata.gz: 4e13cd460126fb67c58f89d186157463ca47162a228cc12e46dfc373bd9773d30a11ba318c9ea36d1892474b94bf3a2008c49e847ed35b049acf095f6da517d0
7
- data.tar.gz: c0cdc0051dd65ef19bffb36378943733c4f66f68c3ef8662f77a66763a4439f8024daf20b1a35f5d11285bb730bc8ef256eed8ea8460fee387fa2fdda8f9a39b
6
+ metadata.gz: aa2493ad95cdc85442f350a4d613ce66a996b114ac2054dd0c2a145f9ce54c844371dbbb053e4011e3a4a95a4a2986e98037d2d6fe00a8879bfec2f0edf952bd
7
+ data.tar.gz: 946de795ff75887899fb882ed7b74d0497b5e78af394f118c4369f8c779aede8626f08def7bfd5675b645f925b882f596d04269f40719c1c50a80b8d653ab14e
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.8.2
4
+
5
+ - `Premailer::Rails::CSSLoaders::NetworkLoader` is more resilient and works even
6
+ if the Rails asset host is set without a URI scheme. (panthomakos)
7
+
3
8
  ## v1.8.1
4
9
 
5
10
  - Add support for longer fingerprint generated by sprocket 3.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ki premailer-rails
1
+ # premailer-rails
2
2
 
3
3
  CSS styled emails without the hassle.
4
4
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.1
1
+ 1.8.2
@@ -12,29 +12,29 @@ class Premailer
12
12
  def uri_for_url(url)
13
13
  uri = URI(url)
14
14
 
15
- if not valid_uri?(uri) and defined?(::Rails)
16
- scheme, host =
17
- asset_host.split(%r{:?//})
15
+ if uri.host.present?
16
+ return uri if uri.scheme.present?
17
+ URI("http://#{uri.to_s}")
18
+ elsif asset_host_present?
19
+ scheme, host = asset_host.split(%r{:?//})
20
+ scheme, host = host, scheme if host.nil?
18
21
  scheme = 'http' if scheme.blank?
19
- uri.scheme ||= scheme
20
- uri.host ||= host
22
+ path = url
23
+ URI(File.join("#{scheme}://#{host}", path))
21
24
  end
22
-
23
- uri if valid_uri?(uri)
24
25
  end
25
26
 
26
27
  def valid_uri?(uri)
27
28
  uri.host.present? && uri.scheme.present?
28
29
  end
29
30
 
30
- def asset_host
31
- host = ::Rails.configuration.action_controller.asset_host
31
+ def asset_host_present?
32
+ ::Rails.configuration.action_controller.asset_host.present?
33
+ end
32
34
 
33
- if host.respond_to?(:call)
34
- host.call
35
- else
36
- host
37
- end
35
+ def asset_host
36
+ config = ::Rails.configuration.action_controller.asset_host
37
+ config.respond_to?(:call) ? config.call : config
38
38
  end
39
39
  end
40
40
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Premailer::Rails::CSSLoaders::NetworkLoader do
4
+ describe '#uri_for_url' do
5
+ subject { described_class.uri_for_url(url) }
6
+ let(:asset_host) { nil }
7
+
8
+ before do
9
+ action_controller = double(asset_host: asset_host)
10
+ config = double(action_controller: action_controller)
11
+ allow(Rails).to receive(:configuration).and_return(config)
12
+ end
13
+
14
+ context 'with a valid URL' do
15
+ let(:url) { 'http://example.com/test.css' }
16
+ it { is_expected.to eq(URI(url)) }
17
+ end
18
+
19
+ context 'with a protocol relative URL' do
20
+ let(:url) { '//example.com/test.css' }
21
+ it { is_expected.to eq(URI("http://#{url}")) }
22
+ end
23
+
24
+ context 'with a file path' do
25
+ let(:url) { '/assets/foo.css' }
26
+
27
+ context 'and a domain as asset host' do
28
+ let(:asset_host) { 'example.com' }
29
+ it { is_expected.to eq(URI("http://example.com#{url}")) }
30
+ end
31
+
32
+ context 'and a URL as asset host' do
33
+ let(:asset_host) { 'https://example.com' }
34
+ it { is_expected.to eq(URI("https://example.com/assets/foo.css")) }
35
+ end
36
+
37
+ context 'and a protocol relative URL as asset host' do
38
+ let(:asset_host) { '//example.com' }
39
+ it { is_expected.to eq(URI("http://example.com/assets/foo.css")) }
40
+ end
41
+
42
+ context 'and a proc as asset host' do
43
+ let(:asset_host) { ->{ 'example.com' } }
44
+ it { is_expected.to eq(URI("http://example.com/assets/foo.css")) }
45
+ end
46
+
47
+ context 'without an asset host' do
48
+ let(:asset_host) { nil }
49
+ it { is_expected.not_to be }
50
+ end
51
+ end
52
+ end
53
+ 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.8.1
4
+ version: 1.8.2
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-05-08 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: premailer
@@ -163,6 +163,7 @@ files:
163
163
  - spec/support/stubs/action_mailer.rb
164
164
  - spec/support/stubs/rails.rb
165
165
  - spec/unit/css_loaders/asset_pipeline_loader_spec.rb
166
+ - spec/unit/css_loaders/network_loader_spec.rb
166
167
  - spec/unit/customized_premailer_spec.rb
167
168
  - spec/unit/premailer_rails_spec.rb
168
169
  homepage: https://github.com/fphilipe/premailer-rails
@@ -198,5 +199,6 @@ test_files:
198
199
  - spec/support/stubs/action_mailer.rb
199
200
  - spec/support/stubs/rails.rb
200
201
  - spec/unit/css_loaders/asset_pipeline_loader_spec.rb
202
+ - spec/unit/css_loaders/network_loader_spec.rb
201
203
  - spec/unit/customized_premailer_spec.rb
202
204
  - spec/unit/premailer_rails_spec.rb