cdn_asset_gem 1.0.5 → 1.0.6
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 +24 -20
- 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: b4b299a4a5813c055d79c561c28ae9859527a571
|
4
|
+
data.tar.gz: 05e3455d86fda6e5a335538e0b25efdc2041d6dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af8e893c820b32b51791478d6fc7a2ed5d041a9b9a9f3921dc8a6760d87d2101305a1e119a443ffb591ac5248bb2d34437be34ae7e415cb8b27872c279d64f37
|
7
|
+
data.tar.gz: 340857a2b6bf807f208a17884b4019861f6b16c03140af181d4671e18cc5b582bd8b5785cd257f3725a8c1d4f287020cbcda2ca31f8f6dac5739aeec97b42603
|
@@ -1,28 +1,32 @@
|
|
1
1
|
module CdnAssetGem
|
2
|
-
|
3
|
-
|
2
|
+
module View
|
3
|
+
module Helpers
|
4
|
+
def map_asset(root_path: '', asset_name:, file_type:)
|
5
|
+
file = "#{file_type}/#{asset_name}.min.#{file_type}"
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
if manifest_hash(root_path)[file]
|
8
|
+
"#{ENV['CDN_URL']}#{root_path}/assets/#{manifest_hash(root_path)[file]}"
|
9
|
+
else
|
10
|
+
"#{ENV['CDN_URL']}#{root_path}/assets/#{file}"
|
11
|
+
end
|
12
|
+
end
|
11
13
|
|
12
|
-
|
14
|
+
private
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def manifest_hash(root_path)
|
17
|
+
if root_path.blank? || root_path == '/'
|
18
|
+
assets_path = '/assets'
|
19
|
+
else
|
20
|
+
assets_path = "#{root_path}/assets"
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
Rails.cache.fetch("cdn-asset-#{root_path}", expires_in: 5.minutes) do
|
24
|
+
uri = URI("#{ENV['CDN_URL']}#{assets_path}/rev-manifest.json")
|
25
|
+
response = Net::HTTP.get(uri)
|
26
|
+
response_code = Net::HTTP.get_response(uri).code
|
27
|
+
JSON.parse(response) if response_code == '200'
|
28
|
+
end
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|