caleb-cloudfront_asset_host 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
@@ -29,6 +29,9 @@ module CloudfrontAssetHost
|
|
29
29
|
# Key-prefix under which to store gzipped assets
|
30
30
|
mattr_accessor :gzip_prefix
|
31
31
|
|
32
|
+
# Key-prefix under which to store plain (unzipped) assets
|
33
|
+
mattr_accessor :plain_prefix
|
34
|
+
|
32
35
|
class << self
|
33
36
|
|
34
37
|
def configure
|
@@ -64,17 +67,21 @@ module CloudfrontAssetHost
|
|
64
67
|
|
65
68
|
if gzip_accepted && gzip_allowed
|
66
69
|
host << "/#{CloudfrontAssetHost.gzip_prefix}"
|
70
|
+
else
|
71
|
+
host << "/#{CloudfrontAssetHost.plain_prefix}"
|
67
72
|
end
|
73
|
+
else
|
74
|
+
host << "/#{CloudfrontAssetHost.plain_prefix}"
|
68
75
|
end
|
69
76
|
|
70
77
|
host
|
71
78
|
end
|
72
79
|
|
73
80
|
def cname
|
74
|
-
if
|
75
|
-
|
81
|
+
if @@cname.is_a? Proc
|
82
|
+
@@cname.call
|
76
83
|
else
|
77
|
-
|
84
|
+
@@cname
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
@@ -32,8 +32,15 @@ module CloudfrontAssetHost
|
|
32
32
|
if url
|
33
33
|
path = path_for_url(url, stylesheet_path)
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
# handle paths that have a url hash in them (like svg fonts sometimes do)
|
36
|
+
file_path = if path.include?('#') && path.reverse.split(/#/, 2).last.reverse.end_with?('.svg')
|
37
|
+
path.reverse.split(/#/, 2).last.reverse
|
38
|
+
else
|
39
|
+
path
|
40
|
+
end
|
41
|
+
|
42
|
+
if path.present? && File.exists?(file_path)
|
43
|
+
key = CloudfrontAssetHost.key_for_path(file_path) + path.gsub(Rails.public_path, '')
|
37
44
|
"url(#{CloudfrontAssetHost.asset_host}/#{key})"
|
38
45
|
else
|
39
46
|
puts "Could not extract path: #{path}"
|
@@ -57,7 +57,7 @@ module CloudfrontAssetHost
|
|
57
57
|
|
58
58
|
def keys_with_paths
|
59
59
|
current_paths.inject({}) do |result, path|
|
60
|
-
key = CloudfrontAssetHost.key_for_path(path) + path.gsub(Rails.public_path, '')
|
60
|
+
key = "#{CloudfrontAssetHost.plain_prefix}/" << CloudfrontAssetHost.key_for_path(path) + path.gsub(Rails.public_path, '')
|
61
61
|
|
62
62
|
result[key] = path
|
63
63
|
result
|
@@ -111,7 +111,8 @@ module CloudfrontAssetHost
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def s3
|
114
|
-
|
114
|
+
env_config = config.has_key?(Rails.env) ? config[Rails.env] : config
|
115
|
+
@s3 ||= RightAws::S3.new(env_config['access_key_id'], env_config['secret_access_key'])
|
115
116
|
end
|
116
117
|
|
117
118
|
def config
|