sprockets 3.0.0.beta.8 → 3.0.0.beta.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/lib/sprockets.rb +39 -15
- data/lib/sprockets/autoload.rb +11 -0
- data/lib/sprockets/autoload/closure.rb +7 -0
- data/lib/sprockets/autoload/coffee_script.rb +7 -0
- data/lib/sprockets/autoload/eco.rb +7 -0
- data/lib/sprockets/autoload/ejs.rb +7 -0
- data/lib/sprockets/autoload/sass.rb +7 -0
- data/lib/sprockets/autoload/uglifier.rb +7 -0
- data/lib/sprockets/autoload/yui.rb +7 -0
- data/lib/sprockets/bundle.rb +33 -3
- data/lib/sprockets/cache.rb +15 -6
- data/lib/sprockets/closure_compressor.rb +3 -5
- data/lib/sprockets/coffee_script_processor.rb +2 -5
- data/lib/sprockets/compressing.rb +2 -2
- data/lib/sprockets/context.rb +2 -2
- data/lib/sprockets/dependencies.rb +1 -1
- data/lib/sprockets/directive_processor.rb +3 -3
- data/lib/sprockets/eco_processor.rb +2 -4
- data/lib/sprockets/ejs_processor.rb +1 -3
- data/lib/sprockets/engines.rb +1 -1
- data/lib/sprockets/http_utils.rb +17 -1
- data/lib/sprockets/legacy.rb +3 -2
- data/lib/sprockets/loader.rb +11 -8
- data/lib/sprockets/manifest.rb +27 -17
- data/lib/sprockets/manifest_utils.rb +45 -0
- data/lib/sprockets/mime.rb +10 -7
- data/lib/sprockets/paths.rb +2 -2
- data/lib/sprockets/processing.rb +35 -52
- data/lib/sprockets/processor_utils.rb +34 -28
- data/lib/sprockets/resolve.rb +35 -25
- data/lib/sprockets/sass_cache_store.rb +29 -2
- data/lib/sprockets/sass_compressor.rb +3 -5
- data/lib/sprockets/sass_processor.rb +11 -32
- data/lib/sprockets/server.rb +4 -4
- data/lib/sprockets/transformers.rb +1 -1
- data/lib/sprockets/uglifier_compressor.rb +3 -5
- data/lib/sprockets/uri_utils.rb +3 -3
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets/yui_compressor.rb +3 -5
- metadata +12 -4
- data/lib/sprockets/autoload_processor.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da01c3bbf8752fe3705b073775d7067b1a984239
|
4
|
+
data.tar.gz: 934f3ea753eba823e957005907d594771d053ec2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86023eba8d65c22262182f2602b8c22a6347a634bf894cc969d4d5e7bf94a75198ea4034a3cad71f80c4bfb4ea46cf7bcdf2cad5f1dcdc1877589c9b1a967589
|
7
|
+
data.tar.gz: af13b0c540e0e78f0fa36a567aa2aa98f50680f20468c9d3d8433563f0d16c21d19279e3cac3b6369d532104cecb667a48cf9c6d150061cea41c86bfccb35465
|
data/README.md
CHANGED
@@ -179,7 +179,7 @@ binding.
|
|
179
179
|
If the `coffee-script` gem is available to your application, you can
|
180
180
|
use CoffeeScript to write JavaScript assets in Sprockets. Note that
|
181
181
|
the CoffeeScript compiler is written in JavaScript, and you will need
|
182
|
-
an [ExecJS](https://github.com/
|
182
|
+
an [ExecJS](https://github.com/rails/execjs)-supported runtime
|
183
183
|
on your system to invoke it.
|
184
184
|
|
185
185
|
To write JavaScript assets with CoffeeScript, use the extension
|
@@ -378,7 +378,7 @@ Sprockets 2.x was originally design around [Tilt](https://github.com/rtomayko/ti
|
|
378
378
|
|
379
379
|
Similar to Rack, a processor is a any "callable" (an object that responds to `call`). This maybe a simple Proc or a full class that defines a `def self.call(input)` method. The `call` method accepts an `input` Hash and returns a Hash of metadata.
|
380
380
|
|
381
|
-
Also see [`Sprockets::ProcessorUtils`](https://github.com/
|
381
|
+
Also see [`Sprockets::ProcessorUtils`](https://github.com/rails/sprockets/blob/master/lib/sprockets/processor_utils.rb) for public helper methods.
|
382
382
|
|
383
383
|
### input Hash
|
384
384
|
|
@@ -386,7 +386,7 @@ The `input` Hash defines the following public fields.
|
|
386
386
|
|
387
387
|
* `:data` - String asset contents
|
388
388
|
* `:environment` - Current `Sprockets::Environment` instance.
|
389
|
-
* `:cache` - A `Sprockets::Cache` instance. See [`Sprockets::Cache#fetch`](https://github.com/
|
389
|
+
* `:cache` - A `Sprockets::Cache` instance. See [`Sprockets::Cache#fetch`](https://github.com/rails/sprockets/blob/master/lib/sprockets/cache.rb).
|
390
390
|
* `:uri` - String Asset URI.
|
391
391
|
* `:filename` - String full path to original file.
|
392
392
|
* `:load_path` - String current load path for filename.
|
@@ -436,14 +436,14 @@ end
|
|
436
436
|
### Contributing
|
437
437
|
|
438
438
|
The Sprockets source code is [hosted on
|
439
|
-
GitHub](https://github.com/
|
439
|
+
GitHub](https://github.com/rails/sprockets). You can check out a
|
440
440
|
copy of the latest code using Git:
|
441
441
|
|
442
|
-
$ git clone https://github.com/
|
442
|
+
$ git clone https://github.com/rails/sprockets
|
443
443
|
|
444
444
|
If you've found a bug or have a question, please open an issue on the
|
445
445
|
[Sprockets issue
|
446
|
-
tracker](https://github.com/
|
446
|
+
tracker](https://github.com/rails/sprockets/issues). Or, clone
|
447
447
|
the Sprockets repository, write a failing test case, fix the bug and
|
448
448
|
submit a pull request.
|
449
449
|
|
@@ -469,6 +469,7 @@ submit a pull request.
|
|
469
469
|
* Rename `Asset#digest` to `Asset#hexdigest`. `Asset#digest` is deprecated and will
|
470
470
|
return a raw byte String in 4.x.
|
471
471
|
* Added transitional compatibility flag to `Environment#resolve(path, compat: true)`. 2.x mode operates with `compat: true` and 4.x with `compat: false`
|
472
|
+
* `manifest-abc123.json` renamed to `.sprockets-abc123.json`
|
472
473
|
|
473
474
|
**2.12.3** (October 28, 2014)
|
474
475
|
|
data/lib/sprockets.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sprockets/version'
|
2
|
+
require 'sprockets/autoload'
|
2
3
|
|
3
4
|
module Sprockets
|
4
5
|
# Environment
|
@@ -10,7 +11,6 @@ module Sprockets
|
|
10
11
|
|
11
12
|
# Processing
|
12
13
|
autoload :Bundle, 'sprockets/bundle'
|
13
|
-
autoload :CoffeeScriptTemplate, 'sprockets/coffee_script_template'
|
14
14
|
autoload :Context, 'sprockets/context'
|
15
15
|
autoload :DirectiveProcessor, 'sprockets/directive_processor'
|
16
16
|
autoload :FileReader, 'sprockets/file_reader'
|
@@ -48,6 +48,7 @@ module Sprockets
|
|
48
48
|
mime_exts: {}.freeze,
|
49
49
|
mime_types: {}.freeze,
|
50
50
|
paths: [].freeze,
|
51
|
+
pipelines: {}.freeze,
|
51
52
|
postprocessors: Hash.new { |h, k| [].freeze }.freeze,
|
52
53
|
preprocessors: Hash.new { |h, k| [].freeze }.freeze,
|
53
54
|
registered_transformers: Hash.new { |h, k| {}.freeze }.freeze,
|
@@ -97,6 +98,18 @@ module Sprockets
|
|
97
98
|
register_mime_type 'application/x-font-ttf', extensions: ['.ttf']
|
98
99
|
register_mime_type 'application/font-woff', extensions: ['.woff']
|
99
100
|
|
101
|
+
register_pipeline :source do |env|
|
102
|
+
[]
|
103
|
+
end
|
104
|
+
|
105
|
+
register_pipeline :self do |env, type, file_type, engine_extnames|
|
106
|
+
env.self_processors_for(type, file_type, engine_extnames)
|
107
|
+
end
|
108
|
+
|
109
|
+
register_pipeline :default do |env, type, file_type, engine_extnames|
|
110
|
+
env.default_processors_for(type, file_type, engine_extnames)
|
111
|
+
end
|
112
|
+
|
100
113
|
require 'sprockets/directive_processor'
|
101
114
|
register_preprocessor 'text/css', DirectiveProcessor.new(
|
102
115
|
comments: ["//", ["/*", "*/"]]
|
@@ -113,28 +126,39 @@ module Sprockets
|
|
113
126
|
register_bundle_metadata_reducer 'application/javascript', :data, Utils.method(:concat_javascript_sources)
|
114
127
|
register_bundle_metadata_reducer '*/*', :links, :+
|
115
128
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
register_compressor '
|
121
|
-
register_compressor '
|
122
|
-
register_compressor '
|
129
|
+
require 'sprockets/closure_compressor'
|
130
|
+
require 'sprockets/sass_compressor'
|
131
|
+
require 'sprockets/uglifier_compressor'
|
132
|
+
require 'sprockets/yui_compressor'
|
133
|
+
register_compressor 'text/css', :sass, SassCompressor
|
134
|
+
register_compressor 'text/css', :scss, SassCompressor
|
135
|
+
register_compressor 'text/css', :yui, YUICompressor
|
136
|
+
register_compressor 'application/javascript', :closure, ClosureCompressor
|
137
|
+
register_compressor 'application/javascript', :uglifier, UglifierCompressor
|
138
|
+
register_compressor 'application/javascript', :uglify, UglifierCompressor
|
139
|
+
register_compressor 'application/javascript', :yui, YUICompressor
|
123
140
|
|
124
141
|
# Mmm, CoffeeScript
|
125
|
-
|
142
|
+
require 'sprockets/coffee_script_processor'
|
143
|
+
register_engine '.coffee', CoffeeScriptProcessor, mime_type: 'application/javascript'
|
126
144
|
|
127
145
|
# JST engines
|
128
|
-
|
129
|
-
|
130
|
-
|
146
|
+
require 'sprockets/eco_processor'
|
147
|
+
require 'sprockets/ejs_processor'
|
148
|
+
require 'sprockets/jst_processor'
|
149
|
+
register_engine '.jst', JstProcessor, mime_type: 'application/javascript'
|
150
|
+
register_engine '.eco', EcoProcessor, mime_type: 'application/javascript'
|
151
|
+
register_engine '.ejs', EjsProcessor, mime_type: 'application/javascript'
|
131
152
|
|
132
153
|
# CSS engines
|
133
|
-
|
134
|
-
register_engine '.
|
154
|
+
require 'sprockets/sass_processor'
|
155
|
+
register_engine '.sass', SassProcessor, mime_type: 'text/css'
|
156
|
+
register_engine '.scss', ScssProcessor, mime_type: 'text/css'
|
157
|
+
register_bundle_metadata_reducer 'text/css', :sass_dependencies, Set.new, :+
|
135
158
|
|
136
159
|
# Other
|
137
|
-
|
160
|
+
require 'sprockets/erb_processor'
|
161
|
+
register_engine '.erb', ERBProcessor, mime_type: 'text/plain'
|
138
162
|
|
139
163
|
register_dependency_resolver 'environment-version' do |env|
|
140
164
|
env.version
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Autoload
|
3
|
+
autoload :Closure, 'sprockets/autoload/closure'
|
4
|
+
autoload :CoffeeScript, 'sprockets/autoload/coffee_script'
|
5
|
+
autoload :Eco, 'sprockets/autoload/eco'
|
6
|
+
autoload :EJS, 'sprockets/autoload/ejs'
|
7
|
+
autoload :Sass, 'sprockets/autoload/sass'
|
8
|
+
autoload :Uglifier, 'sprockets/autoload/uglifier'
|
9
|
+
autoload :YUI, 'sprockets/autoload/yui'
|
10
|
+
end
|
11
|
+
end
|
data/lib/sprockets/bundle.rb
CHANGED
@@ -15,8 +15,10 @@ module Sprockets
|
|
15
15
|
def self.call(input)
|
16
16
|
env = input[:environment]
|
17
17
|
type = input[:content_type]
|
18
|
+
dependencies = Set.new(input[:metadata][:dependencies])
|
18
19
|
|
19
|
-
processed_uri = env.
|
20
|
+
processed_uri, deps = env.resolve(input[:filename], accept: type, pipeline: :self, compat: false)
|
21
|
+
dependencies.merge(deps)
|
20
22
|
|
21
23
|
find_required = proc { |uri| env.load(uri).metadata[:required] }
|
22
24
|
required = Utils.dfs(processed_uri, &find_required)
|
@@ -24,12 +26,40 @@ module Sprockets
|
|
24
26
|
required.subtract(stubbed)
|
25
27
|
assets = required.map { |uri| env.load(uri) }
|
26
28
|
|
27
|
-
dependencies = Set.new(input[:metadata][:dependencies])
|
28
29
|
(required + stubbed).each do |uri|
|
29
30
|
dependencies.merge(env.load(uri).metadata[:dependencies])
|
30
31
|
end
|
31
32
|
|
32
|
-
env.
|
33
|
+
reducers = Hash[env.match_mime_type_keys(env.config[:bundle_reducers], type).flat_map(&:to_a)]
|
34
|
+
process_bundle_reducers(assets, reducers).merge(dependencies: dependencies, included: assets.map(&:uri))
|
35
|
+
end
|
36
|
+
|
37
|
+
# Internal: Run bundle reducers on set of Assets producing a reduced
|
38
|
+
# metadata Hash.
|
39
|
+
#
|
40
|
+
# assets - Array of Assets
|
41
|
+
# reducers - Array of [initial, reducer_proc] pairs
|
42
|
+
#
|
43
|
+
# Returns reduced asset metadata Hash.
|
44
|
+
def self.process_bundle_reducers(assets, reducers)
|
45
|
+
initial = {}
|
46
|
+
reducers.each do |k, (v, _)|
|
47
|
+
initial[k] = v if !v.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
assets.reduce(initial) do |h, asset|
|
51
|
+
reducers.each do |k, (_, block)|
|
52
|
+
value = k == :data ? asset.source : asset.metadata[k]
|
53
|
+
if h.key?(k)
|
54
|
+
if !value.nil?
|
55
|
+
h[k] = block.call(h[k], value)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
h[k] = value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
h
|
62
|
+
end
|
33
63
|
end
|
34
64
|
end
|
35
65
|
end
|
data/lib/sprockets/cache.rb
CHANGED
@@ -60,7 +60,7 @@ module Sprockets
|
|
60
60
|
# cache - A compatible backend cache store instance.
|
61
61
|
def initialize(cache = nil, logger = self.class.default_logger)
|
62
62
|
@cache_wrapper = get_cache_wrapper(cache)
|
63
|
-
@fetch_cache = Cache::MemoryStore.new(
|
63
|
+
@fetch_cache = Cache::MemoryStore.new(4096)
|
64
64
|
@logger = logger
|
65
65
|
end
|
66
66
|
|
@@ -107,8 +107,14 @@ module Sprockets
|
|
107
107
|
# Returns a JSON serializable object or nil if there was a cache miss.
|
108
108
|
def get(key, local = false)
|
109
109
|
expanded_key = expand_key(key)
|
110
|
-
|
111
|
-
value = @
|
110
|
+
|
111
|
+
if local && value = @fetch_cache.get(expanded_key)
|
112
|
+
return value
|
113
|
+
end
|
114
|
+
|
115
|
+
value = @cache_wrapper.get(expanded_key)
|
116
|
+
@fetch_cache.set(expanded_key, value) if local
|
117
|
+
|
112
118
|
value
|
113
119
|
end
|
114
120
|
|
@@ -126,7 +132,7 @@ module Sprockets
|
|
126
132
|
# Returns the value argument.
|
127
133
|
def set(key, value, local = false)
|
128
134
|
expanded_key = expand_key(key)
|
129
|
-
@fetch_cache.set(expanded_key, value)
|
135
|
+
@fetch_cache.set(expanded_key, value) if local
|
130
136
|
@cache_wrapper.set(expanded_key, value)
|
131
137
|
end
|
132
138
|
|
@@ -156,9 +162,12 @@ module Sprockets
|
|
156
162
|
#
|
157
163
|
# Returns a String with a length less than 100 characters.
|
158
164
|
def peek_key(key)
|
159
|
-
|
165
|
+
case key
|
166
|
+
when Integer
|
167
|
+
key.to_s
|
168
|
+
when String
|
160
169
|
key[0, PEEK_SIZE].inspect
|
161
|
-
|
170
|
+
when Array
|
162
171
|
str = []
|
163
172
|
key.each { |k| str << peek_key(k) }
|
164
173
|
str.join(':')[0, PEEK_SIZE]
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'closure-compiler'
|
2
|
-
|
3
1
|
module Sprockets
|
4
2
|
# Public: Closure Compiler minifier.
|
5
3
|
#
|
@@ -34,11 +32,11 @@ module Sprockets
|
|
34
32
|
attr_reader :cache_key
|
35
33
|
|
36
34
|
def initialize(options = {})
|
37
|
-
@compiler = ::Closure::Compiler.new(options)
|
35
|
+
@compiler = Autoload::Closure::Compiler.new(options)
|
38
36
|
@cache_key = [
|
39
37
|
self.class.name,
|
40
|
-
::Closure::VERSION,
|
41
|
-
::Closure::COMPILER_VERSION,
|
38
|
+
Autoload::Closure::VERSION,
|
39
|
+
Autoload::Closure::COMPILER_VERSION,
|
42
40
|
VERSION,
|
43
41
|
options
|
44
42
|
].freeze
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'coffee_script'
|
2
|
-
|
3
1
|
module Sprockets
|
4
2
|
# Processor engine class for the CoffeeScript compiler.
|
5
3
|
# Depends on the `coffee-script` and `coffee-script-source` gems.
|
@@ -10,16 +8,15 @@ module Sprockets
|
|
10
8
|
#
|
11
9
|
module CoffeeScriptProcessor
|
12
10
|
VERSION = '1'
|
13
|
-
SOURCE_VERSION = ::CoffeeScript::Source.version
|
14
11
|
|
15
12
|
def self.cache_key
|
16
|
-
@cache_key ||= [name,
|
13
|
+
@cache_key ||= [name, Autoload::CoffeeScript::Source.version, VERSION].freeze
|
17
14
|
end
|
18
15
|
|
19
16
|
def self.call(input)
|
20
17
|
data = input[:data]
|
21
18
|
input[:cache].fetch(self.cache_key + [data]) do
|
22
|
-
::CoffeeScript.compile(data)
|
19
|
+
Autoload::CoffeeScript.compile(data)
|
23
20
|
end
|
24
21
|
end
|
25
22
|
end
|
@@ -33,7 +33,7 @@ module Sprockets
|
|
33
33
|
return unless compressor
|
34
34
|
|
35
35
|
if compressor.is_a?(Symbol)
|
36
|
-
@css_compressor = klass = compressors['text/css'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
36
|
+
@css_compressor = klass = config[:compressors]['text/css'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
37
37
|
elsif compressor.respond_to?(:compress)
|
38
38
|
klass = LegacyProcProcessor.new(:css_compressor, proc { |context, data| compressor.compress(data) })
|
39
39
|
@css_compressor = :css_compressor
|
@@ -60,7 +60,7 @@ module Sprockets
|
|
60
60
|
return unless compressor
|
61
61
|
|
62
62
|
if compressor.is_a?(Symbol)
|
63
|
-
@js_compressor = klass = compressors['application/javascript'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
63
|
+
@js_compressor = klass = config[:compressors]['application/javascript'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
64
64
|
elsif compressor.respond_to?(:compress)
|
65
65
|
klass = LegacyProcProcessor.new(:js_compressor, proc { |context, data| compressor.compress(data) })
|
66
66
|
@js_compressor = :js_compressor
|
data/lib/sprockets/context.rb
CHANGED
@@ -133,7 +133,7 @@ module Sprockets
|
|
133
133
|
# <%= require_asset "#{framework}.js" %>
|
134
134
|
#
|
135
135
|
def require_asset(path)
|
136
|
-
@required << resolve(path, accept: @content_type,
|
136
|
+
@required << resolve(path, accept: @content_type, pipeline: :self, compat: false)
|
137
137
|
nil
|
138
138
|
end
|
139
139
|
|
@@ -141,7 +141,7 @@ module Sprockets
|
|
141
141
|
# `path` must be an asset which may or may not already be included
|
142
142
|
# in the bundle.
|
143
143
|
def stub_asset(path)
|
144
|
-
@stubbed << resolve(path, accept: @content_type,
|
144
|
+
@stubbed << resolve(path, accept: @content_type, pipeline: :self, compat: false)
|
145
145
|
nil
|
146
146
|
end
|
147
147
|
|
@@ -204,7 +204,7 @@ module Sprockets
|
|
204
204
|
# //= require "./bar"
|
205
205
|
#
|
206
206
|
def process_require_directive(path)
|
207
|
-
@required << resolve(path, accept: @content_type,
|
207
|
+
@required << resolve(path, accept: @content_type, pipeline: :self)
|
208
208
|
end
|
209
209
|
|
210
210
|
# `require_self` causes the body of the current file to be inserted
|
@@ -285,7 +285,7 @@ module Sprockets
|
|
285
285
|
# //= stub "jquery"
|
286
286
|
#
|
287
287
|
def process_stub_directive(path)
|
288
|
-
@stubbed << resolve(path, accept: @content_type,
|
288
|
+
@stubbed << resolve(path, accept: @content_type, pipeline: :self)
|
289
289
|
end
|
290
290
|
|
291
291
|
# Declares a linked dependency on the target asset.
|
@@ -347,7 +347,7 @@ module Sprockets
|
|
347
347
|
end
|
348
348
|
|
349
349
|
def require_paths(paths, deps)
|
350
|
-
resolve_paths(paths, deps, accept: @content_type,
|
350
|
+
resolve_paths(paths, deps, accept: @content_type, pipeline: :self) do |uri|
|
351
351
|
@required << uri
|
352
352
|
end
|
353
353
|
end
|