non-digest-assets 1.0.10 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -14
- data/lib/non-digest-assets.rb +20 -7
- metadata +141 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80b93df0270935cdbe8ba8922096e751837547f208016155a29de165eb1f9d44
|
4
|
+
data.tar.gz: fe54746fafaaa49f88054d94c4226de043342ad1df2687e3aa7e03ba64781a6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb7ffc2fa8215502b35c300aa964bd7238905f726ed9b9db8952c5b6dd2ce86a6e176a64c06501ec694223b4daa39f5269477e33916b351b74eaf47588293afb
|
7
|
+
data.tar.gz: 713d3227fc6444a26dfdba5f788d3d670cd7392783287b6608705c3e92e86582dbccb169d034fba8d91962abd80fbe5b8f542f8c191a74f72c82d26e890d7698
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
Non-digest assets in Rails
|
2
|
-
|
1
|
+
Non-digest assets in Rails
|
2
|
+
==========================
|
3
3
|
|
4
4
|
What is it?
|
5
5
|
-----------
|
6
6
|
|
7
|
-
In Rails
|
8
|
-
non-digest assets. This is problematic if you also need to refer to
|
9
|
-
outside your Rails application. This gem solves the problem with the
|
10
|
-
possible effort.
|
7
|
+
In Rails starting from version 4, there is no way to by default compile both
|
8
|
+
digest and non-digest assets. This is problematic if you also need to refer to
|
9
|
+
assets from outside your Rails application. This gem solves the problem with the
|
10
|
+
minimum possible effort.
|
11
11
|
|
12
12
|
How do I install it?
|
13
13
|
--------------------
|
@@ -18,7 +18,8 @@ Just put it in your Gemfile
|
|
18
18
|
gem "non-digest-assets"
|
19
19
|
```
|
20
20
|
|
21
|
-
If you want to whitelist non-digest assets for only certain files, you can
|
21
|
+
If you want to whitelist non-digest assets for only certain files, you can
|
22
|
+
configure a whitelist like this:
|
22
23
|
|
23
24
|
```ruby
|
24
25
|
# config/initializers/non_digest_assets.rb
|
@@ -26,9 +27,11 @@ If you want to whitelist non-digest assets for only certain files, you can confi
|
|
26
27
|
NonDigestAssets.whitelist += [/tinymce\/.*/, "image.png"]
|
27
28
|
```
|
28
29
|
|
29
|
-
Be sure to give either a regex that will match the right assets or the logical
|
30
|
+
Be sure to give either a regex that will match the right assets or the logical
|
31
|
+
path of the asset in question.
|
30
32
|
|
31
|
-
Note that the logical path is what you would provide to `asset_url`, so for an
|
33
|
+
Note that the logical path is what you would provide to `asset_url`, so for an
|
34
|
+
image at `RAILS_ROOT/assets/images/foo.png` the logical path is `foo.png`
|
32
35
|
|
33
36
|
But shouldn't I always use the Rails asset helpers anyway?
|
34
37
|
----------------------------------------------------------
|
@@ -41,16 +44,38 @@ Yes. But there are some obvious cases where you can't do this:
|
|
41
44
|
|
42
45
|
What about other solutions?
|
43
46
|
--------------------------
|
44
|
-
[sprockets-redirect](https://github.com/sikachu/sprockets-redirect) uses a rack
|
47
|
+
[sprockets-redirect](https://github.com/sikachu/sprockets-redirect) uses a rack
|
48
|
+
middleware to 302 redirect to the digest asset. This is terrible for
|
49
|
+
performance because it requires 2 HTTP requests, and it also hits your ruby
|
50
|
+
stack. An asset request should be handled by your webserver (e.g. nginx)
|
51
|
+
because that's what it's good at.
|
45
52
|
|
46
|
-
[This rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134)
|
53
|
+
[This rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134)
|
54
|
+
will solve this problem, but requires an extra rake task. It won't work by
|
55
|
+
default with things like capistrano / heroku. And it requires you to manage the
|
56
|
+
code in your app.
|
47
57
|
|
48
58
|
Why do I need digest assets at all?
|
49
59
|
-----------------------------------
|
50
60
|
|
51
|
-
Digests are used for cache busting. Remember that if you use the non-digest
|
61
|
+
Digests are used for cache busting. Remember that if you use the non-digest
|
62
|
+
assets and serve them with far-future expires headers, you will cause problems
|
63
|
+
with cached assets if the contents ever need to change. You must bear this in
|
64
|
+
mind when using non-digest assets.
|
52
65
|
|
53
|
-
Why is this not the default or a config option in Rails
|
66
|
+
Why is this not the default or a config option in Rails?
|
54
67
|
----------------------------------------------------------------
|
55
68
|
|
56
|
-
The sprockets-rails developers do not want to support it.
|
69
|
+
The sprockets-rails developers do not want to support it.
|
70
|
+
[Read the discussion here](https://github.com/rails/sprockets-rails/issues/49)
|
71
|
+
|
72
|
+
Which versions of Ruby and Rails are supported?
|
73
|
+
--------------------------------------
|
74
|
+
|
75
|
+
This gem is tested with Rails 5.0, 5.1, 5.2 and 6.0 and targets Ruby 2.4 and up.
|
76
|
+
|
77
|
+
Who wrote this?
|
78
|
+
---------------
|
79
|
+
|
80
|
+
This gem was created under a different name by Alex Speller and is currently
|
81
|
+
maintained by Matijs van Zuijlen.
|
data/lib/non-digest-assets.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "sprockets/manifest"
|
4
|
+
require "active_support/core_ext/module/attribute_accessors"
|
2
5
|
|
3
6
|
module NonDigestAssets
|
4
7
|
mattr_accessor :whitelist
|
@@ -7,13 +10,14 @@ module NonDigestAssets
|
|
7
10
|
class << self
|
8
11
|
def assets(assets)
|
9
12
|
return assets if whitelist.empty?
|
13
|
+
|
10
14
|
whitelisted_assets(assets)
|
11
15
|
end
|
12
16
|
|
13
17
|
private
|
14
18
|
|
15
19
|
def whitelisted_assets(assets)
|
16
|
-
assets.select do |logical_path,
|
20
|
+
assets.select do |logical_path, _digest_path|
|
17
21
|
whitelist.any? do |item|
|
18
22
|
item === logical_path
|
19
23
|
end
|
@@ -22,7 +26,15 @@ module NonDigestAssets
|
|
22
26
|
end
|
23
27
|
|
24
28
|
module CompileWithNonDigest
|
25
|
-
|
29
|
+
# Copy an asset and preserve atime and mtime attributes. If the file exists
|
30
|
+
# and is not owned by the calling user, the utime call will fail so we just
|
31
|
+
# delete the target file first in any case.
|
32
|
+
def copy_file(from, to)
|
33
|
+
FileUtils.rm_f to
|
34
|
+
FileUtils.copy_file from, to, :preserve_attributes
|
35
|
+
end
|
36
|
+
|
37
|
+
def compile(*args)
|
26
38
|
paths = super
|
27
39
|
NonDigestAssets.assets(assets).each do |(logical_path, digest_path)|
|
28
40
|
full_digest_path = File.join dir, digest_path
|
@@ -30,22 +42,23 @@ module NonDigestAssets
|
|
30
42
|
full_non_digest_path = File.join dir, logical_path
|
31
43
|
full_non_digest_gz_path = "#{full_non_digest_path}.gz"
|
32
44
|
|
33
|
-
if File.
|
45
|
+
if File.exist? full_digest_path
|
34
46
|
logger.debug "Writing #{full_non_digest_path}"
|
35
|
-
|
47
|
+
copy_file full_digest_path, full_non_digest_path
|
36
48
|
else
|
37
49
|
logger.debug "Could not find: #{full_digest_path}"
|
38
50
|
end
|
39
|
-
if File.
|
51
|
+
if File.exist? full_digest_gz_path
|
40
52
|
logger.debug "Writing #{full_non_digest_gz_path}"
|
41
|
-
|
53
|
+
copy_file full_digest_gz_path, full_non_digest_gz_path
|
42
54
|
else
|
43
55
|
logger.debug "Could not find: #{full_digest_gz_path}"
|
44
56
|
end
|
45
57
|
end
|
58
|
+
|
46
59
|
paths
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
50
63
|
|
51
|
-
Sprockets::Manifest.
|
64
|
+
Sprockets::Manifest.prepend NonDigestAssets::CompileWithNonDigest
|
metadata
CHANGED
@@ -1,16 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: non-digest-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Speller
|
8
8
|
- Matijs van Zuijlen
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '6.2'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '4.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.2'
|
14
34
|
- !ruby/object:Gem::Dependency
|
15
35
|
name: sprockets
|
16
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -18,6 +38,9 @@ dependencies:
|
|
18
38
|
- - ">="
|
19
39
|
- !ruby/object:Gem::Version
|
20
40
|
version: '2.0'
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.0'
|
21
44
|
type: :runtime
|
22
45
|
prerelease: false
|
23
46
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -25,22 +48,129 @@ dependencies:
|
|
25
48
|
- - ">="
|
26
49
|
- !ruby/object:Gem::Version
|
27
50
|
version: '2.0'
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5.0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: appraisal
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.3'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.3'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: aruba
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: pry
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.14.0
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.14.0
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rails
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '5.0'
|
103
|
+
- - "<"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '6.2'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '5.0'
|
113
|
+
- - "<"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '6.2'
|
28
116
|
- !ruby/object:Gem::Dependency
|
29
117
|
name: rake
|
30
118
|
requirement: !ruby/object:Gem::Requirement
|
31
119
|
requirements:
|
32
120
|
- - "~>"
|
33
121
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
122
|
+
version: '13.0'
|
123
|
+
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '13.0'
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
name: rspec
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '3.10'
|
137
|
+
type: :development
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '3.10'
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: rubocop
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.12.0
|
151
|
+
type: :development
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.12.0
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: rubocop-performance
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - "~>"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: 1.10.0
|
35
165
|
type: :development
|
36
166
|
prerelease: false
|
37
167
|
version_requirements: !ruby/object:Gem::Requirement
|
38
168
|
requirements:
|
39
169
|
- - "~>"
|
40
170
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
171
|
+
version: 1.10.0
|
42
172
|
description: |2
|
43
|
-
Rails
|
173
|
+
Rails provides no option to generate both digest and non-digest
|
44
174
|
assets. Installing this gem automatically creates both digest and
|
45
175
|
non-digest assets which are useful for many reasons.
|
46
176
|
email:
|
@@ -56,7 +186,7 @@ homepage: http://github.com/mvz/non-digest-assets
|
|
56
186
|
licenses:
|
57
187
|
- MIT
|
58
188
|
metadata: {}
|
59
|
-
post_install_message:
|
189
|
+
post_install_message:
|
60
190
|
rdoc_options: []
|
61
191
|
require_paths:
|
62
192
|
- lib
|
@@ -64,17 +194,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
194
|
requirements:
|
65
195
|
- - ">="
|
66
196
|
- !ruby/object:Gem::Version
|
67
|
-
version: '2.
|
197
|
+
version: '2.4'
|
68
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
199
|
requirements:
|
70
200
|
- - ">="
|
71
201
|
- !ruby/object:Gem::Version
|
72
202
|
version: '0'
|
73
203
|
requirements: []
|
74
|
-
|
75
|
-
|
76
|
-
signing_key:
|
204
|
+
rubygems_version: 3.2.3
|
205
|
+
signing_key:
|
77
206
|
specification_version: 4
|
78
|
-
summary:
|
79
|
-
assets
|
207
|
+
summary: Make the Rails asset pipeline generate non-digest along with digest assets
|
80
208
|
test_files: []
|