sprockets 2.3.2 → 3.0.0
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 +7 -0
- data/LICENSE +2 -2
- data/README.md +332 -115
- data/bin/sprockets +8 -0
- data/lib/rake/sprocketstask.rb +25 -13
- data/lib/sprockets/asset.rb +143 -205
- 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/autoload.rb +11 -0
- data/lib/sprockets/base.rb +49 -257
- data/lib/sprockets/bower.rb +58 -0
- data/lib/sprockets/bundle.rb +65 -0
- data/lib/sprockets/cache/file_store.rb +165 -14
- data/lib/sprockets/cache/memory_store.rb +66 -0
- data/lib/sprockets/cache/null_store.rb +46 -0
- data/lib/sprockets/cache.rb +234 -0
- data/lib/sprockets/cached_environment.rb +69 -0
- data/lib/sprockets/closure_compressor.rb +53 -0
- data/lib/sprockets/coffee_script_processor.rb +25 -0
- data/lib/sprockets/coffee_script_template.rb +6 -0
- data/lib/sprockets/compressing.rb +74 -0
- data/lib/sprockets/configuration.rb +83 -0
- data/lib/sprockets/context.rb +125 -131
- data/lib/sprockets/dependencies.rb +73 -0
- data/lib/sprockets/digest_utils.rb +156 -0
- data/lib/sprockets/directive_processor.rb +209 -211
- data/lib/sprockets/eco_processor.rb +32 -0
- data/lib/sprockets/eco_template.rb +3 -35
- data/lib/sprockets/ejs_processor.rb +31 -0
- data/lib/sprockets/ejs_template.rb +3 -34
- data/lib/sprockets/encoding_utils.rb +258 -0
- data/lib/sprockets/engines.rb +45 -38
- data/lib/sprockets/environment.rb +17 -67
- data/lib/sprockets/erb_processor.rb +30 -0
- data/lib/sprockets/erb_template.rb +6 -0
- data/lib/sprockets/errors.rb +6 -13
- data/lib/sprockets/file_reader.rb +15 -0
- data/lib/sprockets/http_utils.rb +115 -0
- data/lib/sprockets/jst_processor.rb +35 -19
- data/lib/sprockets/legacy.rb +314 -0
- data/lib/sprockets/legacy_proc_processor.rb +35 -0
- data/lib/sprockets/legacy_tilt_processor.rb +29 -0
- data/lib/sprockets/loader.rb +176 -0
- data/lib/sprockets/manifest.rb +179 -98
- data/lib/sprockets/manifest_utils.rb +45 -0
- data/lib/sprockets/mime.rb +114 -32
- data/lib/sprockets/path_dependency_utils.rb +85 -0
- data/lib/sprockets/path_digest_utils.rb +47 -0
- data/lib/sprockets/path_utils.rb +282 -0
- data/lib/sprockets/paths.rb +81 -0
- data/lib/sprockets/processing.rb +157 -189
- data/lib/sprockets/processor_utils.rb +103 -0
- data/lib/sprockets/resolve.rb +208 -0
- data/lib/sprockets/sass_cache_store.rb +19 -15
- data/lib/sprockets/sass_compressor.rb +59 -0
- data/lib/sprockets/sass_functions.rb +2 -0
- data/lib/sprockets/sass_importer.rb +2 -29
- data/lib/sprockets/sass_processor.rb +285 -0
- data/lib/sprockets/sass_template.rb +4 -44
- data/lib/sprockets/server.rb +109 -84
- data/lib/sprockets/transformers.rb +145 -0
- data/lib/sprockets/uglifier_compressor.rb +63 -0
- data/lib/sprockets/uri_utils.rb +190 -0
- data/lib/sprockets/utils.rb +193 -44
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets/yui_compressor.rb +65 -0
- data/lib/sprockets.rb +144 -53
- metadata +248 -238
- data/lib/sprockets/asset_attributes.rb +0 -126
- data/lib/sprockets/bundled_asset.rb +0 -79
- data/lib/sprockets/caching.rb +0 -96
- data/lib/sprockets/charset_normalizer.rb +0 -41
- data/lib/sprockets/index.rb +0 -99
- data/lib/sprockets/processed_asset.rb +0 -152
- data/lib/sprockets/processor.rb +0 -32
- data/lib/sprockets/safety_colons.rb +0 -28
- data/lib/sprockets/scss_template.rb +0 -13
- data/lib/sprockets/static_asset.rb +0 -57
- data/lib/sprockets/trail.rb +0 -90
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 196e262a4bc69c0989859f510f703ccf2b2c16ca
|
4
|
+
data.tar.gz: 8c511861fd25f35955e3f4c748bf97a1ef49dc6b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78fed6b263b253262e03d814f7b1989da90e4c840a7be325a6bae7ff40d58dbc807ae9469f95400ef8fbf33f1ade9746757344a42da29c48dc0a228567337d71
|
7
|
+
data.tar.gz: 1798e1b5216d9c9ed70056b0a828f3ac7a119e0dd2773a590a80dec4b209f93c12eedc7ee7e49b00381df16d91891fc124ca7d0aa59253e9602dc34a398d79ed
|
data/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Copyright (c)
|
2
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2014 Sam Stephenson
|
2
|
+
Copyright (c) 2014 Joshua Peek
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -3,22 +3,28 @@
|
|
3
3
|
Sprockets is a Ruby library for compiling and serving web assets.
|
4
4
|
It features declarative dependency management for JavaScript and CSS
|
5
5
|
assets, as well as a powerful preprocessor pipeline that allows you to
|
6
|
-
write assets in languages like CoffeeScript, Sass
|
6
|
+
write assets in languages like CoffeeScript, Sass and SCSS.
|
7
7
|
|
8
|
-
|
8
|
+
|
9
|
+
## Installation
|
9
10
|
|
10
11
|
Install Sprockets from RubyGems:
|
11
12
|
|
12
|
-
|
13
|
+
``` sh
|
14
|
+
$ gem install sprockets
|
15
|
+
```
|
13
16
|
|
14
17
|
Or include it in your project's `Gemfile` with Bundler:
|
15
18
|
|
16
|
-
|
19
|
+
``` ruby
|
20
|
+
gem 'sprockets', '~> 3.0'
|
21
|
+
```
|
22
|
+
|
17
23
|
|
18
|
-
|
24
|
+
## Understanding the Sprockets Environment
|
19
25
|
|
20
26
|
You'll need an instance of the `Sprockets::Environment` class to
|
21
|
-
access and serve assets from your application. Under Rails
|
27
|
+
access and serve assets from your application. Under Rails 4.0 and
|
22
28
|
later, `YourApp::Application.assets` is a preconfigured
|
23
29
|
`Sprockets::Environment` instance. For Rack-based applications, create
|
24
30
|
an instance in `config.ru`.
|
@@ -28,7 +34,7 @@ assets, manipulating the load path, and registering processors. It is
|
|
28
34
|
also a Rack application that can be mounted at a URL to serve assets
|
29
35
|
over HTTP.
|
30
36
|
|
31
|
-
|
37
|
+
### The Load Path
|
32
38
|
|
33
39
|
The *load path* is an ordered list of directories that Sprockets uses
|
34
40
|
to search for assets.
|
@@ -42,29 +48,31 @@ The power of the load path is that it lets you organize your source
|
|
42
48
|
files into multiple directories -- even directories that live outside
|
43
49
|
your application -- and combine those directories into a single
|
44
50
|
virtual filesystem. That means you can easily bundle JavaScript, CSS
|
45
|
-
and images into a Ruby library and import them into your application.
|
51
|
+
and images into a Ruby library or [Bower](http://bower.io) package and import them into your application.
|
46
52
|
|
47
|
-
|
53
|
+
#### Manipulating the Load Path
|
48
54
|
|
49
55
|
To add a directory to your environment's load path, use the
|
50
56
|
`append_path` and `prepend_path` methods. Directories at the beginning
|
51
57
|
of the load path have precedence over subsequent directories.
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
``` ruby
|
60
|
+
environment = Sprockets::Environment.new
|
61
|
+
environment.append_path 'app/assets/javascripts'
|
62
|
+
environment.append_path 'lib/assets/javascripts'
|
63
|
+
environment.append_path 'vendor/assets/bower_components'
|
64
|
+
```
|
57
65
|
|
58
66
|
In general, you should append to the path by default and reserve
|
59
67
|
prepending for cases where you need to override existing assets.
|
60
68
|
|
61
|
-
|
69
|
+
### Accessing Assets
|
62
70
|
|
63
71
|
Once you've set up your environment's load path, you can mount the
|
64
72
|
environment as a Rack server and request assets via HTTP. You can also
|
65
73
|
access assets programmatically from within your application.
|
66
74
|
|
67
|
-
|
75
|
+
#### Logical Paths
|
68
76
|
|
69
77
|
Assets in Sprockets are always referenced by their *logical path*.
|
70
78
|
|
@@ -90,7 +98,7 @@ contains the directory `app/assets/javascripts`:
|
|
90
98
|
In this way, all directories in the load path are merged to create a
|
91
99
|
virtual filesystem whose entries are logical paths.
|
92
100
|
|
93
|
-
|
101
|
+
#### Serving Assets Over HTTP
|
94
102
|
|
95
103
|
When you mount an environment, all of its assets are accessible as
|
96
104
|
logical paths underneath the *mount point*. For example, if you mount
|
@@ -98,48 +106,57 @@ your environment at `/assets` and request the URL
|
|
98
106
|
`/assets/application.js`, Sprockets will search your load path for the
|
99
107
|
file named `application.js` and serve it.
|
100
108
|
|
101
|
-
Under Rails
|
109
|
+
Under Rails 4.0 and later, your Sprockets environment is automatically
|
102
110
|
mounted at `/assets`. If you are using Sprockets with a Rack
|
103
111
|
application, you will need to mount the environment yourself. A good
|
104
112
|
way to do this is with the `map` method in `config.ru`:
|
105
113
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
114
|
+
``` ruby
|
115
|
+
require 'sprockets'
|
116
|
+
map '/assets' do
|
117
|
+
environment = Sprockets::Environment.new
|
118
|
+
environment.append_path 'app/assets/javascripts'
|
119
|
+
environment.append_path 'app/assets/stylesheets'
|
120
|
+
run environment
|
121
|
+
end
|
113
122
|
|
114
|
-
|
115
|
-
|
116
|
-
|
123
|
+
map '/' do
|
124
|
+
run YourRackApp
|
125
|
+
end
|
126
|
+
```
|
117
127
|
|
118
|
-
|
128
|
+
#### Accessing Assets Programmatically
|
119
129
|
|
120
130
|
You can use the `find_asset` method (aliased as `[]`) to retrieve an
|
121
131
|
asset from a Sprockets environment. Pass it a logical path and you'll
|
122
|
-
get a `Sprockets::
|
132
|
+
get a `Sprockets::Asset` instance back:
|
123
133
|
|
124
|
-
|
125
|
-
|
134
|
+
``` ruby
|
135
|
+
environment['application.js']
|
136
|
+
# => #<Sprockets::Asset ...>
|
137
|
+
```
|
126
138
|
|
127
139
|
Call `to_s` on the resulting asset to access its contents, `length` to
|
128
140
|
get its length in bytes, `mtime` to query its last-modified time, and
|
129
|
-
`
|
141
|
+
`filename` to get its full path on the filesystem.
|
142
|
+
|
130
143
|
|
131
|
-
|
144
|
+
## Using Processors
|
132
145
|
|
133
|
-
Asset source files can be written in another
|
146
|
+
Asset source files can be written in another format, like SCSS or
|
134
147
|
CoffeeScript, and automatically compiled to CSS or JavaScript by
|
135
|
-
Sprockets.
|
148
|
+
Sprockets. Processors that convert a file from one format to another are called *transformers*.
|
136
149
|
|
137
|
-
|
138
|
-
filename. For example, a CSS file written in SCSS might have the name
|
139
|
-
`layout.css.scss`, while a JavaScript file written in CoffeeScript
|
140
|
-
might have the name `dialog.js.coffee`.
|
150
|
+
### Minifying Assets
|
141
151
|
|
142
|
-
|
152
|
+
Several JavaScript and CSS minifiers are available through shorthand.
|
153
|
+
|
154
|
+
``` ruby
|
155
|
+
environment.js_compressor = :uglify
|
156
|
+
environment.css_compressor = :scss
|
157
|
+
```
|
158
|
+
|
159
|
+
### Styling with Sass and SCSS
|
143
160
|
|
144
161
|
[Sass](http://sass-lang.com/) is a language that compiles to CSS and
|
145
162
|
adds features like nested rules, variables, mixins and selector
|
@@ -149,23 +166,10 @@ If the `sass` gem is available to your application, you can use Sass
|
|
149
166
|
to write CSS assets in Sprockets.
|
150
167
|
|
151
168
|
Sprockets supports both Sass syntaxes. For the original
|
152
|
-
whitespace-sensitive syntax, use the extension `.
|
153
|
-
new SCSS syntax, use the extension `.
|
154
|
-
|
155
|
-
## Styling with LESS ##
|
169
|
+
whitespace-sensitive syntax, use the extension `.sass`. For the
|
170
|
+
new SCSS syntax, use the extension `.scss`.
|
156
171
|
|
157
|
-
|
158
|
-
variables, mixins, operations and functions.
|
159
|
-
|
160
|
-
If the `less` gem is available to your application, you can use LESS
|
161
|
-
to write CSS assets in Sprockets. Note that the LESS compiler is
|
162
|
-
written in JavaScript, and at the time of this writing, the `less` gem
|
163
|
-
depends on `therubyracer` which embeds the V8 JavaScript runtime in
|
164
|
-
Ruby.
|
165
|
-
|
166
|
-
To write CSS assets with LESS, use the extension `.css.less`.
|
167
|
-
|
168
|
-
## Scripting with CoffeeScript ##
|
172
|
+
### Scripting with CoffeeScript
|
169
173
|
|
170
174
|
[CoffeeScript](http://jashkenas.github.com/coffee-script/) is a
|
171
175
|
language that compiles to the "good parts" of JavaScript, featuring a
|
@@ -175,13 +179,13 @@ binding.
|
|
175
179
|
If the `coffee-script` gem is available to your application, you can
|
176
180
|
use CoffeeScript to write JavaScript assets in Sprockets. Note that
|
177
181
|
the CoffeeScript compiler is written in JavaScript, and you will need
|
178
|
-
an [ExecJS](https://github.com/
|
182
|
+
an [ExecJS](https://github.com/rails/execjs)-supported runtime
|
179
183
|
on your system to invoke it.
|
180
184
|
|
181
185
|
To write JavaScript assets with CoffeeScript, use the extension
|
182
|
-
`.
|
186
|
+
`.coffee`.
|
183
187
|
|
184
|
-
|
188
|
+
### JavaScript Templating with EJS and Eco
|
185
189
|
|
186
190
|
Sprockets supports *JavaScript templates* for client-side rendering of
|
187
191
|
strings or markup. JavaScript templates have the special format
|
@@ -192,12 +196,14 @@ logical path as a property on the global `JST` object. Invoke a
|
|
192
196
|
template function to render the template as a string. The resulting
|
193
197
|
string can then be inserted into the DOM.
|
194
198
|
|
195
|
-
|
196
|
-
|
199
|
+
```
|
200
|
+
<!-- templates/hello.jst.ejs -->
|
201
|
+
<div>Hello, <span><%= name %></span>!</div>
|
197
202
|
|
198
|
-
|
199
|
-
|
200
|
-
|
203
|
+
// application.js
|
204
|
+
//= require templates/hello
|
205
|
+
$("#hello").html(JST["templates/hello"]({ name: "Sam" }));
|
206
|
+
```
|
201
207
|
|
202
208
|
Sprockets supports two JavaScript template languages:
|
203
209
|
[EJS](https://github.com/sstephenson/ruby-ejs), for embedded
|
@@ -214,17 +220,12 @@ templates have the extension `.jst.eco`. Note that the `eco` gem
|
|
214
220
|
depends on the CoffeeScript compiler, so the same caveats apply as
|
215
221
|
outlined above for the CoffeeScript engine.
|
216
222
|
|
217
|
-
|
223
|
+
### Invoking Ruby with ERB
|
218
224
|
|
219
225
|
Sprockets provides an ERB engine for preprocessing assets using
|
220
226
|
embedded Ruby code. Append `.erb` to a CSS or JavaScript asset's
|
221
227
|
filename to enable the ERB engine.
|
222
228
|
|
223
|
-
**Note**: Sprockets processes multiple engine extensions in order from
|
224
|
-
right to left, so you can use multiple engines with a single
|
225
|
-
asset. For example, to have a CoffeeScript asset that is first
|
226
|
-
preprocessed with ERB, use the extension `.js.coffee.erb`.
|
227
|
-
|
228
229
|
Ruby code embedded in an asset is evaluated in the context of a
|
229
230
|
`Sprockets::Context` instance for the given asset. Common uses for ERB
|
230
231
|
include:
|
@@ -237,16 +238,11 @@ include:
|
|
237
238
|
database, in a JavaScript asset via JSON
|
238
239
|
- embedding version constants loaded from another file
|
239
240
|
|
240
|
-
See the [Helper Methods](
|
241
|
+
See the [Helper Methods](lib/sprockets/context.rb) section for more information about
|
241
242
|
interacting with `Sprockets::Context` instances via ERB.
|
242
243
|
|
243
|
-
### String Interpolation Syntax ###
|
244
|
-
|
245
|
-
If you need access to Ruby from an asset but cannot use ERB's `<% …
|
246
|
-
%>` syntax, Sprockets also supports Ruby string interpolation syntax
|
247
|
-
(`#{ … }`) with the `.str` engine extension.
|
248
244
|
|
249
|
-
|
245
|
+
## Managing and Bundling Dependencies
|
250
246
|
|
251
247
|
You can create *asset bundles* -- ordered concatenations of asset
|
252
248
|
source files -- by specifying dependencies in a special comment syntax
|
@@ -257,16 +253,18 @@ them to recursively build a dependency graph. When you request an
|
|
257
253
|
asset with dependencies, the dependencies will be included in order at
|
258
254
|
the top of the file.
|
259
255
|
|
260
|
-
|
256
|
+
### The Directive Processor
|
261
257
|
|
262
258
|
Sprockets runs the *directive processor* on each CSS and JavaScript
|
263
259
|
source file. The directive processor scans for comment lines beginning
|
264
260
|
with `=` in comment blocks at the top of the file.
|
265
261
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
262
|
+
``` js
|
263
|
+
//= require jquery
|
264
|
+
//= require jquery-ui
|
265
|
+
//= require backbone
|
266
|
+
//= require_tree .
|
267
|
+
```
|
270
268
|
|
271
269
|
The first word immediately following `=` specifies the directive
|
272
270
|
name. Any words following the directive name are treated as
|
@@ -278,21 +276,27 @@ contain spaces, similar to commands in the Unix shell.
|
|
278
276
|
processing. Sprockets will not look for directives in comment blocks
|
279
277
|
that occur after the first line of code.
|
280
278
|
|
281
|
-
|
279
|
+
#### Supported Comment Types
|
282
280
|
|
283
281
|
The directive processor understands comment blocks in three formats:
|
284
282
|
|
285
|
-
|
286
|
-
|
287
|
-
|
283
|
+
``` css
|
284
|
+
/* Multi-line comment blocks (CSS, SCSS, JavaScript)
|
285
|
+
*= require foo
|
286
|
+
*/
|
287
|
+
```
|
288
288
|
|
289
|
-
|
290
|
-
|
289
|
+
``` js
|
290
|
+
// Single-line comment blocks (SCSS, JavaScript)
|
291
|
+
//= require foo
|
292
|
+
```
|
291
293
|
|
292
|
-
|
293
|
-
|
294
|
+
``` coffee
|
295
|
+
# Single-line comment blocks (CoffeeScript)
|
296
|
+
#= require foo
|
297
|
+
```
|
294
298
|
|
295
|
-
|
299
|
+
### Sprockets Directives
|
296
300
|
|
297
301
|
You can use the following directives to declare dependencies in asset
|
298
302
|
source files.
|
@@ -301,65 +305,278 @@ For directives that take a *path* argument, you may specify either a
|
|
301
305
|
logical path or a relative path. Relative paths begin with `./` and
|
302
306
|
reference files relative to the location of the current file.
|
303
307
|
|
304
|
-
|
308
|
+
#### The `require` Directive
|
305
309
|
|
306
310
|
`require` *path* inserts the contents of the asset source file
|
307
311
|
specified by *path*. If the file is required multiple times, it will
|
308
312
|
appear in the bundle only once.
|
309
313
|
|
310
|
-
### The `include` Directive ###
|
311
|
-
|
312
|
-
`include` *path* works like `require`, but inserts the contents of the
|
313
|
-
specified source file even if it has already been included or
|
314
|
-
required.
|
315
|
-
|
316
314
|
### The `require_directory` Directive ###
|
317
315
|
|
318
316
|
`require_directory` *path* requires all source files of the same
|
319
317
|
format in the directory specified by *path*. Files are required in
|
320
318
|
alphabetical order.
|
321
319
|
|
322
|
-
|
320
|
+
#### The `require_tree` Directive
|
323
321
|
|
324
322
|
`require_tree` *path* works like `require_directory`, but operates
|
325
323
|
recursively to require all files in all subdirectories of the
|
326
324
|
directory specified by *path*.
|
327
325
|
|
328
|
-
|
326
|
+
#### The `require_self` Directive
|
329
327
|
|
330
328
|
`require_self` tells Sprockets to insert the body of the current
|
331
|
-
source file before any subsequent `require`
|
329
|
+
source file before any subsequent `require` directives.
|
330
|
+
|
331
|
+
#### The `link` Directive
|
332
|
+
|
333
|
+
`link` *path* declares a dependency on the target *path* and adds it to a list
|
334
|
+
of subdependencies to automatically be compiled when the asset is written out to
|
335
|
+
disk.
|
336
|
+
|
337
|
+
For an example, in a CSS file you might reference an external image that always
|
338
|
+
needs to be compiled along with the css file.
|
339
|
+
|
340
|
+
``` css
|
341
|
+
/*= link "logo.png" */
|
342
|
+
.logo {
|
343
|
+
background-image: url(logo.png)
|
344
|
+
}
|
345
|
+
```
|
332
346
|
|
333
|
-
|
347
|
+
However, if you use a `asset-path` or `asset-url` SCSS helper, these links will
|
348
|
+
automatically be defined for you.
|
349
|
+
|
350
|
+
``` css
|
351
|
+
.logo {
|
352
|
+
background-image: asset-url("logo.png")
|
353
|
+
}
|
354
|
+
```
|
355
|
+
|
356
|
+
#### The `depend_on` Directive
|
334
357
|
|
335
358
|
`depend_on` *path* declares a dependency on the given *path* without
|
336
359
|
including it in the bundle. This is useful when you need to expire an
|
337
360
|
asset's cache in response to a change in another file.
|
338
361
|
|
339
|
-
|
362
|
+
#### The `depend_on_asset` Directive
|
363
|
+
|
364
|
+
`depend_on_asset` *path* works like `depend_on`, but operates
|
365
|
+
recursively reading the file and following the directives found. This is automatically implied if you use `link`, so consider if it just makes sense using `link` instead of `depend_on_asset`.
|
366
|
+
|
367
|
+
#### The `stub` Directive
|
340
368
|
|
341
369
|
`stub` *path* allows dependency to be excluded from the asset bundle.
|
342
370
|
The *path* must be a valid asset and may or may not already be part
|
343
|
-
of the bundle.
|
344
|
-
|
371
|
+
of the bundle. `stub` should only be used at the top level bundle, not
|
372
|
+
within any subdependencies.
|
373
|
+
|
345
374
|
|
346
|
-
|
375
|
+
## Processor Interface
|
347
376
|
|
348
|
-
|
377
|
+
Sprockets 2.x was originally design around [Tilt](https://github.com/rtomayko/tilt)'s engine interface. However, starting with 3.x, a new interface has been introduced deprecating Tilt.
|
378
|
+
|
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
|
+
|
381
|
+
Also see [`Sprockets::ProcessorUtils`](https://github.com/rails/sprockets/blob/master/lib/sprockets/processor_utils.rb) for public helper methods.
|
382
|
+
|
383
|
+
### input Hash
|
384
|
+
|
385
|
+
The `input` Hash defines the following public fields.
|
386
|
+
|
387
|
+
* `:data` - String asset contents
|
388
|
+
* `:environment` - Current `Sprockets::Environment` instance.
|
389
|
+
* `:cache` - A `Sprockets::Cache` instance. See [`Sprockets::Cache#fetch`](https://github.com/rails/sprockets/blob/master/lib/sprockets/cache.rb).
|
390
|
+
* `:uri` - String Asset URI.
|
391
|
+
* `:filename` - String full path to original file.
|
392
|
+
* `:load_path` - String current load path for filename.
|
393
|
+
* `:name` - String logical path for filename.
|
394
|
+
* `:content_type` - String content type of the output asset.
|
395
|
+
* `:metadata` - Hash of processor metadata.
|
396
|
+
|
397
|
+
``` ruby
|
398
|
+
def self.call(input)
|
399
|
+
input[:cache].fetch("my:cache:key:v1") do
|
400
|
+
# Remove all semicolons from source
|
401
|
+
input[:data].gsub(";", "")
|
402
|
+
end
|
403
|
+
end
|
404
|
+
```
|
405
|
+
|
406
|
+
### return Hash
|
407
|
+
|
408
|
+
The processor should return metadata `Hash`. With the exception of the `:data` key, the processor can store arbitrary JSON valid values in this Hash. The data will be stored and exposed on `Asset#metadata`.
|
409
|
+
|
410
|
+
The returned `:data` replaces the assets `input[:data]` to the next processor in the chain. Returning a `String` is shorthand for returning `{ data: str }`. And returning `nil` is shorthand for a no-op where the input data is not transformed, `{ data: input[:data] }`.
|
411
|
+
|
412
|
+
### metadata
|
413
|
+
|
414
|
+
The metadata Hash provides an open format for processors to extend the pipeline processor. Internally, built-in processors use it for passing data to each other.
|
415
|
+
|
416
|
+
* `:required` - A `Set` of String Asset URIs that the Bundle processor should concatenate together.
|
417
|
+
* `:stubbed` - A `Set` of String Asset URIs that will be omitted from the `:required` set.
|
418
|
+
* `:links` - A `Set` of String Asset URIs that should be compiled along with this asset.
|
419
|
+
* `:dependencies` - A `Set` of String Cache URIs that should be monitored for caching.
|
420
|
+
|
421
|
+
``` ruby
|
422
|
+
def self.call(input)
|
423
|
+
# Any metadata may start off as nil, so initialize it the value
|
424
|
+
required = Set.new(input[:metadata][:required])
|
425
|
+
|
426
|
+
# Manually add "foo.js" asset uri to our bundle
|
427
|
+
required << input[:environment].resolve("foo.js")
|
428
|
+
|
429
|
+
{ required: required }
|
430
|
+
end
|
431
|
+
```
|
432
|
+
|
433
|
+
|
434
|
+
## Development
|
435
|
+
|
436
|
+
### Contributing
|
349
437
|
|
350
438
|
The Sprockets source code is [hosted on
|
351
|
-
GitHub](https://github.com/
|
439
|
+
GitHub](https://github.com/rails/sprockets). You can check out a
|
352
440
|
copy of the latest code using Git:
|
353
441
|
|
354
|
-
$ git clone https://github.com/
|
442
|
+
$ git clone https://github.com/rails/sprockets
|
355
443
|
|
356
444
|
If you've found a bug or have a question, please open an issue on the
|
357
445
|
[Sprockets issue
|
358
|
-
tracker](https://github.com/
|
446
|
+
tracker](https://github.com/rails/sprockets/issues). Or, clone
|
359
447
|
the Sprockets repository, write a failing test case, fix the bug and
|
360
448
|
submit a pull request.
|
361
449
|
|
362
|
-
|
450
|
+
### Version History
|
451
|
+
|
452
|
+
**3.0.0**
|
453
|
+
|
454
|
+
* New processor API. Tilt interface is deprecated.
|
455
|
+
* Improved file store caching backend.
|
456
|
+
* MIME Types now accept charset custom charset detecters. Improves support for UTF-16/32 files.
|
457
|
+
* Environment#version no longer affects asset digests. Only used for busting the asset cache.
|
458
|
+
* Removed builtin support for LESS.
|
459
|
+
* Removed `//= include` directive support.
|
460
|
+
* Deprecated `BundledAsset#to_a`. Use `BundledAsset#included` to access debugging subcomponents.
|
461
|
+
* Support circular dependencies. For parity with ES6 modules.
|
462
|
+
* Manifest compilation will no longer generate .gz files by default. [Mixing
|
463
|
+
Content-Encoding and ETags is just a bad
|
464
|
+
idea](https://issues.apache.org/bugzilla/show_bug.cgi?id=39727)
|
465
|
+
* Added linked or referenced assets. When an asset is compiled, any of its links will be compiled as well.
|
466
|
+
* Introduce some limitations around enumerating all logical paths. 4.x will deprecate it and favor linked manifests for compliation.
|
467
|
+
* Add Asset integrity attribute for Subresource Integrity
|
468
|
+
* Default digest changed to SHA256. Configuring `digest_class` is deprecated.
|
469
|
+
* Rename `Asset#digest` to `Asset#hexdigest`. `Asset#digest` is deprecated and will
|
470
|
+
return a raw byte String in 4.x.
|
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`
|
473
|
+
|
474
|
+
**2.12.3** (October 28, 2014)
|
475
|
+
|
476
|
+
* Security: Fix directory traversal bug in development mode server.
|
477
|
+
|
478
|
+
**2.12.2** (September 5, 2014)
|
479
|
+
|
480
|
+
* Ensure internal asset lookups calls are still restricted to load paths within
|
481
|
+
asset compiles. Though, you should not depend on internal asset resolves to be
|
482
|
+
completely restricted for security reasons. Assets themselves should be
|
483
|
+
considered full scripting environments with filesystem access.
|
484
|
+
|
485
|
+
**2.12.1** (April 17, 2014)
|
486
|
+
|
487
|
+
* Fix making manifest target directory when its different than the output directory.
|
488
|
+
|
489
|
+
**2.12.0** (March 13, 2014)
|
490
|
+
|
491
|
+
* Avoid context reference in SassImporter hack so its Marshallable. Fixes
|
492
|
+
issues with Sass 3.3.x.
|
493
|
+
|
494
|
+
**2.11.0** (February 19, 2014)
|
495
|
+
|
496
|
+
* Cache store must now be an LRU implementation.
|
497
|
+
* Default digest changed to SHA1. To continue using MD5.
|
498
|
+
`env.digest_class = Digest::MD5`.
|
499
|
+
|
500
|
+
**2.10.0** (May 24, 2013)
|
501
|
+
|
502
|
+
* Support for `bower.json`
|
503
|
+
|
504
|
+
**2.9.3** (April 20, 2013)
|
505
|
+
|
506
|
+
* Fixed sass caching bug
|
507
|
+
|
508
|
+
**2.9.2** (April 8, 2013)
|
509
|
+
|
510
|
+
* Improve file freshness check performance
|
511
|
+
* Directive processor encoding fixes
|
512
|
+
|
513
|
+
**2.9.1** (April 6, 2013)
|
514
|
+
|
515
|
+
* Support for Uglifier 2.x
|
516
|
+
|
517
|
+
**2.9.0** (February 25, 2013)
|
518
|
+
|
519
|
+
* Write out gzipped variants of bundled assets.
|
520
|
+
|
521
|
+
**2.8.2** (December 10, 2012)
|
522
|
+
|
523
|
+
* Fixed top level Sass constant references
|
524
|
+
* Fixed manifest logger when environment is disabled
|
525
|
+
|
526
|
+
**2.8.1** (October 31, 2012)
|
527
|
+
|
528
|
+
* Fixed Sass importer bug
|
529
|
+
|
530
|
+
**2.8.0** (October 16, 2012)
|
531
|
+
|
532
|
+
* Allow manifest location to be separated from output directory
|
533
|
+
* Pass logical path and absolute path to each_logical_path iterator
|
534
|
+
|
535
|
+
**2.7.0** (October 10, 2012)
|
536
|
+
|
537
|
+
* Added --css-compressor and --js-compressor command line flags
|
538
|
+
* Added css/js compressor shorthand
|
539
|
+
* Change default manifest.json filename to be a randomized manifest-16HEXBYTES.json
|
540
|
+
* Allow nil environment to be passed to manifest
|
541
|
+
* Allow manifest instance to be set on rake task
|
542
|
+
|
543
|
+
**2.6.0** (September 19, 2012)
|
544
|
+
|
545
|
+
* Added bower component.json require support
|
546
|
+
|
547
|
+
**2.5.0** (September 4, 2012)
|
548
|
+
|
549
|
+
* Fixed Ruby 2.0 RegExp warning
|
550
|
+
* Provide stubbed implementation of context *_path helpers
|
551
|
+
* Add SassCompressor
|
552
|
+
|
553
|
+
**2.4.5** (July 10, 2012)
|
554
|
+
|
555
|
+
* Tweaked some logger levels
|
556
|
+
|
557
|
+
**2.4.4** (July 2, 2012)
|
558
|
+
|
559
|
+
* Canonicalize logical path extensions
|
560
|
+
* Check absolute paths passed to depend_on
|
561
|
+
|
562
|
+
**2.4.3** (May 16, 2012)
|
563
|
+
|
564
|
+
* Exposed :sprockets in sass options
|
565
|
+
* Include dependency paths in asset mtime
|
566
|
+
|
567
|
+
**2.4.2** (May 7, 2012)
|
568
|
+
|
569
|
+
* Fixed MultiJson feature detect
|
570
|
+
|
571
|
+
**2.4.1** (April 26, 2012)
|
572
|
+
|
573
|
+
* Fixed MultiJson API change
|
574
|
+
* Fixed gzip mtime
|
575
|
+
|
576
|
+
**2.4.0** (March 27, 2012)
|
577
|
+
|
578
|
+
* Added global path registry
|
579
|
+
* Added global processor registry
|
363
580
|
|
364
581
|
**2.3.2** (March 26, 2012)
|
365
582
|
|
@@ -385,7 +602,7 @@ submit a pull request.
|
|
385
602
|
|
386
603
|
**2.1.2** (November 20, 2011)
|
387
604
|
|
388
|
-
* Disabled If-Modified-Since server checks. Fixes some browser caching issues when serving the asset body only. If-None-Match caching is
|
605
|
+
* Disabled If-Modified-Since server checks. Fixes some browser caching issues when serving the asset body only. If-None-Match caching is sufficient.
|
389
606
|
|
390
607
|
**2.1.1** (November 18, 2011)
|
391
608
|
|
@@ -416,11 +633,11 @@ submit a pull request.
|
|
416
633
|
|
417
634
|
* Initial public release.
|
418
635
|
|
419
|
-
|
636
|
+
## License
|
420
637
|
|
421
|
-
Copyright ©
|
638
|
+
Copyright © 2014 Sam Stephenson <<sstephenson@gmail.com>>
|
422
639
|
|
423
|
-
Copyright ©
|
640
|
+
Copyright © 2014 Joshua Peek <<josh@joshpeek.com>>
|
424
641
|
|
425
642
|
Sprockets is distributed under an MIT-style license. See LICENSE for
|
426
643
|
details.
|