branchable_cdn_assets-middleman 0.5.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/branchable_cdn_assets/middleman/extension.rb +22 -8
- data/lib/branchable_cdn_assets/middleman/helpers.rb +42 -11
- data/lib/branchable_cdn_assets/middleman/rake_tasks.rb +6 -1
- data/lib/branchable_cdn_assets/middleman/version.rb +1 -1
- data/spec/fixtures/multi/config.rb +58 -0
- data/spec/lib/branchable_cdn_assets/middleman/extension_spec.rb +4 -3
- data/spec/lib/branchable_cdn_assets/middleman/helpers_spec.rb +178 -0
- data/spec/spec_helper.rb +1 -1
- metadata +16 -14
- data/spec/lib/branchable_cdn_assets/middleman/helpers_specs.rb +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8030ec152bd0407e74c622d95d127cecebe65e
|
4
|
+
data.tar.gz: 1a59b0c2b966dfe40f48073ea600199dfbcea039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 983fedb01fa253045cfc846fa871b47ce48566ceb19452a6019b9c3decfb86fd61ff2c83c2f32b964651c2031ff34721c02d233d47936208a9f94b9bcbfc4381
|
7
|
+
data.tar.gz: a72ae5b031b45fc52149b784aee430f289dc6e68d023f3a7ec4b805bee2be0662d5b03714d5a8b98dd50b12ad7ac0b4557669e90dfc10f8bd8c3007e6508caee
|
@@ -2,12 +2,16 @@ module BranchableCDNAssets
|
|
2
2
|
module Middleman
|
3
3
|
|
4
4
|
class Extension < ::Middleman::Extension
|
5
|
+
self.supports_multiple_instances = true
|
5
6
|
|
6
|
-
option :
|
7
|
-
option :
|
8
|
-
option :
|
7
|
+
option :id, nil, 'name of this cdn'
|
8
|
+
option :environments, {}, 'environment specific configuration'
|
9
|
+
option :cloudfront, nil, 'access keys for cloudfront account'
|
10
|
+
option :cdn_dir, 'cdn', 'source directory for cdn files'
|
9
11
|
option :production_branch, 'master', 'which branch is the production branch'
|
10
|
-
option :default_env, 'staging',
|
12
|
+
option :default_env, 'staging', 'the default environment if none is set'
|
13
|
+
option :file_filter, nil, 'filter for managed files'
|
14
|
+
option :allow_local, false, 'allow local files to remain on deploy checks'
|
11
15
|
|
12
16
|
def after_configuration
|
13
17
|
if defined?(::Sass::Script::Functions)
|
@@ -25,9 +29,15 @@ module BranchableCDNAssets
|
|
25
29
|
production_branch: options.production_branch,
|
26
30
|
default_env: options.default_env,
|
27
31
|
environments: options.environments,
|
28
|
-
|
29
|
-
|
32
|
+
dir: options.cdn_dir,
|
33
|
+
file_filter: options.file_filter,
|
34
|
+
allow_local: options.allow_local
|
30
35
|
}
|
36
|
+
if options.cloudfront
|
37
|
+
data.merge! invalidators: {
|
38
|
+
cloudfront: options.cloudfront
|
39
|
+
}
|
40
|
+
end
|
31
41
|
Config.new data
|
32
42
|
end
|
33
43
|
|
@@ -35,6 +45,10 @@ module BranchableCDNAssets
|
|
35
45
|
BranchableCDNAssets::FileManager.new config
|
36
46
|
end
|
37
47
|
|
48
|
+
def id
|
49
|
+
options.id || self.object_id.to_s
|
50
|
+
end
|
51
|
+
|
38
52
|
helpers do
|
39
53
|
include Helpers
|
40
54
|
end
|
@@ -45,8 +59,8 @@ module BranchableCDNAssets
|
|
45
59
|
file_manager.list( :local ).map do |file|
|
46
60
|
::Middleman::Sitemap::Resource.new(
|
47
61
|
app.sitemap,
|
48
|
-
File.join( "assets/cdn", file ),
|
49
|
-
File.join( app.root,
|
62
|
+
File.join( "assets/cdn", id, file ),
|
63
|
+
File.join( app.root, options.cdn_dir, file )
|
50
64
|
)
|
51
65
|
end
|
52
66
|
end
|
@@ -8,26 +8,50 @@ module BranchableCDNAssets
|
|
8
8
|
#
|
9
9
|
# @param path [String]
|
10
10
|
# @return [String] path to asset
|
11
|
-
def cdn_asset_url path
|
11
|
+
def cdn_asset_url path, cdn=nil
|
12
12
|
|
13
13
|
# remove trailing characters after extension
|
14
|
-
|
14
|
+
# http://rubular.com/r/l0JR3ZuqI2
|
15
|
+
ext_trail = path.match(/(?:\.\w+)?([\#\?\&]\S+)/).to_a
|
15
16
|
ext_trail = ext_trail[1] || ''
|
16
17
|
|
17
18
|
real_path = path.sub(ext_trail, '')
|
18
19
|
|
19
|
-
# check for file in sitemap
|
20
|
-
|
21
|
-
|
20
|
+
# check for file in sitemap on each extension
|
21
|
+
sitemap_candidates = []
|
22
|
+
if environment != :build
|
23
|
+
extensions[:cdn_assets].each do |k, inst|
|
24
|
+
next if cdn && inst.id != cdn
|
25
|
+
|
26
|
+
resource = sitemap.find_resource_by_path( File.join( "assets/cdn", inst.id, real_path ) )
|
27
|
+
sitemap_candidates.push ["/", resource.destination_path, ext_trail].join('') if resource
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
24
|
-
# check for the file in the
|
25
|
-
|
31
|
+
# check for the file in the file_managers
|
32
|
+
file_manager_candidates = []
|
33
|
+
extensions[:cdn_assets].each do |k, inst|
|
34
|
+
next if cdn && inst.id != cdn
|
35
|
+
|
36
|
+
location = (environment == :build) ? :remote : :all;
|
37
|
+
file = inst.file_manager.find(real_path, location)
|
26
38
|
|
27
|
-
|
39
|
+
file_manager_candidates.push [file, ext_trail].join('') if file && file != :local
|
40
|
+
end
|
41
|
+
|
42
|
+
candidates = file_manager_candidates + sitemap_candidates
|
43
|
+
unless candidates.empty?
|
44
|
+
if candidates.length == 1
|
45
|
+
return candidates.first
|
46
|
+
elsif cdn # file found local & on remote
|
47
|
+
return candidates.first
|
48
|
+
else
|
49
|
+
raise MultipleCDNError, "asset at '#{real_path}' found on multiple cdns. please pass a cdn id"
|
50
|
+
end
|
51
|
+
end
|
28
52
|
|
29
53
|
# not found at any location
|
30
|
-
raise "missing asset at '#{real_path}'"
|
54
|
+
raise FileNotFoundError, "missing asset at '#{real_path}'"
|
31
55
|
end
|
32
56
|
alias :cdn_asset_path :cdn_asset_url
|
33
57
|
|
@@ -36,13 +60,20 @@ module BranchableCDNAssets
|
|
36
60
|
|
37
61
|
module SassHelpers
|
38
62
|
|
39
|
-
def cdn_asset_url( path )
|
40
|
-
|
63
|
+
def cdn_asset_url( path, cdn=nil )
|
64
|
+
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 )
|
41
66
|
::Sass::Script::String.new("url(\"#{file}\")")
|
42
67
|
end
|
43
68
|
alias :cdn_asset_path :cdn_asset_url
|
44
69
|
|
45
70
|
end
|
46
71
|
|
72
|
+
class MultipleCDNError < StandardError
|
73
|
+
end
|
74
|
+
|
75
|
+
class FileNotFoundError < StandardError
|
76
|
+
end
|
77
|
+
|
47
78
|
end
|
48
79
|
end
|
@@ -22,7 +22,12 @@ module BranchableCDNAssets
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def file_manager
|
25
|
-
@_file_manager
|
25
|
+
return @_file_manager if @_file_manager
|
26
|
+
|
27
|
+
inst = mm.extensions[:cdn_assets].values.find { |inst| inst.id.to_s == @rake_namespace.to_s }
|
28
|
+
@_file_manager = FileManager.new inst.config
|
29
|
+
|
30
|
+
return @_file_manager
|
26
31
|
end
|
27
32
|
|
28
33
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
set :environment, :test
|
2
|
+
set :show_exceptions, false
|
3
|
+
|
4
|
+
set :css_dir, "assets/css"
|
5
|
+
set :js_dir, "assets/scripts"
|
6
|
+
set :images_dir, "assets/images"
|
7
|
+
|
8
|
+
activate :cdn_assets do |c|
|
9
|
+
|
10
|
+
c.id = "cdn1"
|
11
|
+
c.cdn_dir = "cdn"
|
12
|
+
|
13
|
+
c.environments = {
|
14
|
+
production: {
|
15
|
+
host: 'production_host',
|
16
|
+
url: 'http://production.com',
|
17
|
+
root: '/var/www/production'
|
18
|
+
},
|
19
|
+
test: {
|
20
|
+
host: 'test_host',
|
21
|
+
url: 'http://test.com',
|
22
|
+
root: '/var/www/test'
|
23
|
+
},
|
24
|
+
staging: {
|
25
|
+
host: 'staging_host',
|
26
|
+
url: 'http://staging.com',
|
27
|
+
root: '/var/www/staging'
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
activate :cdn_assets do |c|
|
34
|
+
|
35
|
+
c.id = "cdn2"
|
36
|
+
c.cdn_dir = "cdn2"
|
37
|
+
|
38
|
+
c.environments = {
|
39
|
+
production: {
|
40
|
+
host: 'production_host',
|
41
|
+
url: 'http://production.com',
|
42
|
+
root: '/var/www/production'
|
43
|
+
},
|
44
|
+
test: {
|
45
|
+
host: 'test_host',
|
46
|
+
url: 'http://test.com',
|
47
|
+
root: '/var/www/test'
|
48
|
+
},
|
49
|
+
staging: {
|
50
|
+
host: 'staging_host',
|
51
|
+
url: 'http://staging.com',
|
52
|
+
root: '/var/www/staging'
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
activate :directory_indexes
|
@@ -9,7 +9,8 @@ describe BranchableCDNAssets::Middleman::Extension do
|
|
9
9
|
Given.file 'cdn/img_two', ''
|
10
10
|
|
11
11
|
@mm = Middleman::Fixture.app
|
12
|
-
|
12
|
+
|
13
|
+
@extension = @mm.extensions[:cdn_assets].first[1]
|
13
14
|
end
|
14
15
|
|
15
16
|
after :each do
|
@@ -54,8 +55,8 @@ describe BranchableCDNAssets::Middleman::Extension do
|
|
54
55
|
describe "#manipulate_resource_list" do
|
55
56
|
it "adds local files to the resource list" do
|
56
57
|
resource_paths = @mm.sitemap.resources.map(&:url)
|
57
|
-
expect( resource_paths ).to include
|
58
|
-
expect( resource_paths ).to include
|
58
|
+
expect( resource_paths ).to include "/assets/cdn/#{@extension.object_id}/img_one"
|
59
|
+
expect( resource_paths ).to include "/assets/cdn/#{@extension.object_id}/img_two"
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'middleman_spec_helper'
|
3
|
+
|
4
|
+
describe BranchableCDNAssets::Middleman::Helpers do
|
5
|
+
|
6
|
+
|
7
|
+
describe "with a single instance" do
|
8
|
+
before :each do
|
9
|
+
Given.fixture 'base'
|
10
|
+
Given.file 'cdn/master.manifest', "image_one\nimage_all\nimage_remote_one\nimg.one.jpg\nimage_prod"
|
11
|
+
Given.file 'cdn/some_branch.manifest', "image_one\nimage_all\nimage_remote_two\n"
|
12
|
+
Given.file 'cdn/image_one', ''
|
13
|
+
Given.file 'cdn/image_two', ''
|
14
|
+
Given.file 'cdn/image_all', ''
|
15
|
+
Given.file 'cdn/image_prod', ''
|
16
|
+
|
17
|
+
@mm = Middleman::Fixture.app
|
18
|
+
@extension = @mm.extensions[:cdn_assets].first[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
Given.cleanup!
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "sitemap helpers" do
|
26
|
+
describe "#cdn_asset_url" do
|
27
|
+
context "when asset is on production cdn" do
|
28
|
+
it "returns the 'live' url of the asset" do
|
29
|
+
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'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when asset is on staging cdn" do
|
35
|
+
it "returns the 'live' url of the asset" do
|
36
|
+
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'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when asset is local" do
|
42
|
+
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"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when asset is local and listed in a manifest" do
|
48
|
+
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"
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when building" do
|
53
|
+
it "returns remote url" do
|
54
|
+
@mm.config[:environment] = :build
|
55
|
+
|
56
|
+
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"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when the asset is missing" do
|
65
|
+
it "raises an error with the asset name" do
|
66
|
+
expect{
|
67
|
+
@mm.cdn_asset_url('missing_image')
|
68
|
+
}.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image'"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when assets have multiple extensions" do
|
73
|
+
it "returns the url with the given extensions" do
|
74
|
+
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"
|
76
|
+
end
|
77
|
+
it "raises an error if the root asset is missing" do
|
78
|
+
expect{
|
79
|
+
@mm.cdn_asset_url('missing_image.1.jpg')
|
80
|
+
}.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image.1.jpg'"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "with added file extensions" do
|
85
|
+
it "returns the url with the given extensions" do
|
86
|
+
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"
|
89
|
+
end
|
90
|
+
it "raises an error if the root asset is missing" do
|
91
|
+
expect{
|
92
|
+
@mm.cdn_asset_url('missing_image?#iefix')
|
93
|
+
}.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image'"
|
94
|
+
expect{
|
95
|
+
@mm.cdn_asset_url('missing_image.one.jpg?#iefix')
|
96
|
+
}.to raise_error BranchableCDNAssets::Middleman::FileNotFoundError, "missing asset at 'missing_image.one.jpg'"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "sass helpers" do
|
103
|
+
describe "#cdn_asset_url" do
|
104
|
+
it "calls mm#cdn_asset_url with the asset path" do
|
105
|
+
expect( @mm ).to receive(:cdn_asset_url).with('image_path', nil)
|
106
|
+
|
107
|
+
source = 'body { background: url( cdn_asset_url("image_path") ); }'
|
108
|
+
Sass.compile( source )
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe "with a multiple instances" do
|
116
|
+
before :all do
|
117
|
+
Given.fixture 'multi'
|
118
|
+
Given.file 'cdn/master.manifest', "image_one\nimage_remote_cdn1"
|
119
|
+
Given.file 'cdn/image_local', ''
|
120
|
+
Given.file 'cdn/image_cdn', ''
|
121
|
+
Given.file 'cdn2/master.manifest', "image_one\nimage_remote_cdn2"
|
122
|
+
Given.file 'cdn2/image_local', ''
|
123
|
+
Given.file 'cdn2/image_cdn2', ''
|
124
|
+
|
125
|
+
@mm = Middleman::Fixture.app
|
126
|
+
@cdn1 = @mm.extensions[:cdn_assets]["instance_0"]
|
127
|
+
@cdn2 = @mm.extensions[:cdn_assets]["instance_1"]
|
128
|
+
end
|
129
|
+
|
130
|
+
after :all do
|
131
|
+
Given.cleanup!
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
describe "sitemap helpers" do
|
136
|
+
describe "#cdn_asset_url" do
|
137
|
+
context "when file exists on only one cdn" do
|
138
|
+
it "finds remote files on correct cdn" do
|
139
|
+
allow( Asgit ).to receive(:current_branch).and_return('master')
|
140
|
+
|
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'
|
143
|
+
end
|
144
|
+
|
145
|
+
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"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "when file exists on multiple cdns" do
|
152
|
+
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"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "raises error if a cdn key isn't given" do
|
158
|
+
expect{
|
159
|
+
@mm.cdn_asset_url('image_local')
|
160
|
+
}.to raise_error BranchableCDNAssets::Middleman::MultipleCDNError
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "sass helpers" do
|
167
|
+
describe "#cdn_asset_url" do
|
168
|
+
it "is called with the cdn argument if given" do
|
169
|
+
expect( @mm ).to receive(:cdn_asset_url).with('image_path', 'cdn2')
|
170
|
+
|
171
|
+
source = 'body { background: url( cdn_asset_url("image_path", "cdn2") ); }'
|
172
|
+
Sass.compile( source )
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: branchable_cdn_assets-middleman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.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:
|
11
|
+
date: 2015-11-18 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
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: branchable_cdn_assets
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
41
|
-
description:
|
40
|
+
version: '0.7'
|
41
|
+
description: " Middleman Adaptor for branchable_cdn_assets "
|
42
42
|
email: marketing-dev@mailchimp.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
@@ -52,9 +52,10 @@ files:
|
|
52
52
|
- lib/branchable_cdn_assets/middleman/version.rb
|
53
53
|
- lib/middleman_extension.rb
|
54
54
|
- spec/fixtures/base/config.rb
|
55
|
+
- spec/fixtures/multi/config.rb
|
55
56
|
- spec/lib/branchable_cdn_assets-middleman_spec.rb
|
56
57
|
- spec/lib/branchable_cdn_assets/middleman/extension_spec.rb
|
57
|
-
- spec/lib/branchable_cdn_assets/middleman/
|
58
|
+
- spec/lib/branchable_cdn_assets/middleman/helpers_spec.rb
|
58
59
|
- spec/lib/branchable_cdn_assets/middleman/rake_tasks_spec.rb
|
59
60
|
- spec/middleman_spec_helper.rb
|
60
61
|
- spec/spec_helper.rb
|
@@ -72,24 +73,25 @@ require_paths:
|
|
72
73
|
- lib
|
73
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
|
-
- -
|
76
|
+
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: 1.9.3
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
|
-
- -
|
81
|
+
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
85
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.4.5
|
86
|
+
rubygems_version: 2.4.5.1
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: Middleman Adaptor for branchable_cdn_assets
|
89
90
|
test_files:
|
90
91
|
- spec/fixtures/base/config.rb
|
92
|
+
- spec/fixtures/multi/config.rb
|
91
93
|
- spec/lib/branchable_cdn_assets/middleman/extension_spec.rb
|
92
|
-
- spec/lib/branchable_cdn_assets/middleman/
|
94
|
+
- spec/lib/branchable_cdn_assets/middleman/helpers_spec.rb
|
93
95
|
- spec/lib/branchable_cdn_assets/middleman/rake_tasks_spec.rb
|
94
96
|
- spec/lib/branchable_cdn_assets-middleman_spec.rb
|
95
97
|
- spec/middleman_spec_helper.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'middleman_spec_helper'
|
3
|
-
|
4
|
-
describe CDNAssets::Middleman::Helpers do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
Given.fixture 'base'
|
8
|
-
Given.file 'cdn/production.manifest', "image_one\nimage_remote_one\nimg.one.jpg"
|
9
|
-
Given.file 'cdn/staging.manifest', "image_one\nimage_remote_two\n"
|
10
|
-
Given.file 'cdn/image_one', ''
|
11
|
-
Given.file 'cdn/image_two', ''
|
12
|
-
|
13
|
-
@mm = Middleman::Fixture.app
|
14
|
-
@extension = @mm.extensions[:cdn_assets]
|
15
|
-
end
|
16
|
-
|
17
|
-
after :each do
|
18
|
-
Given.cleanup!
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "sitemap helpers" do
|
22
|
-
describe "#cdn_asset_url" do
|
23
|
-
context "when asset is on production cdn" do
|
24
|
-
it "returns the 'live' url of the asset" do
|
25
|
-
Asgit.stub(current_branch: 'master')
|
26
|
-
expect( @mm.cdn_asset_url('image_remote_one') ).to eq 'http://production.com/image_remote_one'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when asset is on staging cdn" do
|
31
|
-
it "returns the 'live' url of the asset" do
|
32
|
-
Asgit.stub(current_branch: 'some_branch')
|
33
|
-
expect( @mm.cdn_asset_url('image_remote_two') ).to eq 'http://staging.com/some_branch/image_remote_two'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when asset is local" do
|
38
|
-
it "returns the 'localhost' url of the asset" do
|
39
|
-
expect( @mm.cdn_asset_url('image_two') ).to eq '/assets/cdn/image_two'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when asset is local and listed in a manifest" do
|
44
|
-
it "returns the 'localhost' url of the asset" do
|
45
|
-
expect( @mm.cdn_asset_url('image_one') ).to eq '/assets/cdn/image_one'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when the asset is missing" do
|
50
|
-
it "raises an error with the asset name" do
|
51
|
-
expect{
|
52
|
-
@mm.cdn_asset_url('missing_image')
|
53
|
-
}.to raise_error "missing asset at 'missing_image'"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when assets have multiple extensions" do
|
58
|
-
it "returns the url with the given extensions" do
|
59
|
-
expect( @mm.cdn_asset_url('img.one.jpg') ).to eq '/assets/cdn/img.one.jpg'
|
60
|
-
end
|
61
|
-
it "raises an error if the root asset is missing" do
|
62
|
-
expect{
|
63
|
-
@mm.cdn_asset_url('missing_image.1.jpg')
|
64
|
-
}.to raise_error "missing asset at 'missing_image.1.jpg'"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "with added file extensions" do
|
69
|
-
it "returns the url with the given extensions" do
|
70
|
-
expect( @mm.cdn_asset_url('image_one?#iefix') ).to eq '/assets/cdn/image_one?#iefix'
|
71
|
-
expect( @mm.cdn_asset_url('img.one.jpg?#iefix') ).to eq '/assets/cdn/img.one.jpg?#iefix'
|
72
|
-
end
|
73
|
-
it "raises an error if the root asset is missing" do
|
74
|
-
expect{
|
75
|
-
@mm.cdn_asset_url('missing_image?#iefix')
|
76
|
-
}.to raise_error "missing asset at 'missing_image'"
|
77
|
-
expect{
|
78
|
-
@mm.cdn_asset_url('missing_image.one.jpg?#iefix')
|
79
|
-
}.to raise_error "missing asset at 'missing_image.one.jpg'"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "sass helpers" do
|
86
|
-
describe "#cdn_asset_url" do
|
87
|
-
it "calls mm#cdn_asset_url with the asset path" do
|
88
|
-
expect( @mm ).to receive(:cdn_asset_url).with('image_path')
|
89
|
-
|
90
|
-
source = 'body { background: url( cdn_asset_url("image_path") ); }'
|
91
|
-
Sass.compile( source )
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|