sprockets-rails 3.0.4 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +25 -5
- data/lib/sprockets/rails/context.rb +1 -1
- data/lib/sprockets/rails/helper.rb +38 -15
- data/lib/sprockets/rails/quiet_assets.rb +18 -0
- data/lib/sprockets/rails/task.rb +0 -1
- data/lib/sprockets/rails/version.rb +1 -1
- data/lib/sprockets/railtie.rb +44 -6
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 801a6cbc13340fb4c74ecf9b7aa2d5c6c563605e3462512e0073f268e269fe8d
|
4
|
+
data.tar.gz: facde95b73f355f987059128c7f6d852b5b8845d26f2eca5214b4fc37ded168d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f6c2f179ba5b3294ad0b49357c4a7a50c207f221d6cbb5d9cad406b1143ee5ff9d5a71897f3f6a2bd9709eda8d5e5bad5380e4defa1e135700cc3edd9669749
|
7
|
+
data.tar.gz: cbd34277b1e2e89c5ddded1b616ce179a269e384f1781b7032972c966737803e725440f5a23951383adf6b4a8705b50a307eb94a2bd6055ab42dcfc505aa468c
|
data/README.md
CHANGED
@@ -48,9 +48,12 @@ Each asset task will invoke `assets:environment` first. By default this loads th
|
|
48
48
|
|
49
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).
|
50
50
|
|
51
|
-
|
52
51
|
### Initializer options
|
53
52
|
|
53
|
+
**`config.assets.unknown_asset_fallback`**
|
54
|
+
|
55
|
+
When set to a truthy value, a result will be returned even if the requested asset is not found in the asset pipeline. When set to a falsey value it will raise an error when no asset is found in the pipeline. Defaults to `true`.
|
56
|
+
|
54
57
|
**`config.assets.precompile`**
|
55
58
|
|
56
59
|
Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.
|
@@ -59,6 +62,9 @@ Add additional assets to compile on deploy. Defaults to `application.js`, `appli
|
|
59
62
|
|
60
63
|
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.
|
61
64
|
|
65
|
+
**`config.assets.quiet`**
|
66
|
+
|
67
|
+
Suppresses logger output for asset requests. Uses the `config.assets.prefix` path to match asset requests. Defaults to `false`.
|
62
68
|
|
63
69
|
**`config.assets.version`**
|
64
70
|
|
@@ -121,6 +127,10 @@ is not enabled, then we check the environment if compiling is enabled:
|
|
121
127
|
```
|
122
128
|
If the resolver list is empty (e.g. if debug is true and compile is false), the standard rails public path resolution will be used.
|
123
129
|
|
130
|
+
**`config.assets.check_precompiled_asset`**
|
131
|
+
|
132
|
+
When enabled, an exception is raised for missing assets. This option is enabled by default.
|
133
|
+
|
124
134
|
## Complementary plugins
|
125
135
|
|
126
136
|
The following plugins provide some extras for the Sprockets Asset Pipeline.
|
@@ -128,7 +138,7 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
128
138
|
* [coffee-rails](https://github.com/rails/coffee-rails)
|
129
139
|
* [sass-rails](https://github.com/rails/sass-rails)
|
130
140
|
|
131
|
-
**NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (
|
141
|
+
**NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (and many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.
|
132
142
|
|
133
143
|
|
134
144
|
## Changes from Rails 3.x
|
@@ -138,7 +148,16 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
138
148
|
* JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglifier` or `config.assets.css_compressor = :sass` for the standard compressors.
|
139
149
|
* The manifest file is now in a JSON format. Since it lives in public/ by default, the initial filename is also randomized to obfuscate public access to the resource.
|
140
150
|
* `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory.
|
141
|
-
* Two cleanup tasks
|
151
|
+
* 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. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
|
152
|
+
|
153
|
+
### But what if I want sprockets to generate non-digest assets?
|
154
|
+
|
155
|
+
You have several options:
|
156
|
+
|
157
|
+
* Use the [non-digest-assets gem](https://github.com/mvz/non-digest-assets).
|
158
|
+
* Use the [sprockets-redirect gem](https://github.com/sikachu/sprockets-redirect).
|
159
|
+
* Use the [smart_assets gem](https://github.com/zarqman/smart_assets).
|
160
|
+
* Create [a rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134) to pre-generate a non-digest version in `public/`.
|
142
161
|
|
143
162
|
## Experimental
|
144
163
|
|
@@ -151,6 +170,8 @@ javascript_include_tag :application, integrity: true
|
|
151
170
|
# => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
|
152
171
|
```
|
153
172
|
|
173
|
+
Note that sprockets-rails only adds integrity hashes to assets when served in a secure context (over an HTTPS connection or localhost).
|
174
|
+
|
154
175
|
|
155
176
|
## Contributing to Sprockets Rails
|
156
177
|
|
@@ -175,6 +196,5 @@ Sprockets Rails is released under the [MIT License](MIT-LICENSE).
|
|
175
196
|
|
176
197
|
## Code Status
|
177
198
|
|
178
|
-
* [![Travis CI](https://
|
199
|
+
* [![Travis CI](https://travis-ci.org/rails/sprockets-rails.svg?branch=master)](http://travis-ci.org/rails/sprockets-rails)
|
179
200
|
* [![Gem Version](https://badge.fury.io/rb/sprockets-rails.svg)](http://badge.fury.io/rb/sprockets-rails)
|
180
|
-
* [![Dependencies](https://gemnasium.com/rails/sprockets-rails.svg)](https://gemnasium.com/rails/sprockets-rails)
|
@@ -6,19 +6,18 @@ require 'sprockets/rails/utils'
|
|
6
6
|
module Sprockets
|
7
7
|
module Rails
|
8
8
|
module Helper
|
9
|
-
class
|
9
|
+
class AssetNotFound < StandardError; end
|
10
|
+
class AssetNotPrecompiled < StandardError; end
|
11
|
+
|
12
|
+
class AssetNotPrecompiledError < AssetNotPrecompiled
|
10
13
|
include Sprockets::Rails::Utils
|
11
14
|
def initialize(source)
|
12
15
|
msg =
|
13
16
|
if using_sprockets4?
|
14
|
-
"Asset `#{source}` was not declared to be precompiled in production.\n" +
|
15
|
-
"Declare links to your assets in `assets/config/manifest.js`.\n" +
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"`//= link_directory ../javascripts .js`\n" +
|
19
|
-
"`//= link_directory ../stylesheets .css`\n" +
|
20
|
-
"`//= link_tree ../javascripts .js`\n" +
|
21
|
-
"`//= link_tree ../images`\n"
|
17
|
+
"Asset `#{ source }` was not declared to be precompiled in production.\n" +
|
18
|
+
"Declare links to your assets in `app/assets/config/manifest.js`.\n\n" +
|
19
|
+
" //= link #{ source }\n\n" +
|
20
|
+
"and restart your server"
|
22
21
|
else
|
23
22
|
"Asset was not declared to be precompiled in production.\n" +
|
24
23
|
"Add `Rails.application.config.assets.precompile += " +
|
@@ -37,7 +36,8 @@ module Sprockets
|
|
37
36
|
:assets_environment, :assets_manifest,
|
38
37
|
:assets_precompile, :precompiled_asset_checker,
|
39
38
|
:assets_prefix, :digest_assets, :debug_assets,
|
40
|
-
:resolve_assets_with
|
39
|
+
:resolve_assets_with, :check_precompiled_asset,
|
40
|
+
:unknown_asset_fallback
|
41
41
|
]
|
42
42
|
|
43
43
|
def self.included(klass)
|
@@ -58,7 +58,7 @@ module Sprockets
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.extended(obj)
|
61
|
-
obj.class_eval do
|
61
|
+
obj.singleton_class.class_eval do
|
62
62
|
attr_accessor(*VIEW_ACCESSORS)
|
63
63
|
|
64
64
|
remove_method :assets_environment
|
@@ -72,12 +72,26 @@ module Sprockets
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
# Writes over the built in ActionView::Helpers::AssetUrlHelper#compute_asset_path
|
76
|
+
# to use the asset pipeline.
|
75
77
|
def compute_asset_path(path, options = {})
|
76
78
|
debug = options[:debug]
|
77
79
|
|
78
80
|
if asset_path = resolve_asset_path(path, debug)
|
79
81
|
File.join(assets_prefix || "/", legacy_debug_path(asset_path, debug))
|
80
82
|
else
|
83
|
+
message = "The asset #{ path.inspect } is not present in the asset pipeline.\n"
|
84
|
+
raise AssetNotFound, message unless unknown_asset_fallback
|
85
|
+
|
86
|
+
if respond_to?(:public_compute_asset_path)
|
87
|
+
message << "Falling back to an asset that may be in the public folder.\n"
|
88
|
+
message << "This behavior is deprecated and will be removed.\n"
|
89
|
+
message << "To bypass the asset pipeline and preserve this behavior,\n"
|
90
|
+
message << "use the `skip_pipeline: true` option.\n"
|
91
|
+
|
92
|
+
call_stack = Kernel.respond_to?(:caller_locations) && ::Rails::VERSION::MAJOR >= 5 ? caller_locations : caller
|
93
|
+
ActiveSupport::Deprecation.warn(message, call_stack)
|
94
|
+
end
|
81
95
|
super
|
82
96
|
end
|
83
97
|
end
|
@@ -196,7 +210,7 @@ module Sprockets
|
|
196
210
|
# Only serve integrity metadata for HTTPS requests:
|
197
211
|
# http://www.w3.org/TR/SRI/#non-secure-contexts-remain-non-secure
|
198
212
|
def secure_subresource_integrity_context?
|
199
|
-
respond_to?(:request) && self.request && self.request.ssl?
|
213
|
+
respond_to?(:request) && self.request && (self.request.local? || self.request.ssl?)
|
200
214
|
end
|
201
215
|
|
202
216
|
# Enable split asset debugging. Eventually will be deprecated
|
@@ -303,6 +317,7 @@ module Sprockets
|
|
303
317
|
raise ArgumentError, 'config.assets.resolve_with includes :environment, but app.assets is nil' unless view.assets_environment
|
304
318
|
@env = view.assets_environment
|
305
319
|
@precompiled_asset_checker = view.precompiled_asset_checker
|
320
|
+
@check_precompiled_asset = view.check_precompiled_asset
|
306
321
|
end
|
307
322
|
|
308
323
|
def asset_path(path, digest, allow_non_precompiled = false)
|
@@ -337,8 +352,16 @@ module Sprockets
|
|
337
352
|
end
|
338
353
|
|
339
354
|
private
|
340
|
-
|
341
|
-
|
355
|
+
if RUBY_VERSION >= "2.7"
|
356
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
357
|
+
def find_asset(path, options = {})
|
358
|
+
@env[path, **options]
|
359
|
+
end
|
360
|
+
RUBY
|
361
|
+
else
|
362
|
+
def find_asset(path, options = {})
|
363
|
+
@env[path, options]
|
364
|
+
end
|
342
365
|
end
|
343
366
|
|
344
367
|
def precompiled?(path)
|
@@ -346,7 +369,7 @@ module Sprockets
|
|
346
369
|
end
|
347
370
|
|
348
371
|
def raise_unless_precompiled_asset(path)
|
349
|
-
raise Helper::AssetNotPrecompiled.new(path)
|
372
|
+
raise Helper::AssetNotPrecompiled.new(path) if @check_precompiled_asset && !precompiled?(path)
|
350
373
|
end
|
351
374
|
end
|
352
375
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Rails
|
3
|
+
class QuietAssets
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
@assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env['PATH_INFO'] =~ @assets_regex
|
11
|
+
::Rails.logger.silence { @app.call(env) }
|
12
|
+
else
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/sprockets/rails/task.rb
CHANGED
data/lib/sprockets/railtie.rb
CHANGED
@@ -6,6 +6,7 @@ require 'active_support/core_ext/numeric/bytes'
|
|
6
6
|
require 'sprockets'
|
7
7
|
require 'sprockets/rails/context'
|
8
8
|
require 'sprockets/rails/helper'
|
9
|
+
require 'sprockets/rails/quiet_assets'
|
9
10
|
require 'sprockets/rails/route_wrapper'
|
10
11
|
require 'sprockets/rails/version'
|
11
12
|
require 'set'
|
@@ -66,9 +67,24 @@ module Sprockets
|
|
66
67
|
class Railtie < ::Rails::Railtie
|
67
68
|
include Sprockets::Rails::Utils
|
68
69
|
|
70
|
+
class ManifestNeededError < StandardError
|
71
|
+
def initialize
|
72
|
+
msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" +
|
73
|
+
"But did not, please create this file and use it to link any assets that need\n" +
|
74
|
+
"to be rendered by your app:\n\n" +
|
75
|
+
"Example:\n" +
|
76
|
+
" //= link_tree ../images\n" +
|
77
|
+
" //= link_directory ../javascripts .js\n" +
|
78
|
+
" //= link_directory ../stylesheets .css\n" +
|
79
|
+
"and restart your server\n\n" +
|
80
|
+
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
|
81
|
+
super msg
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
69
85
|
LOOSE_APP_ASSETS = lambda do |logical_path, filename|
|
70
|
-
|
71
|
-
|
86
|
+
filename.start_with?(::Rails.root.join("app/assets").to_s) &&
|
87
|
+
!['.js', '.css', ''].include?(File.extname(logical_path))
|
72
88
|
end
|
73
89
|
|
74
90
|
class OrderedOptions < ActiveSupport::OrderedOptions
|
@@ -80,18 +96,34 @@ module Sprockets
|
|
80
96
|
config.assets = OrderedOptions.new
|
81
97
|
config.assets._blocks = []
|
82
98
|
config.assets.paths = []
|
99
|
+
config.assets.precompile = []
|
83
100
|
config.assets.prefix = "/assets"
|
84
101
|
config.assets.manifest = nil
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
102
|
+
config.assets.quiet = false
|
103
|
+
|
104
|
+
initializer :set_default_precompile do |app|
|
105
|
+
if using_sprockets4?
|
106
|
+
raise ManifestNeededError unless ::Rails.root.join("app/assets/config/manifest.js").exist?
|
107
|
+
app.config.assets.precompile += %w( manifest.js )
|
108
|
+
else
|
109
|
+
app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
|
110
|
+
end
|
89
111
|
end
|
112
|
+
|
113
|
+
initializer :quiet_assets do |app|
|
114
|
+
if app.config.assets.quiet
|
115
|
+
app.middleware.insert_before ::Rails::Rack::Logger, ::Sprockets::Rails::QuietAssets
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
90
119
|
config.assets.version = ""
|
91
120
|
config.assets.debug = false
|
92
121
|
config.assets.compile = true
|
93
122
|
config.assets.digest = true
|
94
123
|
config.assets.cache_limit = 50.megabytes
|
124
|
+
config.assets.gzip = true
|
125
|
+
config.assets.check_precompiled_asset = true
|
126
|
+
config.assets.unknown_asset_fallback = true
|
95
127
|
|
96
128
|
config.assets.configure do |env|
|
97
129
|
config.assets.paths.each { |path| env.append_path(path) }
|
@@ -124,6 +156,10 @@ module Sprockets
|
|
124
156
|
env.version = config.assets.version
|
125
157
|
end
|
126
158
|
|
159
|
+
config.assets.configure do |env|
|
160
|
+
env.gzip = config.assets.gzip if env.respond_to?(:gzip=)
|
161
|
+
end
|
162
|
+
|
127
163
|
rake_tasks do |app|
|
128
164
|
require 'sprockets/rails/task'
|
129
165
|
Sprockets::Rails::Task.new(app)
|
@@ -210,6 +246,8 @@ module Sprockets
|
|
210
246
|
|
211
247
|
self.resolve_assets_with = config.assets.resolve_with
|
212
248
|
|
249
|
+
self.check_precompiled_asset = config.assets.check_precompiled_asset
|
250
|
+
self.unknown_asset_fallback = config.assets.unknown_asset_fallback
|
213
251
|
# Expose the app precompiled asset check to the view
|
214
252
|
self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path }
|
215
253
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email: josh@joshpeek.com
|
113
113
|
executables: []
|
114
114
|
extensions: []
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/sprockets/rails.rb
|
120
120
|
- lib/sprockets/rails/context.rb
|
121
121
|
- lib/sprockets/rails/helper.rb
|
122
|
+
- lib/sprockets/rails/quiet_assets.rb
|
122
123
|
- lib/sprockets/rails/route_wrapper.rb
|
123
124
|
- lib/sprockets/rails/task.rb
|
124
125
|
- lib/sprockets/rails/utils.rb
|
@@ -128,7 +129,7 @@ homepage: https://github.com/rails/sprockets-rails
|
|
128
129
|
licenses:
|
129
130
|
- MIT
|
130
131
|
metadata: {}
|
131
|
-
post_install_message:
|
132
|
+
post_install_message:
|
132
133
|
rdoc_options: []
|
133
134
|
require_paths:
|
134
135
|
- lib
|
@@ -143,9 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
- !ruby/object:Gem::Version
|
144
145
|
version: '0'
|
145
146
|
requirements: []
|
146
|
-
|
147
|
-
|
148
|
-
signing_key:
|
147
|
+
rubygems_version: 3.1.2
|
148
|
+
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Sprockets Rails integration
|
151
151
|
test_files: []
|