sprockets-rails 3.0.0.beta1 → 3.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +17 -17
- data/lib/sprockets/rails/context.rb +48 -0
- data/lib/sprockets/rails/helper.rb +117 -112
- data/lib/sprockets/rails/route_wrapper.rb +23 -0
- data/lib/sprockets/rails/task.rb +10 -14
- data/lib/sprockets/rails/utils.rb +16 -0
- data/lib/sprockets/rails/version.rb +1 -1
- data/lib/sprockets/railtie.rb +121 -69
- metadata +42 -12
- data/lib/sprockets/rails/environment.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25923aeac0b56b286d1fa13aed70e9473d34ead2
|
4
|
+
data.tar.gz: 9dfd806b0fd3a1839680622882d7a01db8670f44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8c7541800873483a0032d728d776c5578f770708d83804d8aa77ca41d709726af9a1db5c1ad2e600afd0995f506db10e2ebeda08c8a65de9aa9bc61d41c44e
|
7
|
+
data.tar.gz: b7888a09152ca3686aa43e5df660dacbfcf185162e87c3818cddc9aa0698ffb183b19a8a03c6a2c5a4af3aa4fac99bfdb80fddf23f1755c9543ee0cbac677be3
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Only removes old assets (keeps the most recent 3 copies) from `public/assets`. U
|
|
27
27
|
|
28
28
|
**`rake assets:clobber`**
|
29
29
|
|
30
|
-
Nuke `public/assets
|
30
|
+
Nuke `public/assets`.
|
31
31
|
|
32
32
|
#### Customize
|
33
33
|
|
@@ -37,11 +37,6 @@ You can also redefine the task with the built in task generator.
|
|
37
37
|
|
38
38
|
``` ruby
|
39
39
|
require 'sprockets/rails/task'
|
40
|
-
# clean the old tasks
|
41
|
-
Rake::Task["assets:environment"].clear
|
42
|
-
Rake::Task["assets:precompile"].clear
|
43
|
-
Rake::Task["assets:clean"].clear
|
44
|
-
Rake::Task["assets:clobber"].clear
|
45
40
|
Sprockets::Rails::Task.new(Rails.application) do |t|
|
46
41
|
t.environment = lambda { Rails.application.assets }
|
47
42
|
t.assets = %w( application.js application.css )
|
@@ -51,7 +46,7 @@ end
|
|
51
46
|
|
52
47
|
Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.
|
53
48
|
|
54
|
-
Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/
|
49
|
+
Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/rails/sprockets/blob/master/lib/rake/sprocketstask.rb).
|
55
50
|
|
56
51
|
|
57
52
|
### Initializer options
|
@@ -60,10 +55,6 @@ Also see [Sprockets::Rails::Task](https://github.com/rails/sprockets-rails/blob/
|
|
60
55
|
|
61
56
|
Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.
|
62
57
|
|
63
|
-
**`config.assets.raise_runtime_errors`**
|
64
|
-
|
65
|
-
Set to `true` to enable additional runtime error checking. Recommended in the `development` environment to minimize unexpected behavior when deploying to `production`.
|
66
|
-
|
67
58
|
**`config.assets.paths`**
|
68
59
|
|
69
60
|
Add additional load paths to this Array. Rails includes `app/assets`, `lib/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to this.
|
@@ -90,8 +81,6 @@ Defines the full path to be used for the asset precompiler's manifest file. Defa
|
|
90
81
|
**`config.assets.digest`**
|
91
82
|
|
92
83
|
When enabled, fingerprints will be added to asset filenames.
|
93
|
-
If `config.assets.raise_runtime_errors` is also enabled, requests for assets
|
94
|
-
will raise an error unless they contain fingerprints.
|
95
84
|
|
96
85
|
**`config.assets.debug`**
|
97
86
|
|
@@ -99,7 +88,7 @@ Enable expanded asset debugging mode. Individual files will be served to make re
|
|
99
88
|
|
100
89
|
**`config.assets.compile`**
|
101
90
|
|
102
|
-
Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be
|
91
|
+
Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be `nil` to prevent inadvertent compilation calls. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. Initializers expecting `Rails.application.assets` during boot should be accessing the environment in a `config.assets.configure` block. See below.
|
103
92
|
|
104
93
|
**`config.assets.configure`**
|
105
94
|
|
@@ -139,6 +128,17 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
139
128
|
* `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory.
|
140
129
|
* Two cleanup tasks. `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used. While `rake assets:clobber` nukes the entire `public/assets` directory and clears your filesystem cache. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
|
141
130
|
|
131
|
+
## Experimental
|
132
|
+
|
133
|
+
### [SRI](http://www.w3.org/TR/SRI/) support
|
134
|
+
|
135
|
+
Sprockets 3.x adds experimental support for subresource integrity checks. The spec is still evolving and the API may change in backwards incompatible ways.
|
136
|
+
|
137
|
+
``` ruby
|
138
|
+
javascript_include_tag :application, integrity: true
|
139
|
+
# => "<script src="/assets/application.js" integrity="sha-256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
|
140
|
+
```
|
141
|
+
|
142
142
|
|
143
143
|
## Contributing
|
144
144
|
|
@@ -156,17 +156,17 @@ $ bundle exec rake test
|
|
156
156
|
|
157
157
|
## Releases
|
158
158
|
|
159
|
-
sprockets-rails
|
159
|
+
sprockets-rails 3.x will primarily target sprockets 3.x. And future versions will target the corresponding sprockets release line.
|
160
160
|
|
161
161
|
The minor and patch version will be updated according to [semver](http://semver.org/).
|
162
162
|
|
163
163
|
* Any new APIs or config options that don't break compatibility will be in a minor release
|
164
|
-
* Any time the sprockets
|
164
|
+
* Any time the sprockets dependency is bumped, there will be a new minor release
|
165
165
|
* Simple bug fixes will be patch releases
|
166
166
|
|
167
167
|
|
168
168
|
## License
|
169
169
|
|
170
|
-
Copyright ©
|
170
|
+
Copyright © 2014 Joshua Peek.
|
171
171
|
|
172
172
|
Released under the MIT license. See `LICENSE` for details.
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'sprockets'
|
3
|
+
|
4
|
+
module Sprockets
|
5
|
+
module Rails
|
6
|
+
module Context
|
7
|
+
include ActionView::Helpers::AssetUrlHelper
|
8
|
+
include ActionView::Helpers::AssetTagHelper
|
9
|
+
|
10
|
+
def self.included(klass)
|
11
|
+
klass.class_eval do
|
12
|
+
class_attribute :config, :assets_prefix, :digest_assets
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def compute_asset_path(path, options = {})
|
17
|
+
@dependencies << 'actioncontroller-asset-url-config'
|
18
|
+
|
19
|
+
begin
|
20
|
+
asset_uri = resolve(path)
|
21
|
+
rescue FileNotFound
|
22
|
+
# TODO: eh, we should be able to use a form of locate that returns
|
23
|
+
# nil instead of raising an exception.
|
24
|
+
end
|
25
|
+
|
26
|
+
if asset_uri
|
27
|
+
asset = link_asset(path)
|
28
|
+
digest_path = asset.digest_path
|
29
|
+
path = digest_path if digest_assets
|
30
|
+
File.join(assets_prefix || "/", path)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
register_dependency_resolver 'actioncontroller-asset-url-config' do |env|
|
39
|
+
config = env.context_class.config
|
40
|
+
[config.relative_url_root,
|
41
|
+
(config.asset_host unless config.asset_host.respond_to?(:call))]
|
42
|
+
end
|
43
|
+
|
44
|
+
# fallback to the default pipeline when using Sprockets 3.x
|
45
|
+
unless config[:pipelines].include? :debug
|
46
|
+
register_pipeline :debug, config[:pipelines][:default]
|
47
|
+
end
|
48
|
+
end
|
@@ -1,122 +1,123 @@
|
|
1
1
|
require 'action_view'
|
2
2
|
require 'sprockets'
|
3
3
|
require 'active_support/core_ext/class/attribute'
|
4
|
+
require 'sprockets/rails/utils'
|
4
5
|
|
5
6
|
module Sprockets
|
6
7
|
module Rails
|
7
8
|
module Helper
|
8
|
-
class
|
9
|
-
attr_accessor :precompile, :assets, :raise_runtime_errors
|
10
|
-
end
|
11
|
-
|
12
|
-
def precompile
|
13
|
-
Sprockets::Rails::Helper.precompile
|
14
|
-
end
|
15
|
-
|
16
|
-
def assets
|
17
|
-
Sprockets::Rails::Helper.assets
|
18
|
-
end
|
19
|
-
|
20
|
-
def raise_runtime_errors
|
21
|
-
Sprockets::Rails::Helper.raise_runtime_errors
|
22
|
-
end
|
23
|
-
|
24
|
-
class AssetFilteredError < StandardError
|
9
|
+
class AssetNotPrecompiled < StandardError
|
25
10
|
def initialize(source)
|
26
|
-
msg = "Asset
|
27
|
-
"
|
28
|
-
"to `config/initializers/assets.rb` and
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class AbsoluteAssetPathError < ArgumentError
|
34
|
-
def initialize(bad_path, good_path, prefix)
|
35
|
-
msg = "Asset names passed to helpers should not include the #{prefix.inspect} prefix. " <<
|
36
|
-
"Instead of #{bad_path.inspect}, use #{good_path.inspect}"
|
11
|
+
msg = "Asset was not declared to be precompiled in production.\n" +
|
12
|
+
"Add `Rails.application.config.assets.precompile += " +
|
13
|
+
"%w( #{source} )` to `config/initializers/assets.rb` and " +
|
14
|
+
"restart your server"
|
37
15
|
super(msg)
|
38
16
|
end
|
39
17
|
end
|
40
18
|
|
41
19
|
include ActionView::Helpers::AssetUrlHelper
|
42
20
|
include ActionView::Helpers::AssetTagHelper
|
21
|
+
include Sprockets::Rails::Utils
|
43
22
|
|
44
23
|
VIEW_ACCESSORS = [:assets_environment, :assets_manifest,
|
24
|
+
:assets_precompile, :precompiled_assets,
|
45
25
|
:assets_prefix, :digest_assets, :debug_assets]
|
46
26
|
|
47
27
|
def self.included(klass)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
28
|
+
klass.class_attribute(*VIEW_ACCESSORS)
|
29
|
+
|
30
|
+
klass.class_eval do
|
31
|
+
remove_method :assets_environment
|
32
|
+
def assets_environment
|
33
|
+
if instance_variable_defined?(:@assets_environment)
|
34
|
+
@assets_environment = @assets_environment.cached
|
35
|
+
elsif env = self.class.assets_environment
|
36
|
+
@assets_environment = env.cached
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
53
40
|
end
|
54
|
-
else
|
55
|
-
klass.class_attribute(*VIEW_ACCESSORS)
|
56
41
|
end
|
57
42
|
end
|
58
43
|
|
59
44
|
def self.extended(obj)
|
60
45
|
obj.class_eval do
|
61
46
|
attr_accessor(*VIEW_ACCESSORS)
|
47
|
+
|
48
|
+
remove_method :assets_environment
|
49
|
+
def assets_environment
|
50
|
+
if env = @assets_environment
|
51
|
+
@assets_environment = env.cached
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
62
56
|
end
|
63
57
|
end
|
64
58
|
|
65
59
|
def compute_asset_path(path, options = {})
|
66
|
-
|
67
|
-
check_dependencies!(path) if defined?(depend_on)
|
68
|
-
|
69
|
-
if digest_path = asset_digest_path(path)
|
60
|
+
if digest_path = asset_digest_path(path, options)
|
70
61
|
path = digest_path if digest_assets
|
71
|
-
path += "?body=1" if options[:debug]
|
62
|
+
path += "?body=1" if options[:debug] && !using_sprockets4?
|
72
63
|
File.join(assets_prefix || "/", path)
|
73
64
|
else
|
74
65
|
super
|
75
66
|
end
|
76
67
|
end
|
77
68
|
|
78
|
-
#
|
79
|
-
# method checks for errors before returning path.
|
80
|
-
def asset_path(source, options = {})
|
81
|
-
unless options[:debug]
|
82
|
-
check_errors_for(source, options)
|
83
|
-
end
|
84
|
-
super(source, options)
|
85
|
-
end
|
86
|
-
alias :path_to_asset :asset_path
|
87
|
-
|
88
|
-
# Get digest for asset path.
|
69
|
+
# Expand asset path to digested form.
|
89
70
|
#
|
90
71
|
# path - String path
|
91
72
|
# options - Hash options
|
92
73
|
#
|
93
|
-
# Returns String
|
94
|
-
def
|
95
|
-
|
74
|
+
# Returns String path or nil if no asset was found.
|
75
|
+
def asset_digest_path(path, options = {})
|
76
|
+
if manifest = assets_manifest
|
77
|
+
if digest_path = manifest.assets[path]
|
78
|
+
return digest_path
|
79
|
+
end
|
80
|
+
end
|
96
81
|
|
97
|
-
if
|
98
|
-
|
82
|
+
if environment = assets_environment
|
83
|
+
if asset = environment[path]
|
84
|
+
unless options[:debug]
|
85
|
+
if !precompiled_assets.include?(asset.logical_path)
|
86
|
+
raise AssetNotPrecompiled.new(asset.logical_path)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return asset.digest_path
|
90
|
+
end
|
99
91
|
end
|
100
92
|
end
|
101
93
|
|
102
|
-
#
|
94
|
+
# Experimental: Get integrity for asset path.
|
103
95
|
#
|
104
96
|
# path - String path
|
105
97
|
# options - Hash options
|
106
98
|
#
|
107
|
-
# Returns String
|
108
|
-
def
|
99
|
+
# Returns String integrity attribute or nil if no asset was found.
|
100
|
+
def asset_integrity(path, options = {})
|
101
|
+
path = path.to_s
|
102
|
+
if extname = compute_asset_extname(path, options)
|
103
|
+
path = "#{path}#{extname}"
|
104
|
+
end
|
105
|
+
|
109
106
|
if manifest = assets_manifest
|
110
107
|
if digest_path = manifest.assets[path]
|
111
|
-
|
108
|
+
if metadata = manifest.files[digest_path]
|
109
|
+
return metadata["integrity"]
|
110
|
+
end
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
115
114
|
if environment = assets_environment
|
116
115
|
if asset = environment[path]
|
117
|
-
return asset.
|
116
|
+
return asset.integrity
|
118
117
|
end
|
119
118
|
end
|
119
|
+
|
120
|
+
nil
|
120
121
|
end
|
121
122
|
|
122
123
|
# Override javascript tag helper to provide debugging support.
|
@@ -125,20 +126,35 @@ module Sprockets
|
|
125
126
|
def javascript_include_tag(*sources)
|
126
127
|
options = sources.extract_options!.stringify_keys
|
127
128
|
|
129
|
+
unless request_ssl?
|
130
|
+
options.delete("integrity")
|
131
|
+
end
|
132
|
+
|
133
|
+
case options["integrity"]
|
134
|
+
when true, false, nil
|
135
|
+
compute_integrity = options.delete("integrity")
|
136
|
+
end
|
137
|
+
|
128
138
|
if options["debug"] != false && request_debug_assets?
|
129
139
|
sources.map { |source|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
140
|
+
if asset = lookup_debug_asset(source, :type => :javascript)
|
141
|
+
if asset.respond_to?(:to_a)
|
142
|
+
asset.to_a.map do |a|
|
143
|
+
super(path_to_javascript(a.logical_path, :debug => true), options)
|
144
|
+
end
|
145
|
+
else
|
146
|
+
super(path_to_javascript(asset.logical_path, :debug => true), options)
|
134
147
|
end
|
135
148
|
else
|
136
149
|
super(source, options)
|
137
150
|
end
|
138
151
|
}.flatten.uniq.join("\n").html_safe
|
139
152
|
else
|
140
|
-
sources.
|
141
|
-
|
153
|
+
sources.map { |source|
|
154
|
+
super(source, compute_integrity ?
|
155
|
+
options.merge("integrity" => asset_integrity(source, :type => :javascript)) :
|
156
|
+
options)
|
157
|
+
}.join("\n").html_safe
|
142
158
|
end
|
143
159
|
end
|
144
160
|
|
@@ -147,61 +163,42 @@ module Sprockets
|
|
147
163
|
# Eventually will be deprecated and replaced by source maps.
|
148
164
|
def stylesheet_link_tag(*sources)
|
149
165
|
options = sources.extract_options!.stringify_keys
|
166
|
+
|
167
|
+
unless request_ssl?
|
168
|
+
options.delete("integrity")
|
169
|
+
end
|
170
|
+
|
171
|
+
case options["integrity"]
|
172
|
+
when true, false, nil
|
173
|
+
compute_integrity = options.delete("integrity")
|
174
|
+
end
|
175
|
+
|
150
176
|
if options["debug"] != false && request_debug_assets?
|
151
177
|
sources.map { |source|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
178
|
+
if asset = lookup_debug_asset(source, :type => :stylesheet)
|
179
|
+
if asset.respond_to?(:to_a)
|
180
|
+
asset.to_a.map do |a|
|
181
|
+
super(path_to_stylesheet(a.logical_path, :debug => true), options)
|
182
|
+
end
|
183
|
+
else
|
184
|
+
super(path_to_stylesheet(asset.logical_path, :debug => true), options)
|
156
185
|
end
|
157
186
|
else
|
158
187
|
super(source, options)
|
159
188
|
end
|
160
189
|
}.flatten.uniq.join("\n").html_safe
|
161
190
|
else
|
162
|
-
sources.
|
163
|
-
|
191
|
+
sources.map { |source|
|
192
|
+
super(source, compute_integrity ?
|
193
|
+
options.merge("integrity" => asset_integrity(source, :type => :stylesheet)) :
|
194
|
+
options)
|
195
|
+
}.join("\n").html_safe
|
164
196
|
end
|
165
197
|
end
|
166
198
|
|
167
199
|
protected
|
168
|
-
|
169
|
-
|
170
|
-
depend_on(dep)
|
171
|
-
depend_on_asset(dep)
|
172
|
-
rescue Sprockets::FileNotFound
|
173
|
-
end
|
174
|
-
|
175
|
-
# Raise errors when source is not in the precompiled list, or
|
176
|
-
# incorrectly contains the assets_prefix.
|
177
|
-
def check_errors_for(source, options)
|
178
|
-
return unless self.raise_runtime_errors
|
179
|
-
|
180
|
-
source = source.to_s
|
181
|
-
return if source.blank? || source =~ URI_REGEXP
|
182
|
-
|
183
|
-
asset = lookup_asset_for_path(source, options)
|
184
|
-
|
185
|
-
if asset && asset_needs_precompile?(asset.logical_path, asset.pathname.to_s)
|
186
|
-
raise AssetFilteredError.new(asset.logical_path)
|
187
|
-
end
|
188
|
-
|
189
|
-
full_prefix = File.join(self.assets_prefix || "/", '')
|
190
|
-
if !asset && source.start_with?(full_prefix)
|
191
|
-
short_path = source[full_prefix.size, source.size]
|
192
|
-
if lookup_asset_for_path(short_path, options)
|
193
|
-
raise AbsoluteAssetPathError.new(source, short_path, full_prefix)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
# Returns true when an asset will not be available after precompile is run
|
199
|
-
def asset_needs_precompile?(source, filename)
|
200
|
-
if assets_environment && assets_environment.send(:matches_filter, precompile || [], source, filename)
|
201
|
-
false
|
202
|
-
else
|
203
|
-
true
|
204
|
-
end
|
200
|
+
def request_ssl?
|
201
|
+
respond_to?(:request) && self.request && self.request.ssl?
|
205
202
|
end
|
206
203
|
|
207
204
|
# Enable split asset debugging. Eventually will be deprecated
|
@@ -214,13 +211,21 @@ module Sprockets
|
|
214
211
|
|
215
212
|
# Internal method to support multifile debugging. Will
|
216
213
|
# eventually be removed w/ Sprockets 3.x.
|
217
|
-
def
|
214
|
+
def lookup_debug_asset(path, options = {})
|
218
215
|
return unless env = assets_environment
|
219
216
|
path = path.to_s
|
220
217
|
if extname = compute_asset_extname(path, options)
|
221
218
|
path = "#{path}#{extname}"
|
222
219
|
end
|
223
|
-
|
220
|
+
|
221
|
+
if asset = env[path, pipeline: :debug]
|
222
|
+
original_path = asset.logical_path.gsub('.debug', '')
|
223
|
+
unless precompiled_assets.include?(original_path)
|
224
|
+
raise AssetNotPrecompiled.new(original_path)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
asset
|
224
229
|
end
|
225
230
|
end
|
226
231
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Rails
|
3
|
+
module RouteWrapper
|
4
|
+
|
5
|
+
def internal_assets_path?
|
6
|
+
path =~ %r{\A#{self.class.assets_prefix}\z}
|
7
|
+
end
|
8
|
+
|
9
|
+
def internal?
|
10
|
+
super || internal_assets_path?
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(klass)
|
14
|
+
klass.class_eval do
|
15
|
+
def internal_with_sprockets?
|
16
|
+
internal_without_sprockets? || internal_assets_path?
|
17
|
+
end
|
18
|
+
alias_method_chain :internal?, :sprockets
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/sprockets/rails/task.rb
CHANGED
@@ -16,7 +16,9 @@ module Sprockets
|
|
16
16
|
|
17
17
|
def environment
|
18
18
|
if app
|
19
|
-
app.assets
|
19
|
+
# Use initialized app.assets or force build an environment if
|
20
|
+
# config.assets.compile is disabled
|
21
|
+
app.assets || Sprockets::Railtie.build_environment(app)
|
20
22
|
else
|
21
23
|
super
|
22
24
|
end
|
@@ -24,7 +26,8 @@ module Sprockets
|
|
24
26
|
|
25
27
|
def output
|
26
28
|
if app
|
27
|
-
|
29
|
+
config = app.config
|
30
|
+
File.join(config.paths['public'].first, config.assets.prefix)
|
28
31
|
else
|
29
32
|
super
|
30
33
|
end
|
@@ -46,17 +49,12 @@ module Sprockets
|
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
49
|
-
def cache_path
|
50
|
-
if app
|
51
|
-
"#{app.config.root}/tmp/cache/assets"
|
52
|
-
else
|
53
|
-
@cache_path
|
54
|
-
end
|
55
|
-
end
|
56
|
-
attr_writer :cache_path
|
57
|
-
|
58
52
|
def define
|
59
53
|
namespace :assets do
|
54
|
+
%w( environment precompile clean clobber ).each do |task|
|
55
|
+
Rake::Task[task].clear if Rake::Task.task_defined?(task)
|
56
|
+
end
|
57
|
+
|
60
58
|
# Override this task change the loaded dependencies
|
61
59
|
desc "Load asset compile environment"
|
62
60
|
task :environment do
|
@@ -73,9 +71,8 @@ module Sprockets
|
|
73
71
|
|
74
72
|
desc "Remove old compiled assets"
|
75
73
|
task :clean, [:keep] => :environment do |t, args|
|
76
|
-
keep = Integer(args.keep || 2)
|
77
74
|
with_logger do
|
78
|
-
manifest.clean(keep)
|
75
|
+
manifest.clean(Integer(args.keep || self.keep))
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
@@ -83,7 +80,6 @@ module Sprockets
|
|
83
80
|
task :clobber => :environment do
|
84
81
|
with_logger do
|
85
82
|
manifest.clobber
|
86
|
-
rm_rf cache_path if cache_path
|
87
83
|
end
|
88
84
|
end
|
89
85
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module Rails
|
5
|
+
module Utils
|
6
|
+
def using_sprockets4?
|
7
|
+
Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('4.0.0')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Internal: Generate a Set of all precompiled assets logical paths.
|
11
|
+
def build_precompiled_list(manifest, assets)
|
12
|
+
manifest.find(assets || []).map(&:logical_path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/sprockets/railtie.rb
CHANGED
@@ -2,9 +2,11 @@ require 'rails'
|
|
2
2
|
require 'rails/railtie'
|
3
3
|
require 'action_controller/railtie'
|
4
4
|
require 'active_support/core_ext/module/remove_method'
|
5
|
+
require 'active_support/core_ext/numeric/bytes'
|
5
6
|
require 'sprockets'
|
6
|
-
require 'sprockets/rails/
|
7
|
+
require 'sprockets/rails/context'
|
7
8
|
require 'sprockets/rails/helper'
|
9
|
+
require 'sprockets/rails/route_wrapper'
|
8
10
|
require 'sprockets/rails/version'
|
9
11
|
|
10
12
|
module Rails
|
@@ -19,27 +21,36 @@ module Rails
|
|
19
21
|
remove_possible_method :assets
|
20
22
|
remove_possible_method :assets=
|
21
23
|
|
22
|
-
# Returns Sprockets::
|
23
|
-
|
24
|
-
@assets ||= Sprockets::Rails::Environment.new(root.to_s) do |env|
|
25
|
-
env.version = ::Rails.env
|
24
|
+
# Returns Sprockets::Environment for app config.
|
25
|
+
attr_accessor :assets
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# Returns Sprockets::Manifest for app config.
|
28
|
+
attr_accessor :assets_manifest
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# Returns array of already precompiled assets
|
31
|
+
attr_accessor :precompiled_assets
|
32
|
+
end
|
33
|
+
|
34
|
+
class Engine < Railtie
|
35
|
+
# Skip defining append_assets_path on Rails <= 4.2
|
36
|
+
unless initializers.find { |init| init.name == :append_assets_path }
|
37
|
+
initializer :append_assets_path, :group => :all do |app|
|
38
|
+
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
|
39
|
+
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
|
40
|
+
app.config.assets.paths.unshift(*paths["app"].existent_directories.grep(/\/assets\z/))
|
41
|
+
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
|
33
42
|
end
|
34
43
|
end
|
35
|
-
attr_writer :assets
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
39
47
|
module Sprockets
|
40
48
|
class Railtie < ::Rails::Railtie
|
41
|
-
|
42
|
-
|
49
|
+
include Sprockets::Rails::Utils
|
50
|
+
|
51
|
+
LOOSE_APP_ASSETS = lambda do |logical_path, filename|
|
52
|
+
filename.start_with?(::Rails.root.join("app/assets").to_s) &&
|
53
|
+
!%w(.js .css).include?(File.extname(logical_path))
|
43
54
|
end
|
44
55
|
|
45
56
|
class OrderedOptions < ActiveSupport::OrderedOptions
|
@@ -49,88 +60,129 @@ module Sprockets
|
|
49
60
|
end
|
50
61
|
|
51
62
|
config.assets = OrderedOptions.new
|
52
|
-
config.assets._blocks
|
53
|
-
config.assets.paths
|
54
|
-
config.assets.prefix
|
55
|
-
config.assets.manifest
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
config.assets._blocks = []
|
64
|
+
config.assets.paths = []
|
65
|
+
config.assets.prefix = "/assets"
|
66
|
+
config.assets.manifest = nil
|
67
|
+
if using_sprockets4?
|
68
|
+
config.assets.precompile = %w( manifest.js )
|
69
|
+
else
|
70
|
+
config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
|
71
|
+
end
|
72
|
+
config.assets.version = ""
|
73
|
+
config.assets.debug = false
|
74
|
+
config.assets.compile = true
|
75
|
+
config.assets.digest = true
|
76
|
+
config.assets.cache_limit = 50.megabytes
|
77
|
+
|
78
|
+
config.assets.configure do |env|
|
79
|
+
config.assets.paths.each { |path| env.append_path(path) }
|
80
|
+
end
|
61
81
|
|
62
|
-
|
63
|
-
|
64
|
-
|
82
|
+
config.assets.configure do |env|
|
83
|
+
env.js_compressor = config.assets.js_compressor
|
84
|
+
env.css_compressor = config.assets.css_compressor
|
65
85
|
end
|
66
86
|
|
67
|
-
config.
|
68
|
-
|
87
|
+
config.assets.configure do |env|
|
88
|
+
env.context_class.send :include, ::Sprockets::Rails::Context
|
89
|
+
env.context_class.assets_prefix = config.assets.prefix
|
90
|
+
env.context_class.digest_assets = config.assets.digest
|
91
|
+
env.context_class.config = config.action_controller
|
92
|
+
end
|
69
93
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
config.action_controller.relative_url_root,
|
78
|
-
(config.action_controller.asset_host unless config.action_controller.asset_host.respond_to?(:call)),
|
79
|
-
Sprockets::Rails::VERSION
|
80
|
-
].compact.join('-')
|
81
|
-
|
82
|
-
# Copy config.assets.paths to Sprockets
|
83
|
-
config.assets.paths.each do |path|
|
84
|
-
app.assets.append_path path
|
85
|
-
end
|
94
|
+
config.assets.configure do |env|
|
95
|
+
env.cache = Sprockets::Cache::FileStore.new(
|
96
|
+
"#{env.root}/tmp/cache",
|
97
|
+
config.assets.cache_limit,
|
98
|
+
env.logger
|
99
|
+
)
|
100
|
+
end
|
86
101
|
|
87
|
-
|
88
|
-
|
102
|
+
Sprockets.register_dependency_resolver 'rails-env' do
|
103
|
+
::Rails.env
|
104
|
+
end
|
105
|
+
config.assets.configure do |env|
|
106
|
+
env.depend_on 'environment-version'
|
107
|
+
end
|
89
108
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
self.assets_prefix = config.assets.prefix
|
109
|
+
config.assets.configure do |env|
|
110
|
+
env.version = config.assets.version
|
111
|
+
end
|
94
112
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
context.config = config.action_controller
|
113
|
+
rake_tasks do |app|
|
114
|
+
require 'sprockets/rails/task'
|
115
|
+
Sprockets::Rails::Task.new(app)
|
116
|
+
end
|
100
117
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
self.assets_manifest = Sprockets::Manifest.new(manifest_assets_path, config.assets.manifest)
|
106
|
-
end
|
118
|
+
def build_environment(app, initialized = nil)
|
119
|
+
initialized = app.initialized? if initialized.nil?
|
120
|
+
unless initialized
|
121
|
+
::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!"
|
107
122
|
end
|
108
123
|
|
109
|
-
|
110
|
-
app.assets.css_compressor = config.assets.css_compressor
|
124
|
+
env = Sprockets::Environment.new(app.root.to_s)
|
111
125
|
|
112
126
|
# Run app.assets.configure blocks
|
113
|
-
config.assets._blocks.each do |block|
|
114
|
-
block.call
|
127
|
+
app.config.assets._blocks.each do |block|
|
128
|
+
block.call(env)
|
115
129
|
end
|
116
130
|
|
117
131
|
# No more configuration changes at this point.
|
118
132
|
# With cache classes on, Sprockets won't check the FS when files
|
119
133
|
# change. Preferable in production when the FS only changes on
|
120
134
|
# deploys when the app restarts.
|
121
|
-
if config.cache_classes
|
122
|
-
|
135
|
+
if app.config.cache_classes
|
136
|
+
env = env.cached
|
123
137
|
end
|
124
138
|
|
139
|
+
env
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.build_manifest(app)
|
143
|
+
config = app.config
|
144
|
+
path = File.join(config.paths['public'].first, config.assets.prefix)
|
145
|
+
Sprockets::Manifest.new(app.assets, path, config.assets.manifest)
|
146
|
+
end
|
125
147
|
|
126
|
-
|
127
|
-
|
128
|
-
Sprockets::Rails::Helper.raise_runtime_errors = app.config.assets.raise_runtime_errors
|
148
|
+
config.after_initialize do |app|
|
149
|
+
config = app.config
|
129
150
|
|
130
151
|
if config.assets.compile
|
152
|
+
app.assets = self.build_environment(app, true)
|
131
153
|
app.routes.prepend do
|
132
154
|
mount app.assets => config.assets.prefix
|
133
155
|
end
|
156
|
+
app.assets_manifest = build_manifest(app)
|
157
|
+
app.precompiled_assets = build_precompiled_list(app.assets_manifest, config.assets.precompile)
|
158
|
+
else
|
159
|
+
app.assets_manifest = build_manifest(app)
|
160
|
+
end
|
161
|
+
|
162
|
+
ActionDispatch::Routing::RouteWrapper.class_eval do
|
163
|
+
class_attribute :assets_prefix
|
164
|
+
|
165
|
+
if defined?(prepend) && ::Rails.version >= '4'
|
166
|
+
prepend Sprockets::Rails::RouteWrapper
|
167
|
+
else
|
168
|
+
include Sprockets::Rails::RouteWrapper
|
169
|
+
end
|
170
|
+
|
171
|
+
self.assets_prefix = config.assets.prefix
|
172
|
+
end
|
173
|
+
|
174
|
+
ActiveSupport.on_load(:action_view) do
|
175
|
+
include Sprockets::Rails::Helper
|
176
|
+
|
177
|
+
# Copy relevant config to AV context
|
178
|
+
self.debug_assets = config.assets.debug
|
179
|
+
self.digest_assets = config.assets.digest
|
180
|
+
self.assets_prefix = config.assets.prefix
|
181
|
+
self.assets_precompile = config.assets.precompile
|
182
|
+
|
183
|
+
self.assets_environment = app.assets
|
184
|
+
self.assets_manifest = app.assets_manifest
|
185
|
+
self.precompiled_assets = app.precompiled_assets
|
134
186
|
end
|
135
187
|
end
|
136
188
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: railties
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,19 +81,33 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: sass
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: uglifier
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description:
|
84
112
|
email: josh@joshpeek.com
|
85
113
|
executables: []
|
@@ -89,9 +117,11 @@ files:
|
|
89
117
|
- LICENSE
|
90
118
|
- README.md
|
91
119
|
- lib/sprockets/rails.rb
|
92
|
-
- lib/sprockets/rails/
|
120
|
+
- lib/sprockets/rails/context.rb
|
93
121
|
- lib/sprockets/rails/helper.rb
|
122
|
+
- lib/sprockets/rails/route_wrapper.rb
|
94
123
|
- lib/sprockets/rails/task.rb
|
124
|
+
- lib/sprockets/rails/utils.rb
|
95
125
|
- lib/sprockets/rails/version.rb
|
96
126
|
- lib/sprockets/railtie.rb
|
97
127
|
homepage: https://github.com/rails/sprockets-rails
|
@@ -106,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
136
|
requirements:
|
107
137
|
- - ">="
|
108
138
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
139
|
+
version: 1.9.3
|
110
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
141
|
requirements:
|
112
142
|
- - ">"
|
@@ -114,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
144
|
version: 1.3.1
|
115
145
|
requirements: []
|
116
146
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.4.7
|
118
148
|
signing_key:
|
119
149
|
specification_version: 4
|
120
150
|
summary: Sprockets Rails integration
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
require 'sprockets/rails/helper'
|
3
|
-
|
4
|
-
module Sprockets
|
5
|
-
module Rails
|
6
|
-
class Environment < Sprockets::Environment
|
7
|
-
class NoDigestError < StandardError
|
8
|
-
def initialize(asset)
|
9
|
-
msg = "Assets should not be requested directly without their digests: " <<
|
10
|
-
"Use the helpers in ActionView::Helpers to request #{asset}"
|
11
|
-
super(msg)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
if Sprockets::Rails::Helper.raise_runtime_errors && context_class.digest_assets
|
17
|
-
path = unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
|
18
|
-
|
19
|
-
if fingerprint = path_fingerprint(path)
|
20
|
-
path = path.sub("-#{fingerprint}", '')
|
21
|
-
else
|
22
|
-
raise NoDigestError.new(path)
|
23
|
-
end
|
24
|
-
|
25
|
-
asset = find_asset(path)
|
26
|
-
if asset && asset.digest != fingerprint
|
27
|
-
asset_path = File.join(context_class.assets_prefix || "/", asset.digest_path)
|
28
|
-
asset_path += '?' + env['QUERY_STRING'] if env['QUERY_STRING']
|
29
|
-
[302, {"Location" => asset_path}, []]
|
30
|
-
else
|
31
|
-
super(env)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
super(env)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|