sprockets 2.12.3 → 3.0.0
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.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/README.md +226 -119
- data/lib/rake/sprocketstask.rb +5 -4
- data/lib/sprockets/asset.rb +143 -211
- 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 +47 -395
- 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 +41 -10
- data/lib/sprockets/coffee_script_processor.rb +25 -0
- data/lib/sprockets/coffee_script_template.rb +6 -0
- data/lib/sprockets/compressing.rb +24 -23
- data/lib/sprockets/configuration.rb +83 -0
- data/lib/sprockets/context.rb +84 -144
- data/lib/sprockets/dependencies.rb +73 -0
- data/lib/sprockets/digest_utils.rb +156 -0
- data/lib/sprockets/directive_processor.rb +207 -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 +42 -35
- data/lib/sprockets/environment.rb +17 -64
- data/lib/sprockets/erb_processor.rb +30 -0
- data/lib/sprockets/erb_template.rb +6 -0
- data/lib/sprockets/errors.rb +5 -13
- data/lib/sprockets/file_reader.rb +15 -0
- data/lib/sprockets/http_utils.rb +115 -0
- data/lib/sprockets/jst_processor.rb +35 -15
- 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 +153 -129
- data/lib/sprockets/manifest_utils.rb +45 -0
- data/lib/sprockets/mime.rb +112 -31
- 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 +42 -19
- data/lib/sprockets/processing.rb +168 -126
- data/lib/sprockets/processor_utils.rb +103 -0
- data/lib/sprockets/resolve.rb +208 -0
- data/lib/sprockets/sass_cache_store.rb +18 -18
- data/lib/sprockets/sass_compressor.rb +47 -15
- data/lib/sprockets/sass_functions.rb +2 -70
- data/lib/sprockets/sass_importer.rb +2 -30
- data/lib/sprockets/sass_processor.rb +285 -0
- data/lib/sprockets/sass_template.rb +4 -63
- data/lib/sprockets/server.rb +104 -79
- data/lib/sprockets/transformers.rb +145 -0
- data/lib/sprockets/uglifier_compressor.rb +46 -12
- 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 +49 -11
- data/lib/sprockets.rb +132 -81
- metadata +84 -89
- data/lib/sprockets/asset_attributes.rb +0 -137
- data/lib/sprockets/bundled_asset.rb +0 -78
- data/lib/sprockets/caching.rb +0 -96
- data/lib/sprockets/charset_normalizer.rb +0 -41
- data/lib/sprockets/index.rb +0 -100
- 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 -58
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 196e262a4bc69c0989859f510f703ccf2b2c16ca
|
|
4
|
+
data.tar.gz: 8c511861fd25f35955e3f4c748bf97a1ef49dc6b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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*.
|
|
149
|
+
|
|
150
|
+
### Minifying Assets
|
|
151
|
+
|
|
152
|
+
Several JavaScript and CSS minifiers are available through shorthand.
|
|
136
153
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
``` ruby
|
|
155
|
+
environment.js_compressor = :uglify
|
|
156
|
+
environment.css_compressor = :scss
|
|
157
|
+
```
|
|
141
158
|
|
|
142
|
-
|
|
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 `.
|
|
169
|
+
whitespace-sensitive syntax, use the extension `.sass`. For the
|
|
170
|
+
new SCSS syntax, use the extension `.scss`.
|
|
154
171
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
[LESS](http://lesscss.org/) extends CSS with dynamic behavior such as
|
|
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 the `less` gem (on MRI) uses `therubyracer`
|
|
163
|
-
which embeds the V8 JavaScript runtime in Ruby, while on JRuby you're
|
|
164
|
-
going to need `therubyrhino` gem installed.
|
|
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
244
|
|
|
245
|
-
|
|
246
|
-
%>` syntax, Sprockets also supports Ruby string interpolation syntax
|
|
247
|
-
(`#{ … }`) with the `.str` engine extension.
|
|
248
|
-
|
|
249
|
-
# Managing and Bundling Dependencies #
|
|
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,70 +305,171 @@ 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
|
+
```
|
|
346
|
+
|
|
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
|
+
```
|
|
332
355
|
|
|
333
|
-
|
|
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
|
|
340
363
|
|
|
341
364
|
`depend_on_asset` *path* works like `depend_on`, but operates
|
|
342
|
-
recursively reading the
|
|
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`.
|
|
343
366
|
|
|
344
|
-
|
|
367
|
+
#### The `stub` Directive
|
|
345
368
|
|
|
346
369
|
`stub` *path* allows dependency to be excluded from the asset bundle.
|
|
347
370
|
The *path* must be a valid asset and may or may not already be part
|
|
348
|
-
of the bundle.
|
|
349
|
-
|
|
371
|
+
of the bundle. `stub` should only be used at the top level bundle, not
|
|
372
|
+
within any subdependencies.
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
## Processor Interface
|
|
376
|
+
|
|
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
|
+
|
|
350
433
|
|
|
351
|
-
|
|
434
|
+
## Development
|
|
352
435
|
|
|
353
|
-
|
|
436
|
+
### Contributing
|
|
354
437
|
|
|
355
438
|
The Sprockets source code is [hosted on
|
|
356
|
-
GitHub](https://github.com/
|
|
439
|
+
GitHub](https://github.com/rails/sprockets). You can check out a
|
|
357
440
|
copy of the latest code using Git:
|
|
358
441
|
|
|
359
|
-
$ git clone https://github.com/
|
|
442
|
+
$ git clone https://github.com/rails/sprockets
|
|
360
443
|
|
|
361
444
|
If you've found a bug or have a question, please open an issue on the
|
|
362
445
|
[Sprockets issue
|
|
363
|
-
tracker](https://github.com/
|
|
446
|
+
tracker](https://github.com/rails/sprockets/issues). Or, clone
|
|
364
447
|
the Sprockets repository, write a failing test case, fix the bug and
|
|
365
448
|
submit a pull request.
|
|
366
449
|
|
|
367
|
-
|
|
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`
|
|
368
473
|
|
|
369
474
|
**2.12.3** (October 28, 2014)
|
|
370
475
|
|
|
@@ -388,7 +493,9 @@ submit a pull request.
|
|
|
388
493
|
|
|
389
494
|
**2.11.0** (February 19, 2014)
|
|
390
495
|
|
|
391
|
-
*
|
|
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`.
|
|
392
499
|
|
|
393
500
|
**2.10.0** (May 24, 2013)
|
|
394
501
|
|
|
@@ -422,7 +529,7 @@ submit a pull request.
|
|
|
422
529
|
|
|
423
530
|
**2.8.0** (October 16, 2012)
|
|
424
531
|
|
|
425
|
-
* Allow manifest location to be
|
|
532
|
+
* Allow manifest location to be separated from output directory
|
|
426
533
|
* Pass logical path and absolute path to each_logical_path iterator
|
|
427
534
|
|
|
428
535
|
**2.7.0** (October 10, 2012)
|
|
@@ -495,7 +602,7 @@ submit a pull request.
|
|
|
495
602
|
|
|
496
603
|
**2.1.2** (November 20, 2011)
|
|
497
604
|
|
|
498
|
-
* 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.
|
|
499
606
|
|
|
500
607
|
**2.1.1** (November 18, 2011)
|
|
501
608
|
|
|
@@ -526,11 +633,11 @@ submit a pull request.
|
|
|
526
633
|
|
|
527
634
|
* Initial public release.
|
|
528
635
|
|
|
529
|
-
|
|
636
|
+
## License
|
|
530
637
|
|
|
531
|
-
Copyright ©
|
|
638
|
+
Copyright © 2014 Sam Stephenson <<sstephenson@gmail.com>>
|
|
532
639
|
|
|
533
|
-
Copyright ©
|
|
640
|
+
Copyright © 2014 Joshua Peek <<josh@joshpeek.com>>
|
|
534
641
|
|
|
535
642
|
Sprockets is distributed under an MIT-style license. See LICENSE for
|
|
536
643
|
details.
|
data/lib/rake/sprocketstask.rb
CHANGED
|
@@ -37,10 +37,11 @@ module Rake
|
|
|
37
37
|
end
|
|
38
38
|
attr_writer :environment
|
|
39
39
|
|
|
40
|
-
# Returns cached
|
|
41
|
-
def
|
|
42
|
-
@
|
|
40
|
+
# Returns cached cached environment
|
|
41
|
+
def cached
|
|
42
|
+
@cached ||= environment.cached if environment
|
|
43
43
|
end
|
|
44
|
+
alias_method :index, :cached
|
|
44
45
|
|
|
45
46
|
# `Manifest` instance used for already compiled assets.
|
|
46
47
|
#
|
|
@@ -97,7 +98,7 @@ module Rake
|
|
|
97
98
|
def initialize(name = :assets)
|
|
98
99
|
@name = name
|
|
99
100
|
@environment = lambda { Sprockets::Environment.new(Dir.pwd) }
|
|
100
|
-
@manifest = lambda { Sprockets::Manifest.new(
|
|
101
|
+
@manifest = lambda { Sprockets::Manifest.new(cached, output) }
|
|
101
102
|
@logger = Logger.new($stderr)
|
|
102
103
|
@logger.level = Logger::INFO
|
|
103
104
|
@keep = 2
|