cdn_asset_gem 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cdn_asset_gem/view/helpers.rb +9 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df30ad023c94cb34fe2da970a0a2fa0332f4f3c
|
4
|
+
data.tar.gz: 96f55810b672d27934e8dd3f35edfee14dece85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb5d9c1164476198a1b62f6f7d2c676a6f212825e2ab53a1f7b0e01cac3da5a03c71fdf510138e35e3ca5042398adfe253c1234e7d5cc59a679483ee5e76190a
|
7
|
+
data.tar.gz: fbc11c193891ef4726e65109742baca055451909721d452d425eea1573b74eab350b5cb6c0b594ed46c981f97e6321da4cd4ee993e92d0b591165141d2399f62
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module CdnAssetGem
|
2
2
|
module View
|
3
3
|
module Helpers
|
4
|
-
def map_asset(root_path: '', asset_name:)
|
5
|
-
|
6
|
-
|
4
|
+
def map_asset(root_path: '', asset_name:, file_type:)
|
5
|
+
file = "#{file_type}/#{asset_name}.min.#{file_type}"
|
6
|
+
|
7
|
+
if manifest_hash(root_path)[file]
|
8
|
+
"#{ENV['CDN_URL']}#{root_path}/assets/#{manifest_hash(root_path)[file]}"
|
7
9
|
else
|
8
|
-
"#{ENV['CDN_URL']}/#{
|
10
|
+
"#{ENV['CDN_URL']}#{root_path}/assets/#{file}"
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -13,15 +15,14 @@ module CdnAssetGem
|
|
13
15
|
|
14
16
|
def manifest_hash(root_path)
|
15
17
|
if root_path.blank? || root_path == '/'
|
16
|
-
assets_path = 'assets
|
18
|
+
assets_path = '/assets'
|
17
19
|
else
|
18
|
-
assets_path = "#{root_path}/assets
|
20
|
+
assets_path = "#{root_path}/assets"
|
19
21
|
end
|
20
22
|
|
21
23
|
response = Rails.cache.fetch("cdn-asset-#{root_path}", expires_in: 5.minutes) do
|
22
|
-
HTTP.get("#{ENV['CDN_URL']}#{assets_path}rev-manifest.json")
|
24
|
+
HTTP.get("#{ENV['CDN_URL']}#{assets_path}/rev-manifest.json")
|
23
25
|
end
|
24
|
-
|
25
26
|
JSON.parse(response) if response.code == 200
|
26
27
|
end
|
27
28
|
end
|