sprockets-rails 3.1.1 → 3.3.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 +5 -5
- data/README.md +14 -4
- data/lib/sprockets/rails/asset_url_processor.rb +15 -0
- data/lib/sprockets/rails/context.rb +1 -1
- data/lib/sprockets/rails/helper.rb +33 -7
- data/lib/sprockets/rails/task.rb +0 -1
- data/lib/sprockets/rails/version.rb +1 -1
- data/lib/sprockets/railtie.rb +15 -7
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7e6cad3e417e1aa7ebb1d631d729eece508df7a9e7532d345402c4f5ea74b232
|
4
|
+
data.tar.gz: aff71fbf71de696753d98af6268b3f3325614dab7a9a3bcbc703a97c42f3843d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 779b26e279a0ae753c72f3b96281e3693a98701890064c23d769759cff66f4ad4b5500b8e271e8b1152cda74bafb5757c6c446b62f4d72f4bb7b41bd227136b0
|
7
|
+
data.tar.gz: bb5310789f00b8656f13e16473277efbb575aeedd81c10d4b9410e78af0372ce14ab71860c826bca6bfd6e5e8cb5bf9325fc98646d432b36890f25053b6c7eff
|
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`.
|
@@ -135,7 +138,7 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
135
138
|
* [coffee-rails](https://github.com/rails/coffee-rails)
|
136
139
|
* [sass-rails](https://github.com/rails/sass-rails)
|
137
140
|
|
138
|
-
**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.
|
139
142
|
|
140
143
|
|
141
144
|
## Changes from Rails 3.x
|
@@ -147,6 +150,15 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
147
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.
|
148
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.
|
149
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/`.
|
161
|
+
|
150
162
|
## Experimental
|
151
163
|
|
152
164
|
### [SRI](http://www.w3.org/TR/SRI/) support
|
@@ -184,6 +196,4 @@ Sprockets Rails is released under the [MIT License](MIT-LICENSE).
|
|
184
196
|
|
185
197
|
## Code Status
|
186
198
|
|
187
|
-
* [](http://travis-ci.org/rails/sprockets-rails)
|
188
199
|
* [](http://badge.fury.io/rb/sprockets-rails)
|
189
|
-
* [](https://gemnasium.com/rails/sprockets-rails)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Rails
|
3
|
+
# Rewrites urls in CSS files with the digested paths
|
4
|
+
class AssetUrlProcessor
|
5
|
+
REGEX = /url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/
|
6
|
+
|
7
|
+
def self.call(input)
|
8
|
+
context = input[:environment].context_class.new(input)
|
9
|
+
data = input[:data].gsub(REGEX) { |_match| "url(#{context.asset_path($1)})" }
|
10
|
+
|
11
|
+
{ data: data }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -6,14 +6,17 @@ 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
17
|
"Asset `#{ source }` was not declared to be precompiled in production.\n" +
|
15
18
|
"Declare links to your assets in `app/assets/config/manifest.js`.\n\n" +
|
16
|
-
" //= link #{ source }\n" +
|
19
|
+
" //= link #{ source }\n\n" +
|
17
20
|
"and restart your server"
|
18
21
|
else
|
19
22
|
"Asset was not declared to be precompiled in production.\n" +
|
@@ -33,7 +36,8 @@ module Sprockets
|
|
33
36
|
:assets_environment, :assets_manifest,
|
34
37
|
:assets_precompile, :precompiled_asset_checker,
|
35
38
|
:assets_prefix, :digest_assets, :debug_assets,
|
36
|
-
:resolve_assets_with, :check_precompiled_asset
|
39
|
+
:resolve_assets_with, :check_precompiled_asset,
|
40
|
+
:unknown_asset_fallback
|
37
41
|
]
|
38
42
|
|
39
43
|
def self.included(klass)
|
@@ -54,7 +58,7 @@ module Sprockets
|
|
54
58
|
end
|
55
59
|
|
56
60
|
def self.extended(obj)
|
57
|
-
obj.class_eval do
|
61
|
+
obj.singleton_class.class_eval do
|
58
62
|
attr_accessor(*VIEW_ACCESSORS)
|
59
63
|
|
60
64
|
remove_method :assets_environment
|
@@ -68,12 +72,26 @@ module Sprockets
|
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
75
|
+
# Writes over the built in ActionView::Helpers::AssetUrlHelper#compute_asset_path
|
76
|
+
# to use the asset pipeline.
|
71
77
|
def compute_asset_path(path, options = {})
|
72
78
|
debug = options[:debug]
|
73
79
|
|
74
80
|
if asset_path = resolve_asset_path(path, debug)
|
75
81
|
File.join(assets_prefix || "/", legacy_debug_path(asset_path, debug))
|
76
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
|
77
95
|
super
|
78
96
|
end
|
79
97
|
end
|
@@ -334,8 +352,16 @@ module Sprockets
|
|
334
352
|
end
|
335
353
|
|
336
354
|
private
|
337
|
-
|
338
|
-
|
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
|
339
365
|
end
|
340
366
|
|
341
367
|
def precompiled?(path)
|
@@ -343,7 +369,7 @@ module Sprockets
|
|
343
369
|
end
|
344
370
|
|
345
371
|
def raise_unless_precompiled_asset(path)
|
346
|
-
raise Helper::
|
372
|
+
raise Helper::AssetNotPrecompiledError.new(path) if @check_precompiled_asset && !precompiled?(path)
|
347
373
|
end
|
348
374
|
end
|
349
375
|
end
|
data/lib/sprockets/rails/task.rb
CHANGED
data/lib/sprockets/railtie.rb
CHANGED
@@ -4,6 +4,8 @@ require 'action_controller/railtie'
|
|
4
4
|
require 'active_support/core_ext/module/remove_method'
|
5
5
|
require 'active_support/core_ext/numeric/bytes'
|
6
6
|
require 'sprockets'
|
7
|
+
|
8
|
+
require 'sprockets/rails/asset_url_processor'
|
7
9
|
require 'sprockets/rails/context'
|
8
10
|
require 'sprockets/rails/helper'
|
9
11
|
require 'sprockets/rails/quiet_assets'
|
@@ -76,14 +78,15 @@ module Sprockets
|
|
76
78
|
" //= link_tree ../images\n" +
|
77
79
|
" //= link_directory ../javascripts .js\n" +
|
78
80
|
" //= link_directory ../stylesheets .css\n" +
|
79
|
-
"and restart your server"
|
81
|
+
"and restart your server\n\n" +
|
82
|
+
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
|
80
83
|
super msg
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
84
87
|
LOOSE_APP_ASSETS = lambda do |logical_path, filename|
|
85
|
-
|
86
|
-
|
88
|
+
filename.start_with?(::Rails.root.join("app/assets").to_s) &&
|
89
|
+
!['.js', '.css', ''].include?(File.extname(logical_path))
|
87
90
|
end
|
88
91
|
|
89
92
|
class OrderedOptions < ActiveSupport::OrderedOptions
|
@@ -102,10 +105,10 @@ module Sprockets
|
|
102
105
|
|
103
106
|
initializer :set_default_precompile do |app|
|
104
107
|
if using_sprockets4?
|
105
|
-
raise ManifestNeededError
|
106
|
-
app.config.assets.precompile
|
108
|
+
raise ManifestNeededError unless ::Rails.root.join("app/assets/config/manifest.js").exist?
|
109
|
+
app.config.assets.precompile += %w( manifest.js )
|
107
110
|
else
|
108
|
-
app.config.assets.precompile
|
111
|
+
app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
|
109
112
|
end
|
110
113
|
end
|
111
114
|
|
@@ -115,6 +118,10 @@ module Sprockets
|
|
115
118
|
end
|
116
119
|
end
|
117
120
|
|
121
|
+
initializer :asset_url_processor do |app|
|
122
|
+
Sprockets.register_postprocessor "text/css", ::Sprockets::Rails::AssetUrlProcessor
|
123
|
+
end
|
124
|
+
|
118
125
|
config.assets.version = ""
|
119
126
|
config.assets.debug = false
|
120
127
|
config.assets.compile = true
|
@@ -122,6 +129,7 @@ module Sprockets
|
|
122
129
|
config.assets.cache_limit = 50.megabytes
|
123
130
|
config.assets.gzip = true
|
124
131
|
config.assets.check_precompiled_asset = true
|
132
|
+
config.assets.unknown_asset_fallback = true
|
125
133
|
|
126
134
|
config.assets.configure do |env|
|
127
135
|
config.assets.paths.each { |path| env.append_path(path) }
|
@@ -245,7 +253,7 @@ module Sprockets
|
|
245
253
|
self.resolve_assets_with = config.assets.resolve_with
|
246
254
|
|
247
255
|
self.check_precompiled_asset = config.assets.check_precompiled_asset
|
248
|
-
|
256
|
+
self.unknown_asset_fallback = config.assets.unknown_asset_fallback
|
249
257
|
# Expose the app precompiled asset check to the view
|
250
258
|
self.precompiled_asset_checker = -> logical_path { app.asset_precompiled? logical_path }
|
251
259
|
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.3.0
|
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: 2021-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '5.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '5.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: railties
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '5.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '5.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: []
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- MIT-LICENSE
|
118
118
|
- README.md
|
119
119
|
- lib/sprockets/rails.rb
|
120
|
+
- lib/sprockets/rails/asset_url_processor.rb
|
120
121
|
- lib/sprockets/rails/context.rb
|
121
122
|
- lib/sprockets/rails/helper.rb
|
122
123
|
- lib/sprockets/rails/quiet_assets.rb
|
@@ -129,7 +130,7 @@ homepage: https://github.com/rails/sprockets-rails
|
|
129
130
|
licenses:
|
130
131
|
- MIT
|
131
132
|
metadata: {}
|
132
|
-
post_install_message:
|
133
|
+
post_install_message:
|
133
134
|
rdoc_options: []
|
134
135
|
require_paths:
|
135
136
|
- lib
|
@@ -137,16 +138,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
138
|
requirements:
|
138
139
|
- - ">="
|
139
140
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
141
|
+
version: '2.5'
|
141
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
143
|
requirements:
|
143
144
|
- - ">="
|
144
145
|
- !ruby/object:Gem::Version
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
|
-
|
148
|
-
|
149
|
-
signing_key:
|
148
|
+
rubygems_version: 3.2.22
|
149
|
+
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: Sprockets Rails integration
|
152
152
|
test_files: []
|