branchable_cdn_assets-middleman 0.5.0 → 0.5.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: a9ae41911f2c5847089e9f35916266e6af72f5c5
4
- data.tar.gz: 50534f96859ea1fb073d75f1a71068ecad23e6b3
3
+ metadata.gz: c130145cf4f67c1f884a85a31cc1e24abaa68b5a
4
+ data.tar.gz: 8c26d06ccb56d4890f7ea8bd7e04be6c0d63ee02
5
5
  SHA512:
6
- metadata.gz: df4c5833e1795f56d7f39ab50cb79b68daaa5d725bb27a69650a7090882a7dfa918f338c0c71bf1e250ea7aed31b84081a5162d447be740558981925744f85ef
7
- data.tar.gz: 179305796158df8cbba3512aeb6c1bdb98cad9214001ced1e08d550b007351b3fdedee020ce408b412e23e0e21441414beccfedfc1773d15daeff07d1d1ce58d
6
+ metadata.gz: 85e82fe4001cdc02abf6c2d34eb53ff9621507b36cfe47f86b9824fa591c5cd2ef3c02ad0d90e0cf944ce843bbcd98af9dd779aeabe5e297af10b1934b652c79
7
+ data.tar.gz: f8b9d059cc4cef0e02e4b3c6936d48a85eee79f3b2be4aa7bd594460147bc5f45af12dfa9467d146391f49a12fb8eea593cb362879303f8d1c9e9ceff612d178
@@ -10,17 +10,24 @@ module BranchableCDNAssets
10
10
  # @return [String] path to asset
11
11
  def cdn_asset_url path
12
12
 
13
+ # remove trailing characters after extension
14
+ ext_trail = path.match(/\.\w+([\#\?\&]\S+)/).to_a
15
+ ext_trail = ext_trail[1] || ''
16
+
17
+ real_path = path.sub(ext_trail, '')
18
+
13
19
  # check for file in sitemap
14
- if environment != :build && resource = sitemap.find_resource_by_path( File.join( "assets/cdn", path ) )
15
- return "/" + resource.destination_path
20
+ if environment != :build && resource = sitemap.find_resource_by_path( File.join( "assets/cdn", real_path ) )
21
+ return "/" + [resource.destination_path, ext_trail].join
16
22
  end
17
23
 
18
24
  # check for the file in the file_manager
19
- file = extensions[:cdn_assets].file_manager.find(path)
20
- return file if file && file != :local
25
+ file = extensions[:cdn_assets].file_manager.find(real_path)
26
+
27
+ return [file, ext_trail].join if file && file != :local
21
28
 
22
29
  # not found at any location
23
- raise "missing asset at '#{path}'"
30
+ raise "missing asset at '#{real_path}'"
24
31
  end
25
32
  alias :cdn_asset_path :cdn_asset_url
26
33
 
@@ -13,14 +13,18 @@ module BranchableCDNAssets
13
13
  end
14
14
  end
15
15
 
16
- attr_reader :mm
17
-
18
16
  def initialize namespace
19
- @mm = ::Middleman::Application.server.inst
20
- @file_manager = FileManager.new @mm.extensions[:cdn_assets].config
21
17
  @rake_namespace = namespace
22
18
  end
23
19
 
20
+ def mm
21
+ @_mm ||= ::Middleman::Application.server.inst
22
+ end
23
+
24
+ def file_manager
25
+ @_file_manager ||= FileManager.new mm.extensions[:cdn_assets].config
26
+ end
27
+
24
28
  end
25
29
 
26
30
  end
@@ -1,5 +1,5 @@
1
1
  module BranchableCDNAssets
2
2
  module Middleman
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.2'
4
4
  end
5
5
  end
@@ -5,8 +5,8 @@ describe CDNAssets::Middleman::Helpers do
5
5
 
6
6
  before :each do
7
7
  Given.fixture 'base'
8
- Given.file 'cdn/production.manifest', "image_one\nimage_remote_one\n"
9
- Given.file 'cdn/staging.manifest', "image_one\nimage_remote_two\n"
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
10
  Given.file 'cdn/image_one', ''
11
11
  Given.file 'cdn/image_two', ''
12
12
 
@@ -53,6 +53,32 @@ describe CDNAssets::Middleman::Helpers do
53
53
  }.to raise_error "missing asset at 'missing_image'"
54
54
  end
55
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
56
82
  end
57
83
  end
58
84
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branchable_cdn_assets-middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.2.0
85
+ rubygems_version: 2.4.5
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Middleman Adaptor for branchable_cdn_assets