branchable_cdn_assets-middleman 0.7.0 → 0.8.0

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: db8030ec152bd0407e74c622d95d127cecebe65e
4
- data.tar.gz: 1a59b0c2b966dfe40f48073ea600199dfbcea039
3
+ metadata.gz: 3ae86e989e0f3fbc272aa429e13dfde3ff1a5c24
4
+ data.tar.gz: 55987dcadb5b29af7a9bb464de9c97ff2f35f212
5
5
  SHA512:
6
- metadata.gz: 983fedb01fa253045cfc846fa871b47ce48566ceb19452a6019b9c3decfb86fd61ff2c83c2f32b964651c2031ff34721c02d233d47936208a9f94b9bcbfc4381
7
- data.tar.gz: a72ae5b031b45fc52149b784aee430f289dc6e68d023f3a7ec4b805bee2be0662d5b03714d5a8b98dd50b12ad7ac0b4557669e90dfc10f8bd8c3007e6508caee
6
+ metadata.gz: 85e65c9d9a90ae327b5cf6a3442bf2cdbdb123d1139e1afe218ca0b3c63e5c653aa3e779afc12b1490d6ab0d49e0b409f827c8c55ff629f31242bbd95070d460
7
+ data.tar.gz: 2ac4a337fc0e61c5df01f9dc9401676918604d0774a6c7999a016d86b8a0b66c6ebdd1289bb7013df8166ad3a315069ae4ffe23efa98844710c16f92a893d9f4
@@ -15,7 +15,6 @@ module BranchableCDNAssets
15
15
 
16
16
  def after_configuration
17
17
  if defined?(::Sass::Script::Functions)
18
- $app = @app
19
18
  ::Sass::Script::Functions.send :include, SassHelpers
20
19
  end
21
20
  end
@@ -61,11 +61,14 @@ module BranchableCDNAssets
61
61
  module SassHelpers
62
62
 
63
63
  def cdn_asset_url( path, cdn=nil )
64
+ ::Sass::Script::String.new("url(#{cdn_asset_path(path, cdn)})")
65
+ end
66
+
67
+ def cdn_asset_path( path, cdn=nil )
64
68
  cdn = cdn.value if cdn.respond_to?(:value) # have to force cdn to a string if not nil
65
- file = $app.cdn_asset_url( path.value, cdn )
66
- ::Sass::Script::String.new("url(\"#{file}\")")
69
+ file = options[:custom][:middleman_context].cdn_asset_url( path.value, cdn )
70
+ ::Sass::Script::String.new file, :string
67
71
  end
68
- alias :cdn_asset_path :cdn_asset_url
69
72
 
70
73
  end
71
74
 
@@ -1,5 +1,5 @@
1
1
  module BranchableCDNAssets
2
2
  module Middleman
3
- VERSION = '0.7.0' unless defined?(BranchableCDNAssets::Middleman::VERSION)
3
+ VERSION = '0.8.0' unless defined?(BranchableCDNAssets::Middleman::VERSION)
4
4
  end
5
5
  end
@@ -16,6 +16,13 @@ describe BranchableCDNAssets::Middleman::Helpers do
16
16
 
17
17
  @mm = Middleman::Fixture.app
18
18
  @extension = @mm.extensions[:cdn_assets].first[1]
19
+
20
+ # split test based on changes in v4
21
+ if @mm.respond_to?(:template_context_class)
22
+ @context = @mm.template_context_class.new(@mm)
23
+ else
24
+ @context = @mm
25
+ end
19
26
  end
20
27
 
21
28
  after :each do
@@ -27,26 +34,26 @@ describe BranchableCDNAssets::Middleman::Helpers do
27
34
  context "when asset is on production cdn" do
28
35
  it "returns the 'live' url of the asset" do
29
36
  allow( Asgit ).to receive(:current_branch).and_return('master')
30
- expect( @mm.cdn_asset_url('image_remote_one') ).to eq 'http://production.com/image_remote_one'
37
+ expect( @context.cdn_asset_url('image_remote_one') ).to eq 'http://production.com/image_remote_one'
31
38
  end
32
39
  end
33
40
 
34
41
  context "when asset is on staging cdn" do
35
42
  it "returns the 'live' url of the asset" do
36
43
  allow( Asgit ).to receive(:current_branch).and_return('some_branch')
37
- expect( @mm.cdn_asset_url('image_remote_two') ).to eq 'http://staging.com/some_branch/image_remote_two'
44
+ expect( @context.cdn_asset_url('image_remote_two') ).to eq 'http://staging.com/some_branch/image_remote_two'
38
45
  end
39
46
  end
40
47
 
41
48
  context "when asset is local" do
42
49
  it "returns the 'localhost' url of the asset" do
43
- expect( @mm.cdn_asset_url('image_two') ).to eq "/assets/cdn/#{@extension.id}/image_two"
50
+ expect( @context.cdn_asset_url('image_two') ).to eq "/assets/cdn/#{@extension.id}/image_two"
44
51
  end
45
52
  end
46
53
 
47
54
  context "when asset is local and listed in a manifest" do
48
55
  it "returns the 'localhost' url of the asset" do
49
- expect( @mm.cdn_asset_url('image_one') ).to eq "/assets/cdn/#{@extension.id}/image_one"
56
+ expect( @context.cdn_asset_url('image_one') ).to eq "/assets/cdn/#{@extension.id}/image_one"
50
57
  end
51
58
 
52
59
  context "when building" do
@@ -54,9 +61,9 @@ describe BranchableCDNAssets::Middleman::Helpers do
54
61
  @mm.config[:environment] = :build
55
62
 
56
63
  allow( Asgit ).to receive(:current_branch).and_return('some_branch')
57
- expect( @mm.cdn_asset_url('image_all') ).to eq "http://staging.com/some_branch/image_all"
58
- expect( @mm.cdn_asset_url('image_one') ).to eq "http://staging.com/some_branch/image_one"
59
- expect( @mm.cdn_asset_url('image_prod') ).to eq "http://production.com/image_prod"
64
+ expect( @context.cdn_asset_url('image_all') ).to eq "http://staging.com/some_branch/image_all"
65
+ expect( @context.cdn_asset_url('image_one') ).to eq "http://staging.com/some_branch/image_one"
66
+ expect( @context.cdn_asset_url('image_prod') ).to eq "http://production.com/image_prod"
60
67
  end
61
68
  end
62
69
  end
@@ -64,7 +71,7 @@ describe BranchableCDNAssets::Middleman::Helpers do
64
71
  context "when the asset is missing" do
65
72
  it "raises an error with the asset name" do
66
73
  expect{
67
- @mm.cdn_asset_url('missing_image')
74
+ @context.cdn_asset_url('missing_image')
68
75
  }.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image'"
69
76
  end
70
77
  end
@@ -72,11 +79,11 @@ describe BranchableCDNAssets::Middleman::Helpers do
72
79
  context "when assets have multiple extensions" do
73
80
  it "returns the url with the given extensions" do
74
81
  allow( Asgit ).to receive(:current_branch).and_return('master')
75
- expect( @mm.cdn_asset_url('img.one.jpg') ).to eq "http://production.com/img.one.jpg"
82
+ expect( @context.cdn_asset_url('img.one.jpg') ).to eq "http://production.com/img.one.jpg"
76
83
  end
77
84
  it "raises an error if the root asset is missing" do
78
85
  expect{
79
- @mm.cdn_asset_url('missing_image.1.jpg')
86
+ @context.cdn_asset_url('missing_image.1.jpg')
80
87
  }.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image.1.jpg'"
81
88
  end
82
89
  end
@@ -84,15 +91,15 @@ describe BranchableCDNAssets::Middleman::Helpers do
84
91
  context "with added file extensions" do
85
92
  it "returns the url with the given extensions" do
86
93
  allow( Asgit ).to receive(:current_branch).and_return('master')
87
- expect( @mm.cdn_asset_url('image_one?#iefix') ).to eq "/assets/cdn/#{@extension.id}/image_one?#iefix"
88
- expect( @mm.cdn_asset_url('img.one.jpg?#iefix') ).to eq "http://production.com/img.one.jpg?#iefix"
94
+ expect( @context.cdn_asset_url('image_one?#iefix') ).to eq "/assets/cdn/#{@extension.id}/image_one?#iefix"
95
+ expect( @context.cdn_asset_url('img.one.jpg?#iefix') ).to eq "http://production.com/img.one.jpg?#iefix"
89
96
  end
90
97
  it "raises an error if the root asset is missing" do
91
98
  expect{
92
- @mm.cdn_asset_url('missing_image?#iefix')
99
+ @context.cdn_asset_url('missing_image?#iefix')
93
100
  }.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image'"
94
101
  expect{
95
- @mm.cdn_asset_url('missing_image.one.jpg?#iefix')
102
+ @context.cdn_asset_url('missing_image.one.jpg?#iefix')
96
103
  }.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image.one.jpg'"
97
104
  end
98
105
  end
@@ -102,10 +109,10 @@ describe BranchableCDNAssets::Middleman::Helpers do
102
109
  describe "sass helpers" do
103
110
  describe "#cdn_asset_url" do
104
111
  it "calls mm#cdn_asset_url with the asset path" do
105
- expect( @mm ).to receive(:cdn_asset_url).with('image_path', nil)
112
+ expect( @context ).to receive(:cdn_asset_url).with('image_path', nil)
106
113
 
107
114
  source = 'body { background: url( cdn_asset_url("image_path") ); }'
108
- Sass.compile( source )
115
+ Sass.compile( source, {custom: {middleman_context: @context}} )
109
116
  end
110
117
  end
111
118
  end
@@ -125,6 +132,13 @@ describe BranchableCDNAssets::Middleman::Helpers do
125
132
  @mm = Middleman::Fixture.app
126
133
  @cdn1 = @mm.extensions[:cdn_assets]["instance_0"]
127
134
  @cdn2 = @mm.extensions[:cdn_assets]["instance_1"]
135
+
136
+ # split test based on changes in v4
137
+ if @mm.respond_to?(:template_context_class)
138
+ @context = @mm.template_context_class.new(@mm)
139
+ else
140
+ @context = @mm
141
+ end
128
142
  end
129
143
 
130
144
  after :all do
@@ -138,25 +152,25 @@ describe BranchableCDNAssets::Middleman::Helpers do
138
152
  it "finds remote files on correct cdn" do
139
153
  allow( Asgit ).to receive(:current_branch).and_return('master')
140
154
 
141
- expect( @mm.cdn_asset_url('image_remote_cdn1') ).to eq 'http://production.com/image_remote_cdn1'
142
- expect( @mm.cdn_asset_url('image_remote_cdn2') ).to eq 'http://production.com/image_remote_cdn2'
155
+ expect( @context.cdn_asset_url('image_remote_cdn1') ).to eq 'http://production.com/image_remote_cdn1'
156
+ expect( @context.cdn_asset_url('image_remote_cdn2') ).to eq 'http://production.com/image_remote_cdn2'
143
157
  end
144
158
 
145
159
  it "finds local files on correct cdn" do
146
- expect( @mm.cdn_asset_url('image_cdn') ).to eq "/assets/cdn/cdn1/image_cdn"
147
- expect( @mm.cdn_asset_url('image_cdn2') ).to eq "/assets/cdn/cdn2/image_cdn2"
160
+ expect( @context.cdn_asset_url('image_cdn') ).to eq "/assets/cdn/cdn1/image_cdn"
161
+ expect( @context.cdn_asset_url('image_cdn2') ).to eq "/assets/cdn/cdn2/image_cdn2"
148
162
  end
149
163
  end
150
164
 
151
165
  context "when file exists on multiple cdns" do
152
166
  it "returns file on given cdn" do
153
- expect( @mm.cdn_asset_url('image_local', 'cdn1') ).to eq "/assets/cdn/cdn1/image_local"
154
- expect( @mm.cdn_asset_url('image_local', 'cdn2') ).to eq "/assets/cdn/cdn2/image_local"
167
+ expect( @context.cdn_asset_url('image_local', 'cdn1') ).to eq "/assets/cdn/cdn1/image_local"
168
+ expect( @context.cdn_asset_url('image_local', 'cdn2') ).to eq "/assets/cdn/cdn2/image_local"
155
169
  end
156
170
 
157
171
  it "raises error if a cdn key isn't given" do
158
172
  expect{
159
- @mm.cdn_asset_url('image_local')
173
+ @context.cdn_asset_url('image_local')
160
174
  }.to raise_error BranchableCDNAssets::Middleman::MultipleCDNError
161
175
  end
162
176
  end
@@ -166,10 +180,10 @@ describe BranchableCDNAssets::Middleman::Helpers do
166
180
  describe "sass helpers" do
167
181
  describe "#cdn_asset_url" do
168
182
  it "is called with the cdn argument if given" do
169
- expect( @mm ).to receive(:cdn_asset_url).with('image_path', 'cdn2')
183
+ expect( @context ).to receive(:cdn_asset_url).with('image_path', 'cdn2')
170
184
 
171
185
  source = 'body { background: url( cdn_asset_url("image_path", "cdn2") ); }'
172
- Sass.compile( source )
186
+ Sass.compile( source, {custom: {middleman_context: @context}} )
173
187
  end
174
188
  end
175
189
  end
@@ -4,7 +4,12 @@ module Middleman
4
4
  attr_reader :browser
5
5
 
6
6
  def initialize app
7
- app_on_rack = app.class.to_rack_app
7
+ if app.class.respond_to?(:to_rack_app)
8
+ app_on_rack = app.class.to_rack_app
9
+ else
10
+ require 'middleman-core/rack'
11
+ app_on_rack = Middleman::Rack.new(app)
12
+ end
8
13
  @browser = ::Rack::Test::Session.new( ::Rack::MockSession.new(app_on_rack) )
9
14
  end
10
15
 
@@ -12,5 +17,9 @@ module Middleman
12
17
  browser.get( URI.escape(path) ).body
13
18
  end
14
19
 
20
+ def get_response path
21
+ browser.get( URI.escape(path) )
22
+ end
23
+
15
24
  end
16
- end
25
+ end
@@ -1,14 +1,31 @@
1
+ begin
2
+ require 'middleman-core/rack'
3
+ rescue LoadError
4
+ end
5
+
6
+
1
7
  module Middleman
2
8
  module Fixture
3
9
 
4
10
  class << self
11
+
5
12
  def app &block
6
13
  ENV['MM_ROOT'] = Given::TMP
7
- Middleman::Application.server.inst do
8
- instance_eval(&block) if block
14
+
15
+ if Middleman::Application.respond_to?(:server)
16
+ app = Middleman::Application.server.inst do
17
+ instance_eval(&block) if block
18
+ end
19
+ else
20
+ app = Middleman::Application.new do
21
+ instance_eval(&block) if block
22
+ end
9
23
  end
24
+
25
+ app
10
26
  end
27
+
11
28
  end
12
29
 
13
30
  end
14
- end
31
+ end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branchable_cdn_assets-middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: branchable_cdn_assets
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
81
  requirements:
76
82
  - - ">="
77
83
  - !ruby/object:Gem::Version
78
- version: 1.9.3
84
+ version: 2.0.0
79
85
  required_rubygems_version: !ruby/object:Gem::Requirement
80
86
  requirements:
81
87
  - - ">="