smart_asset 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/smart_asset.rb +26 -9
- data/lib/smart_asset/helper.rb +2 -2
- data/lib/smart_asset/version.rb +1 -1
- metadata +2 -2
data/lib/smart_asset.rb
CHANGED
@@ -14,7 +14,7 @@ require 'smart_asset/version'
|
|
14
14
|
class SmartAsset
|
15
15
|
class <<self
|
16
16
|
|
17
|
-
attr_accessor :asset_host, :cache, :config, :dest, :env, :envs, :pub, :root, :sources
|
17
|
+
attr_accessor :asset_host, :asset_counter, :cache, :config, :dest, :env, :envs, :pub, :root, :sources
|
18
18
|
|
19
19
|
BIN = File.expand_path(File.dirname(__FILE__) + '/../bin')
|
20
20
|
CLOSURE_COMPILER = BIN + '/closure_compiler.jar'
|
@@ -84,6 +84,7 @@ class SmartAsset
|
|
84
84
|
@root = File.expand_path(root)
|
85
85
|
@config = YAML::load(File.read("#{@root}/#{relative_config}"))
|
86
86
|
|
87
|
+
@config['asset_host_count'] ||= 4
|
87
88
|
@config['asset_host'] ||= ActionController::Base.asset_host rescue nil
|
88
89
|
@config['environments'] ||= %w(production)
|
89
90
|
@config['public'] ||= 'public'
|
@@ -124,11 +125,6 @@ class SmartAsset
|
|
124
125
|
return @cache[type][match]
|
125
126
|
end
|
126
127
|
|
127
|
-
host =
|
128
|
-
@asset_host.respond_to?(:keys) ?
|
129
|
-
@asset_host[@env.to_s] :
|
130
|
-
@asset_host
|
131
|
-
|
132
128
|
dest = @dest[type]
|
133
129
|
ext = ext_from_type type
|
134
130
|
|
@@ -136,7 +132,7 @@ class SmartAsset
|
|
136
132
|
match = match.gsub('/', '_')
|
137
133
|
@cache[type][match] =
|
138
134
|
if result = Dir["#{dest}/*_#{match}.#{ext}"].sort.last
|
139
|
-
[
|
135
|
+
[ result.gsub(@pub, '') ]
|
140
136
|
else
|
141
137
|
[]
|
142
138
|
end
|
@@ -145,13 +141,13 @@ class SmartAsset
|
|
145
141
|
if package.to_s == match
|
146
142
|
files.collect do |file|
|
147
143
|
file = "/#{@sources[type]}/#{file}.#{ext}"
|
148
|
-
|
144
|
+
file if File.exists?("#{@pub}/#{file}")
|
149
145
|
end
|
150
146
|
elsif files
|
151
147
|
files.collect do |file|
|
152
148
|
if file.to_s == match
|
153
149
|
file = "/#{@sources[type]}/#{file}.#{ext}"
|
154
|
-
|
150
|
+
file if File.exists?("#{@pub}/#{file}")
|
155
151
|
end
|
156
152
|
end
|
157
153
|
end
|
@@ -160,6 +156,27 @@ class SmartAsset
|
|
160
156
|
end
|
161
157
|
end
|
162
158
|
|
159
|
+
def prepend_asset_host(path)
|
160
|
+
if @asset_host.respond_to?(:keys)
|
161
|
+
host = @asset_host[@env.to_s]
|
162
|
+
else
|
163
|
+
host = @asset_host
|
164
|
+
end
|
165
|
+
|
166
|
+
if host
|
167
|
+
if !@asset_counter || @asset_counter == @config['asset_host_count']
|
168
|
+
@asset_counter = 0
|
169
|
+
end
|
170
|
+
|
171
|
+
count = @asset_counter.to_s
|
172
|
+
@asset_counter += 1
|
173
|
+
|
174
|
+
host.gsub('%d', count) + path
|
175
|
+
else
|
176
|
+
path
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
163
180
|
private
|
164
181
|
|
165
182
|
def ext_from_type(type)
|
data/lib/smart_asset/helper.rb
CHANGED
@@ -3,14 +3,14 @@ class SmartAsset
|
|
3
3
|
|
4
4
|
def javascript_include_merged(*javascripts)
|
5
5
|
output = javascript_paths(*javascripts).collect { |js|
|
6
|
-
"<script src=\"#{js}\" type=\"text/javascript\"></script>"
|
6
|
+
"<script src=\"#{SmartAsset.prepend_asset_host js}\" type=\"text/javascript\"></script>"
|
7
7
|
}.join("\n")
|
8
8
|
defined?(Rails) && Rails.version[0..0] == '3' ? output.html_safe : output
|
9
9
|
end
|
10
10
|
|
11
11
|
def stylesheet_link_merged(*stylesheets)
|
12
12
|
output = stylesheet_paths(*stylesheets).collect { |css|
|
13
|
-
"<link href=\"#{css}\" media=\"screen\" rel=\"Stylesheet\" type=\"text/css\" />"
|
13
|
+
"<link href=\"#{SmartAsset.prepend_asset_host css}\" media=\"screen\" rel=\"Stylesheet\" type=\"text/css\" />"
|
14
14
|
}.join("\n")
|
15
15
|
defined?(Rails) && Rails.version[0..0] == '3' ? output.html_safe : output
|
16
16
|
end
|
data/lib/smart_asset/version.rb
CHANGED