sprockets 3.3.1 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprockets might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/sprockets.rb +1 -1
- data/lib/sprockets/base.rb +9 -0
- data/lib/sprockets/loader.rb +62 -171
- data/lib/sprockets/unloaded_asset.rb +137 -0
- data/lib/sprockets/uri_tar.rb +76 -0
- data/lib/sprockets/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6633bafc9b6d1b1570fa828078c0b4e60979bfe1
|
4
|
+
data.tar.gz: 804e028afbdb65c793f4f11d8e6af5d2109d55e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef28f9483212866abe219015449ea9e2f277860a8823b01ccc5898f6265848ed67d828bca494b8c8abc366efa74bb5591043eb19f07f47171bb778718c71661e
|
7
|
+
data.tar.gz: e63e469b61325f97a91625197c213ec92aba3e2720027b4070c6ffd0463e5c7d4a1f09ffee2b0cd2b1c4b24d714e724558fe57467e0a73834c78af9ac6e223d1
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
+
**3.3.2** (August 19, 2015)
|
2
|
+
|
3
|
+
* Fix cache contents to use relative paths instead of absolute paths.
|
4
|
+
|
1
5
|
**3.3.1** (August 15, 2015)
|
2
6
|
|
3
7
|
* Fix legacy Tilt integration when locals is required argument.
|
4
8
|
|
5
9
|
**3.3.0** (August 12, 2015)
|
6
10
|
|
7
|
-
* Change internal cache
|
11
|
+
* Change internal cache key to use relative asset paths instead of absolute paths.
|
8
12
|
|
9
13
|
**3.2.0** (June 2, 2015)
|
10
14
|
|
data/lib/sprockets.rb
CHANGED
@@ -144,7 +144,7 @@ module Sprockets
|
|
144
144
|
env.version
|
145
145
|
end
|
146
146
|
register_dependency_resolver 'environment-paths' do |env|
|
147
|
-
env.paths
|
147
|
+
env.paths.map {|path| env.compress_from_root(path) }
|
148
148
|
end
|
149
149
|
register_dependency_resolver 'file-digest' do |env, str|
|
150
150
|
env.file_digest(env.parse_file_digest_uri(str))
|
data/lib/sprockets/base.rb
CHANGED
@@ -11,6 +11,7 @@ require 'sprockets/path_utils'
|
|
11
11
|
require 'sprockets/resolve'
|
12
12
|
require 'sprockets/server'
|
13
13
|
require 'sprockets/loader'
|
14
|
+
require 'sprockets/uri_tar'
|
14
15
|
|
15
16
|
module Sprockets
|
16
17
|
# `Base` class for `Environment` and `Cached`.
|
@@ -97,5 +98,13 @@ module Sprockets
|
|
97
98
|
"root=#{root.to_s.inspect}, " +
|
98
99
|
"paths=#{paths.inspect}>"
|
99
100
|
end
|
101
|
+
|
102
|
+
def compress_from_root(uri)
|
103
|
+
URITar.new(uri, self).compress
|
104
|
+
end
|
105
|
+
|
106
|
+
def expand_from_root(uri)
|
107
|
+
URITar.new(uri, self).expand
|
108
|
+
end
|
100
109
|
end
|
101
110
|
end
|
data/lib/sprockets/loader.rb
CHANGED
@@ -10,156 +10,10 @@ require 'sprockets/processor_utils'
|
|
10
10
|
require 'sprockets/resolve'
|
11
11
|
require 'sprockets/transformers'
|
12
12
|
require 'sprockets/uri_utils'
|
13
|
+
require 'sprockets/unloaded_asset'
|
13
14
|
|
14
15
|
module Sprockets
|
15
16
|
|
16
|
-
# Internal: Used to parse and store the URI to an unloaded asset
|
17
|
-
# Generates keys used to store and retrieve items from cache
|
18
|
-
class UnloadedAsset
|
19
|
-
|
20
|
-
# Internal: Initialize object for generating cache keys
|
21
|
-
#
|
22
|
-
# uri - A String containing complete URI to a file including schema
|
23
|
-
# and full path such as
|
24
|
-
# "file:///Path/app/assets/js/app.js?type=application/javascript"
|
25
|
-
# env - The current "environment" that assets are being loaded into.
|
26
|
-
# We need it so we know where the +root+ (directory where sprockets
|
27
|
-
# is being invoked). We also need for the `file_digest` method,
|
28
|
-
# since, for some strange reason, memoization is provided by
|
29
|
-
# overriding methods such as `stat` in the `PathUtils` module.
|
30
|
-
#
|
31
|
-
# Returns UnloadedAsset.
|
32
|
-
def initialize(uri, env)
|
33
|
-
@uri = uri
|
34
|
-
@env = env
|
35
|
-
@root = env.root
|
36
|
-
@relative_path = get_relative_path_from_uri
|
37
|
-
@params = nil # lazy loaded
|
38
|
-
@filename = nil # lazy loaded
|
39
|
-
end
|
40
|
-
attr_reader :relative_path, :root, :uri
|
41
|
-
|
42
|
-
|
43
|
-
# Internal: Full file path without schema
|
44
|
-
#
|
45
|
-
# This returns a string containing the full path to the asset without the schema.
|
46
|
-
# Information is loaded lazilly since we want `UnloadedAsset.new(dep, self).relative_path`
|
47
|
-
# to be fast. Calling this method the first time allocates an array and a hash.
|
48
|
-
#
|
49
|
-
# Example
|
50
|
-
#
|
51
|
-
# If the URI is `file:///Full/path/app/assets/javascripts/application.js"` then the
|
52
|
-
# filename would be `"/Full/path/app/assets/javascripts/application.js"`
|
53
|
-
#
|
54
|
-
# Returns a String.
|
55
|
-
def filename
|
56
|
-
unless @filename
|
57
|
-
load_file_params
|
58
|
-
end
|
59
|
-
@filename
|
60
|
-
end
|
61
|
-
|
62
|
-
# Internal: Hash of param values
|
63
|
-
#
|
64
|
-
# This information is generated and used internally by sprockets.
|
65
|
-
# Known keys include `:type` which store the asset's mime-type, `:id` which is a fully resolved
|
66
|
-
# digest for the asset (includes dependency digest as opposed to a digest of only file contents)
|
67
|
-
# and `:pipeline`. Hash may be empty.
|
68
|
-
#
|
69
|
-
# Example
|
70
|
-
#
|
71
|
-
# If the URI is `file:///Full/path/app/assets/javascripts/application.js"type=application/javascript`
|
72
|
-
# Then the params would be `{type: "application/javascript"}`
|
73
|
-
#
|
74
|
-
# Returns a Hash.
|
75
|
-
def params
|
76
|
-
unless @params
|
77
|
-
load_file_params
|
78
|
-
end
|
79
|
-
@params
|
80
|
-
end
|
81
|
-
|
82
|
-
# Internal: Key of asset
|
83
|
-
#
|
84
|
-
# Used to retrieve an asset from the cache based on relative path to asset
|
85
|
-
#
|
86
|
-
# Returns a String.
|
87
|
-
def asset_key
|
88
|
-
"asset-uri:#{relative_path}"
|
89
|
-
end
|
90
|
-
|
91
|
-
# Public: Dependency History key
|
92
|
-
#
|
93
|
-
# Used to retrieve an array of "histories" each of which contain a set of stored dependencies
|
94
|
-
# for a given asset path and filename digest.
|
95
|
-
#
|
96
|
-
# A dependency can refer to either an asset i.e. index.js
|
97
|
-
# may rely on jquery.js (so jquery.js is a dependency), or other factors that may affect
|
98
|
-
# compilation, such as the VERSION of sprockets (i.e. the environment) and what "processors"
|
99
|
-
# are used.
|
100
|
-
#
|
101
|
-
# For example a history array with one Set of dependencies may look like:
|
102
|
-
#
|
103
|
-
# [["environment-version", "environment-paths", "processors:type=text/css&file_type=text/css",
|
104
|
-
# "file-digest:///Full/path/app/assets/stylesheets/application.css",
|
105
|
-
# "processors:type=text/css&file_type=text/css&pipeline=self",
|
106
|
-
# "file-digest:///Full/path/app/assets/stylesheets"]]
|
107
|
-
#
|
108
|
-
# This method of asset lookup is used to ensure that none of the dependencies have been modified
|
109
|
-
# since last lookup. If one of them has, the key will be different and a new entry must be stored.
|
110
|
-
#
|
111
|
-
# URI depndencies are later converted to relative paths
|
112
|
-
#
|
113
|
-
# Returns a String.
|
114
|
-
def dependency_history_key
|
115
|
-
"asset-uri-cache-dependencies:#{relative_path}:#{ @env.file_digest(filename) }"
|
116
|
-
end
|
117
|
-
|
118
|
-
# Internal: Digest key
|
119
|
-
#
|
120
|
-
# Used to retrieve a string containing the relative path to an asset based on
|
121
|
-
# a digest. The digest is generated from dependencies stored via information stored in
|
122
|
-
# the `dependency_history_key` after each of the "dependencies" is "resolved" for example
|
123
|
-
# "environment-version" may be resolved to "environment-1.0-3.2.0" for version "3.2.0" of sprockets
|
124
|
-
#
|
125
|
-
# Returns a String.
|
126
|
-
def digest_key(digest)
|
127
|
-
"asset-uri-digest:#{relative_path}:#{digest}"
|
128
|
-
end
|
129
|
-
|
130
|
-
# Internal: File digest key
|
131
|
-
#
|
132
|
-
# The digest for a given file won't change if the path and the stat time hasn't changed
|
133
|
-
# We can save time by not re-computing this information and storing it in the cache
|
134
|
-
#
|
135
|
-
# Returns a String.
|
136
|
-
def file_digest_key(stat)
|
137
|
-
"file_digest:#{relative_path}:#{stat}"
|
138
|
-
end
|
139
|
-
|
140
|
-
private
|
141
|
-
# Internal: Parses uri into filename and params hash
|
142
|
-
#
|
143
|
-
# Returns Array with filename and params hash
|
144
|
-
def load_file_params
|
145
|
-
@filename, @params = URIUtils.parse_asset_uri(uri)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Internal: Converts uri to a relative path
|
149
|
-
#
|
150
|
-
# Returns a relative path if given URI is in the `@env.root` of where sprockets
|
151
|
-
# is running. Otherwise it returns a string of the absolute path
|
152
|
-
#
|
153
|
-
# Returns a String.
|
154
|
-
def get_relative_path_from_uri
|
155
|
-
path = uri.sub(/\Afile:\/\//, "".freeze)
|
156
|
-
if relative_path = PathUtils.split_subpath(root, path)
|
157
|
-
relative_path
|
158
|
-
else
|
159
|
-
path
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
17
|
# The loader phase takes a asset URI location and returns a constructed Asset
|
164
18
|
# object.
|
165
19
|
module Loader
|
@@ -178,7 +32,7 @@ module Sprockets
|
|
178
32
|
def load(uri)
|
179
33
|
unloaded = UnloadedAsset.new(uri, self)
|
180
34
|
if unloaded.params.key?(:id)
|
181
|
-
unless asset =
|
35
|
+
unless asset = asset_from_cache(unloaded.asset_key)
|
182
36
|
id = unloaded.params.delete(:id)
|
183
37
|
uri_without_id = build_asset_uri(unloaded.filename, unloaded.params)
|
184
38
|
asset = load_from_unloaded(UnloadedAsset.new(uri_without_id, self))
|
@@ -200,7 +54,7 @@ module Sprockets
|
|
200
54
|
if paths
|
201
55
|
digest = DigestUtils.digest(resolve_dependencies(paths))
|
202
56
|
if uri_from_cache = cache.get(unloaded.digest_key(digest), true)
|
203
|
-
|
57
|
+
asset_from_cache(UnloadedAsset.new(uri_from_cache, self).asset_key)
|
204
58
|
end
|
205
59
|
else
|
206
60
|
load_from_unloaded(unloaded)
|
@@ -212,6 +66,24 @@ module Sprockets
|
|
212
66
|
|
213
67
|
private
|
214
68
|
|
69
|
+
# Internal: Load asset hash from cache
|
70
|
+
#
|
71
|
+
# key - A String containing lookup information for an asset
|
72
|
+
#
|
73
|
+
# This method converts all "compressed" paths to absolute paths.
|
74
|
+
# Returns a hash of values representing an asset
|
75
|
+
def asset_from_cache(key)
|
76
|
+
asset = cache.get(key, true)
|
77
|
+
if asset
|
78
|
+
asset[:uri] = expand_from_root(asset[:uri])
|
79
|
+
asset[:load_path] = expand_from_root(asset[:load_path])
|
80
|
+
asset[:filename] = expand_from_root(asset[:filename])
|
81
|
+
asset[:metadata][:included].map! { |uri| expand_from_root(uri) } if asset[:metadata][:included]
|
82
|
+
asset[:metadata][:dependencies].map! { |uri| uri.start_with?("file-digest://") ? expand_from_root(uri) : uri } if asset[:metadata][:dependencies]
|
83
|
+
end
|
84
|
+
asset
|
85
|
+
end
|
86
|
+
|
215
87
|
# Internal: Loads an asset and saves it to cache
|
216
88
|
#
|
217
89
|
# unloaded - An UnloadedAsset
|
@@ -303,16 +175,46 @@ module Sprockets
|
|
303
175
|
}.compact.max
|
304
176
|
asset[:mtime] ||= self.stat(unloaded.filename).mtime.to_i
|
305
177
|
|
306
|
-
|
307
|
-
|
178
|
+
store_asset(asset, unloaded)
|
179
|
+
asset
|
180
|
+
end
|
308
181
|
|
182
|
+
# Internal: Save a given asset to the cache
|
183
|
+
#
|
184
|
+
# asset - A hash containing values of loaded asset
|
185
|
+
# unloaded - The UnloadedAsset used to lookup the `asset`
|
186
|
+
#
|
187
|
+
# This method converts all absolute paths to "compressed" paths
|
188
|
+
# which are relative if they're in the root.
|
189
|
+
def store_asset(asset, unloaded)
|
309
190
|
# Save the asset in the cache under the new URI
|
310
|
-
|
191
|
+
cached_asset = asset.dup
|
192
|
+
cached_asset[:uri] = compress_from_root(asset[:uri])
|
193
|
+
cached_asset[:filename] = compress_from_root(asset[:filename])
|
194
|
+
cached_asset[:load_path] = compress_from_root(asset[:load_path])
|
195
|
+
|
196
|
+
if cached_asset[:metadata]
|
197
|
+
# Deep dup to avoid modifying `asset`
|
198
|
+
cached_asset[:metadata] = cached_asset[:metadata].dup
|
199
|
+
if cached_asset[:metadata][:included]
|
200
|
+
cached_asset[:metadata][:included] = cached_asset[:metadata][:included].dup
|
201
|
+
cached_asset[:metadata][:included] = cached_asset[:metadata][:included].map {|uri| compress_from_root(uri) }
|
202
|
+
end
|
311
203
|
|
312
|
-
|
313
|
-
|
204
|
+
if cached_asset[:metadata][:dependencies]
|
205
|
+
cached_asset[:metadata][:dependencies] = cached_asset[:metadata][:dependencies].dup
|
206
|
+
cached_asset[:metadata][:dependencies].map! do |uri|
|
207
|
+
uri.start_with?("file-digest://".freeze) ? compress_from_root(uri) : uri
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
314
211
|
|
315
|
-
asset
|
212
|
+
# Unloaded asset and stored_asset now have a different URI
|
213
|
+
stored_asset = UnloadedAsset.new(asset[:uri], self)
|
214
|
+
cache.set(stored_asset.asset_key, cached_asset, true)
|
215
|
+
|
216
|
+
# Save the new relative path for the digest key of the unloaded asset
|
217
|
+
cache.set(unloaded.digest_key(asset[:dependencies_digest]), stored_asset.compressed_path, true)
|
316
218
|
end
|
317
219
|
|
318
220
|
|
@@ -334,21 +236,7 @@ module Sprockets
|
|
334
236
|
#
|
335
237
|
# Returns array of resolved dependencies
|
336
238
|
def resolve_dependencies(uris)
|
337
|
-
uris.map
|
338
|
-
dependency = resolve_dependency(uri)
|
339
|
-
case dependency
|
340
|
-
when Array
|
341
|
-
dependency.map do |dep|
|
342
|
-
if dep && dep.is_a?(String)
|
343
|
-
UnloadedAsset.new(dep, self).relative_path
|
344
|
-
else
|
345
|
-
dep
|
346
|
-
end
|
347
|
-
end
|
348
|
-
else
|
349
|
-
dependency
|
350
|
-
end
|
351
|
-
end
|
239
|
+
uris.map { |uri| resolve_dependency(uri) }
|
352
240
|
end
|
353
241
|
|
354
242
|
# Internal: Retrieves an asset based on its digest
|
@@ -388,6 +276,7 @@ module Sprockets
|
|
388
276
|
|
389
277
|
history = cache.get(key) || []
|
390
278
|
history.each_with_index do |deps, index|
|
279
|
+
deps = deps.map { |path| path.start_with?("file-digest://") ? expand_from_root(path) : path }
|
391
280
|
if asset = yield(deps)
|
392
281
|
cache.set(key, history.rotate!(index)) if index > 0
|
393
282
|
return asset
|
@@ -395,7 +284,9 @@ module Sprockets
|
|
395
284
|
end
|
396
285
|
|
397
286
|
asset = yield
|
398
|
-
deps = asset[:metadata][:dependencies]
|
287
|
+
deps = asset[:metadata][:dependencies].map do |uri|
|
288
|
+
uri.start_with?("file-digest://") ? compress_from_root(uri) : uri
|
289
|
+
end
|
399
290
|
cache.set(key, history.unshift(deps).take(limit))
|
400
291
|
asset
|
401
292
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'sprockets/uri_utils'
|
2
|
+
require 'sprockets/uri_tar'
|
3
|
+
|
4
|
+
module Sprockets
|
5
|
+
# Internal: Used to parse and store the URI to an unloaded asset
|
6
|
+
# Generates keys used to store and retrieve items from cache
|
7
|
+
class UnloadedAsset
|
8
|
+
|
9
|
+
# Internal: Initialize object for generating cache keys
|
10
|
+
#
|
11
|
+
# uri - A String containing complete URI to a file including scheme
|
12
|
+
# and full path such as
|
13
|
+
# "file:///Path/app/assets/js/app.js?type=application/javascript"
|
14
|
+
# env - The current "environment" that assets are being loaded into.
|
15
|
+
# We need it so we know where the +root+ (directory where sprockets
|
16
|
+
# is being invoked). We also need for the `file_digest` method,
|
17
|
+
# since, for some strange reason, memoization is provided by
|
18
|
+
# overriding methods such as `stat` in the `PathUtils` module.
|
19
|
+
#
|
20
|
+
# Returns UnloadedAsset.
|
21
|
+
def initialize(uri, env)
|
22
|
+
@uri = uri
|
23
|
+
@env = env
|
24
|
+
@compressed_path = URITar.new(uri, env).compressed_path
|
25
|
+
@params = nil # lazy loaded
|
26
|
+
@filename = nil # lazy loaded
|
27
|
+
end
|
28
|
+
attr_reader :compressed_path, :uri
|
29
|
+
|
30
|
+
# Internal: Full file path without schema
|
31
|
+
#
|
32
|
+
# This returns a string containing the full path to the asset without the schema.
|
33
|
+
# Information is loaded lazilly since we want `UnloadedAsset.new(dep, self).relative_path`
|
34
|
+
# to be fast. Calling this method the first time allocates an array and a hash.
|
35
|
+
#
|
36
|
+
# Example
|
37
|
+
#
|
38
|
+
# If the URI is `file:///Full/path/app/assets/javascripts/application.js"` then the
|
39
|
+
# filename would be `"/Full/path/app/assets/javascripts/application.js"`
|
40
|
+
#
|
41
|
+
# Returns a String.
|
42
|
+
def filename
|
43
|
+
unless @filename
|
44
|
+
load_file_params
|
45
|
+
end
|
46
|
+
@filename
|
47
|
+
end
|
48
|
+
|
49
|
+
# Internal: Hash of param values
|
50
|
+
#
|
51
|
+
# This information is generated and used internally by sprockets.
|
52
|
+
# Known keys include `:type` which store the asset's mime-type, `:id` which is a fully resolved
|
53
|
+
# digest for the asset (includes dependency digest as opposed to a digest of only file contents)
|
54
|
+
# and `:pipeline`. Hash may be empty.
|
55
|
+
#
|
56
|
+
# Example
|
57
|
+
#
|
58
|
+
# If the URI is `file:///Full/path/app/assets/javascripts/application.js"type=application/javascript`
|
59
|
+
# Then the params would be `{type: "application/javascript"}`
|
60
|
+
#
|
61
|
+
# Returns a Hash.
|
62
|
+
def params
|
63
|
+
unless @params
|
64
|
+
load_file_params
|
65
|
+
end
|
66
|
+
@params
|
67
|
+
end
|
68
|
+
|
69
|
+
# Internal: Key of asset
|
70
|
+
#
|
71
|
+
# Used to retrieve an asset from the cache based on "compressed" path to asset.
|
72
|
+
# A "compressed" path can either be relative to the root of the project or an
|
73
|
+
# absolute path.
|
74
|
+
#
|
75
|
+
# Returns a String.
|
76
|
+
def asset_key
|
77
|
+
"asset-uri:#{compressed_path}"
|
78
|
+
end
|
79
|
+
|
80
|
+
# Public: Dependency History key
|
81
|
+
#
|
82
|
+
# Used to retrieve an array of "histories" each of which contain a set of stored dependencies
|
83
|
+
# for a given asset path and filename digest.
|
84
|
+
#
|
85
|
+
# A dependency can refer to either an asset i.e. index.js
|
86
|
+
# may rely on jquery.js (so jquery.js is a dependency), or other factors that may affect
|
87
|
+
# compilation, such as the VERSION of sprockets (i.e. the environment) and what "processors"
|
88
|
+
# are used.
|
89
|
+
#
|
90
|
+
# For example a history array with one Set of dependencies may look like:
|
91
|
+
#
|
92
|
+
# [["environment-version", "environment-paths", "processors:type=text/css&file_type=text/css",
|
93
|
+
# "file-digest:///Full/path/app/assets/stylesheets/application.css",
|
94
|
+
# "processors:type=text/css&file_type=text/css&pipeline=self",
|
95
|
+
# "file-digest:///Full/path/app/assets/stylesheets"]]
|
96
|
+
#
|
97
|
+
# This method of asset lookup is used to ensure that none of the dependencies have been modified
|
98
|
+
# since last lookup. If one of them has, the key will be different and a new entry must be stored.
|
99
|
+
#
|
100
|
+
# URI depndencies are later converted to "compressed" paths
|
101
|
+
#
|
102
|
+
# Returns a String.
|
103
|
+
def dependency_history_key
|
104
|
+
"asset-uri-cache-dependencies:#{compressed_path}:#{ @env.file_digest(filename) }"
|
105
|
+
end
|
106
|
+
|
107
|
+
# Internal: Digest key
|
108
|
+
#
|
109
|
+
# Used to retrieve a string containing the "compressed" path to an asset based on
|
110
|
+
# a digest. The digest is generated from dependencies stored via information stored in
|
111
|
+
# the `dependency_history_key` after each of the "dependencies" is "resolved" for example
|
112
|
+
# "environment-version" may be resolved to "environment-1.0-3.2.0" for version "3.2.0" of sprockets
|
113
|
+
#
|
114
|
+
# Returns a String.
|
115
|
+
def digest_key(digest)
|
116
|
+
"asset-uri-digest:#{compressed_path}:#{digest}"
|
117
|
+
end
|
118
|
+
|
119
|
+
# Internal: File digest key
|
120
|
+
#
|
121
|
+
# The digest for a given file won't change if the path and the stat time hasn't changed
|
122
|
+
# We can save time by not re-computing this information and storing it in the cache
|
123
|
+
#
|
124
|
+
# Returns a String.
|
125
|
+
def file_digest_key(stat)
|
126
|
+
"file_digest:#{compressed_path}:#{stat}"
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
# Internal: Parses uri into filename and params hash
|
131
|
+
#
|
132
|
+
# Returns Array with filename and params hash
|
133
|
+
def load_file_params
|
134
|
+
@filename, @params = URIUtils.parse_asset_uri(uri)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Sprockets
|
2
|
+
# Internal: used to "expand" and "compress" values for storage
|
3
|
+
class URITar
|
4
|
+
attr_reader :scheme, :root, :path
|
5
|
+
|
6
|
+
# Internal: Initialize object for compression or expansion
|
7
|
+
#
|
8
|
+
# uri - A String containing URI that may or may not contain the scheme
|
9
|
+
# env - The current "environment" that assets are being loaded into.
|
10
|
+
def initialize(uri, env)
|
11
|
+
@root = env.root
|
12
|
+
@env = env
|
13
|
+
if uri.include?("://".freeze)
|
14
|
+
uri_array = uri.split("://".freeze)
|
15
|
+
@scheme = uri_array.shift
|
16
|
+
@scheme << "://".freeze
|
17
|
+
@path = uri_array.join("".freeze)
|
18
|
+
else
|
19
|
+
@scheme = "".freeze
|
20
|
+
@path = uri
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Internal: Converts full uri to a "compressed" uri
|
25
|
+
#
|
26
|
+
# If a uri is inside of an environment's root it will
|
27
|
+
# be shortened to be a relative path.
|
28
|
+
#
|
29
|
+
# If a uri is outside of the environment's root the original
|
30
|
+
# uri will be returned.
|
31
|
+
#
|
32
|
+
# Returns String
|
33
|
+
def compress
|
34
|
+
scheme + compressed_path
|
35
|
+
end
|
36
|
+
|
37
|
+
# Internal: Convert a "compressed" uri to an absolute path
|
38
|
+
#
|
39
|
+
# If a uri is inside of the environment's root it will not
|
40
|
+
# start with a slash for example:
|
41
|
+
#
|
42
|
+
# file://this/is/a/relative/path
|
43
|
+
#
|
44
|
+
# If a uri is outside the root, it will start with a slash:
|
45
|
+
#
|
46
|
+
# file:///This/is/an/absolute/path
|
47
|
+
#
|
48
|
+
# Returns String
|
49
|
+
def expand
|
50
|
+
if path.start_with?("/".freeze)
|
51
|
+
# Stored path was absolute, don't add root
|
52
|
+
scheme + path
|
53
|
+
else
|
54
|
+
# Stored path was relative, add root
|
55
|
+
scheme + File.join(root, path)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Internal: Returns "compressed" path
|
60
|
+
#
|
61
|
+
# If the input uri is relative to the environment root
|
62
|
+
# it will return a path relative to the environment root.
|
63
|
+
# Otherwise an absolute path will be returned.
|
64
|
+
#
|
65
|
+
# Only path information is returned, and not scheme.
|
66
|
+
#
|
67
|
+
# Returns String
|
68
|
+
def compressed_path
|
69
|
+
if compressed_path = @env.split_subpath(root, path)
|
70
|
+
compressed_path
|
71
|
+
else
|
72
|
+
path
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/sprockets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-08-
|
12
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -285,6 +285,8 @@ files:
|
|
285
285
|
- lib/sprockets/server.rb
|
286
286
|
- lib/sprockets/transformers.rb
|
287
287
|
- lib/sprockets/uglifier_compressor.rb
|
288
|
+
- lib/sprockets/unloaded_asset.rb
|
289
|
+
- lib/sprockets/uri_tar.rb
|
288
290
|
- lib/sprockets/uri_utils.rb
|
289
291
|
- lib/sprockets/utils.rb
|
290
292
|
- lib/sprockets/version.rb
|
@@ -309,9 +311,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
309
311
|
version: '0'
|
310
312
|
requirements: []
|
311
313
|
rubyforge_project: sprockets
|
312
|
-
rubygems_version: 2.4.
|
314
|
+
rubygems_version: 2.4.5
|
313
315
|
signing_key:
|
314
316
|
specification_version: 4
|
315
317
|
summary: Rack-based asset packaging system
|
316
318
|
test_files: []
|
317
|
-
has_rdoc:
|