cdn_asset_gem 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17c0e6c5c6912191a11388275142871311b2bf5a
4
+ data.tar.gz: 5901afe7be3c49411d48ec0d33d4db9e070cdc64
5
+ SHA512:
6
+ metadata.gz: c78d7ce8c0bf70d9c0eaa58acb909d567ea6259f78c2ee4179bd7ce9b37f7b061414b9022aac1843daf52b5505c68283cb0b5a30806a336c023b37d1471fa7fd
7
+ data.tar.gz: 43f2530182d06948dea1862f4f144c85f9a749ab66d6f69f208bd2f9f098270ebb5633dff17d9d7d21c2398bf144c9f4f9b504bd9332b436dcb808ee067c3668
@@ -0,0 +1,13 @@
1
+ require 'cdn_assets_helper/view/helpers'
2
+
3
+ module CdnAssetsGem
4
+ module View
5
+ module Helpers
6
+ class Railtie < Rails::Railtie
7
+ initializer 'cdn_assets_helper.view.helpers' do |_app|
8
+ ActionView::Base.send :include, CdnAssetsGem::View::Helpers
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module CdnAssetGem
2
+ module View
3
+ module Helpers
4
+ def map_asset(root_path: '', asset_name:)
5
+ if manifest_hash
6
+ "#{ENV['CDN_URL']}/#{manifest_hash[asset_name]}"
7
+ else
8
+ "#{ENV['CDN_URL']}/#{asset_name}"
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def manifest_hash(root_path)
15
+ if root_path.blank? || root_path == '/'
16
+ assets_path = 'assets/'
17
+ else
18
+ assets_path = "#{root_path}/assets/"
19
+ end
20
+
21
+ response = Rails.cache.fetch("cdn-asset-#{root_path}", expires_in: 5.minutes) do
22
+ HTTP.get("#{ENV['CDN_URL']}#{assets_path}rev-manifest.json")
23
+ end
24
+
25
+ JSON.parse(response) if response.code == 200
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdn_asset_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Phil Baker
8
+ - Murray Catto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: http
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description:
29
+ email:
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/cdn_asset_gem.rb
35
+ - lib/cdn_asset_gem/view/helpers.rb
36
+ homepage:
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.6.14
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Asset generator
59
+ test_files: []
60
+ has_rdoc: