non-digest-assets 1.0.10 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -26
  3. data/lib/non-digest-assets.rb +30 -19
  4. metadata +199 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a6f2e6bcaaa60b866e82924300c9790b2d5e9e343b08ac64e10887b877faec9
4
- data.tar.gz: 565990905711447148dba9b25d400786f11fc08b8f8034811132ae15da46e12a
3
+ metadata.gz: 3a3433ab2d073111ffd8139abb4afe36a14aed99e949b37cd28270b075015c68
4
+ data.tar.gz: 113f6f5ac39816845650f4127cbce739d66feee73225ca124f73209a9631b052
5
5
  SHA512:
6
- metadata.gz: c3d71ebaeb3118d2cd1bfc9211f5f780ebfab7068f3210ce791092fa88b6c3911028089ad5ef7fa4e0e0730beba162d3aa0b70b056c17240e23889e21d2c688b
7
- data.tar.gz: e6d6b2218de83949c7dd82dc89f9b14970eb40df649cc913487d2ab1e693b76ef7009b7c182dd885b027740688691b23c583fa4a534847b9ff77651daef627e0
6
+ metadata.gz: 4a63c8cec3f04af579271975f125b6fd3e4798670965cb187f4e8af9e8d075649d9c9bbbe1aeec72ee6364abfb9894b845a399e1f2b7aceaef0fc76b6be3b3d8
7
+ data.tar.gz: bab17ed7ca819150b17573b501f43368f2f096d2d18080779bf4a00c69cfb801f770ee4a5858de78082505b0c250cf16ff804df2187adf9de87c9f7362f85801
data/README.md CHANGED
@@ -1,16 +1,13 @@
1
- Non-digest assets in Rails 4 and 5
2
- ==================================
1
+ # Non-digest assets in Rails
3
2
 
4
- What is it?
5
- -----------
3
+ ## What is it?
6
4
 
7
- In Rails 4 and 5, there is no way to by default compile both digest and
8
- non-digest assets. This is problematic if you also need to refer to assets from
9
- outside your Rails application. This gem solves the problem with the minimum
10
- possible effort.
5
+ In Rails starting from version 4, there is no way to by default compile both
6
+ digest and non-digest assets. This is problematic if you also need to refer to
7
+ assets from outside your Rails application. This gem solves the problem with the
8
+ minimum possible effort.
11
9
 
12
- How do I install it?
13
- --------------------
10
+ ## How do I install it?
14
11
 
15
12
  Just put it in your Gemfile
16
13
 
@@ -18,20 +15,22 @@ Just put it in your Gemfile
18
15
  gem "non-digest-assets"
19
16
  ```
20
17
 
21
- If you want to whitelist non-digest assets for only certain files, you can configure a whitelist like this:
18
+ If you want to generate non-digest assets for only certain files, you can
19
+ configure a list of asset selectors like this:
22
20
 
23
21
  ```ruby
24
22
  # config/initializers/non_digest_assets.rb
25
23
 
26
- NonDigestAssets.whitelist += [/tinymce\/.*/, "image.png"]
24
+ NonDigestAssets.asset_selectors += [/tinymce\/.*/, "image.png"]
27
25
  ```
28
26
 
29
- Be sure to give either a regex that will match the right assets or the logical path of the asset in question.
27
+ Be sure to give either a regex that will match the right assets or the logical
28
+ path of the asset in question.
30
29
 
31
- Note that the logical path is what you would provide to `asset_url`, so for an image at `RAILS_ROOT/assets/images/foo.png` the logical path is `foo.png`
30
+ Note that the logical path is what you would provide to `asset_url`, so for an
31
+ image at `RAILS_ROOT/assets/images/foo.png` the logical path is `foo.png`
32
32
 
33
- But shouldn't I always use the Rails asset helpers anyway?
34
- ----------------------------------------------------------
33
+ ## But shouldn't I always use the Rails asset helpers anyway?
35
34
 
36
35
  Yes. But there are some obvious cases where you can't do this:
37
36
 
@@ -39,18 +38,41 @@ Yes. But there are some obvious cases where you can't do this:
39
38
  * In a static error page, e.g. a 404 page or a 500 page
40
39
  * Referencing the assets from outside your rails application
41
40
 
42
- What about other solutions?
43
- --------------------------
44
- [sprockets-redirect](https://github.com/sikachu/sprockets-redirect) uses a rack middleware to 302 redirect to the digest asset. This is terrible for performance because it requires 2 HTTP requests, and it also hits your ruby stack. An asset request should be handled by your webserver (e.g. nginx) because that's what it's good at.
41
+ ## What about other solutions?
45
42
 
46
- [This rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134) will solve this problem, but requires an extra rake task. It won't work by default with things like capistrano / heroku. And it requires you to manage the code in your app.
43
+ [sprockets-redirect](https://github.com/sikachu/sprockets-redirect) uses a rack
44
+ middleware to 302 redirect to the digest asset. This is terrible for
45
+ performance because it requires 2 HTTP requests, and it also hits your ruby
46
+ stack. An asset request should be handled by your webserver (e.g. nginx)
47
+ because that's what it's good at.
47
48
 
48
- Why do I need digest assets at all?
49
- -----------------------------------
49
+ [This rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134)
50
+ will solve this problem, but requires an extra rake task. It won't work by
51
+ default with things like capistrano / heroku. And it requires you to manage the
52
+ code in your app.
50
53
 
51
- Digests are used for cache busting. Remember that if you use the non-digest assets and serve them with far-future expires headers, you will cause problems with cached assets if the contents ever need to change. You must bear this in mind when using non-digest assets.
54
+ ## Why do I need digest assets at all?
52
55
 
53
- Why is this not the default or a config option in Rails 4 and 5?
54
- ----------------------------------------------------------------
56
+ Digests are used for cache busting. Remember that if you use the non-digest
57
+ assets and serve them with far-future expires headers, you will cause problems
58
+ with cached assets if the contents ever need to change. You must bear this in
59
+ mind when using non-digest assets.
55
60
 
56
- The sprockets-rails developers do not want to support it. [Read the discussion here](https://github.com/rails/sprockets-rails/issues/49)
61
+ ## Why is this not the default or a config option in Rails?
62
+
63
+ The sprockets-rails developers do not want to support it.
64
+ [Read the discussion here](https://github.com/rails/sprockets-rails/issues/49)
65
+
66
+ ## Which versions of Ruby and Rails are supported?
67
+
68
+ This gem is tested with Rails 5.2, 6.0, 6.1 and 7.0 alpha and targets Ruby 2.6
69
+ and up.
70
+
71
+ ## Who wrote this?
72
+
73
+ This gem was created under a different name by Alex Speller and is currently
74
+ maintained by Matijs van Zuijlen.
75
+
76
+ ## Can I contribute?
77
+
78
+ Certainly. See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
@@ -1,51 +1,62 @@
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
- mattr_accessor :whitelist
5
- @@whitelist = []
7
+ mattr_accessor :asset_selectors
8
+ @@asset_selectors = []
6
9
 
7
10
  class << self
8
- def assets(assets)
9
- return assets if whitelist.empty?
10
- whitelisted_assets(assets)
11
+ def filter_assets(asset_list)
12
+ if asset_selectors.empty?
13
+ asset_list
14
+ else
15
+ asset_list.select do |logical_path, _digest_path|
16
+ asset_selectors.any? do |item|
17
+ item === logical_path
18
+ end
19
+ end
20
+ end
11
21
  end
12
22
 
13
- private
23
+ # Copy an asset and preserve atime and mtime attributes. If the file exists
24
+ # and is not owned by the calling user, the utime call will fail so we just
25
+ # delete the target file first in any case.
26
+ def copy_file(from, to)
27
+ return if from == to
14
28
 
15
- def whitelisted_assets(assets)
16
- assets.select do |logical_path, digest_path|
17
- whitelist.any? do |item|
18
- item === logical_path
19
- end
20
- end
29
+ FileUtils.rm_f to
30
+ FileUtils.copy_file from, to, :preserve_attributes
21
31
  end
22
32
  end
23
33
 
24
34
  module CompileWithNonDigest
25
- def compile *args
35
+ def compile(*args)
26
36
  paths = super
27
- NonDigestAssets.assets(assets).each do |(logical_path, digest_path)|
37
+ NonDigestAssets.filter_assets(assets).each do |(logical_path, digest_path)|
28
38
  full_digest_path = File.join dir, digest_path
29
39
  full_digest_gz_path = "#{full_digest_path}.gz"
30
40
  full_non_digest_path = File.join dir, logical_path
31
41
  full_non_digest_gz_path = "#{full_non_digest_path}.gz"
32
42
 
33
- if File.exists? full_digest_path
43
+ if File.exist? full_digest_path
34
44
  logger.debug "Writing #{full_non_digest_path}"
35
- FileUtils.copy_file full_digest_path, full_non_digest_path, :preserve_attributes
45
+ NonDigestAssets.copy_file full_digest_path, full_non_digest_path
36
46
  else
37
47
  logger.debug "Could not find: #{full_digest_path}"
38
48
  end
39
- if File.exists? full_digest_gz_path
49
+ if File.exist? full_digest_gz_path
40
50
  logger.debug "Writing #{full_non_digest_gz_path}"
41
- FileUtils.copy_file full_digest_gz_path, full_non_digest_gz_path, :preserve_attributes
51
+ NonDigestAssets.copy_file full_digest_gz_path, full_non_digest_gz_path
42
52
  else
43
53
  logger.debug "Could not find: #{full_digest_gz_path}"
44
54
  end
45
55
  end
56
+
46
57
  paths
47
58
  end
48
59
  end
49
60
  end
50
61
 
51
- Sprockets::Manifest.send(:prepend, NonDigestAssets::CompileWithNonDigest)
62
+ 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.10
4
+ version: 2.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: 2018-06-16 00:00:00.000000000 Z
12
+ date: 2021-12-24 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: '5.2'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '7.1'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '5.2'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.1'
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,185 @@ 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: '2.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.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.2'
103
+ - - "<"
104
+ - !ruby/object:Gem::Version
105
+ version: '7.1'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '5.2'
113
+ - - "<"
114
+ - !ruby/object:Gem::Version
115
+ version: '7.1'
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: '12.0'
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.24.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.24.0
158
+ - !ruby/object:Gem::Dependency
159
+ name: rubocop-packaging
160
+ requirement: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: 0.5.1
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: 0.5.1
172
+ - !ruby/object:Gem::Dependency
173
+ name: rubocop-performance
174
+ requirement: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: 1.12.0
179
+ type: :development
180
+ prerelease: false
181
+ version_requirements: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - "~>"
184
+ - !ruby/object:Gem::Version
185
+ version: 1.12.0
186
+ - !ruby/object:Gem::Dependency
187
+ name: rubocop-rails
188
+ requirement: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - "~>"
191
+ - !ruby/object:Gem::Version
192
+ version: 2.12.0
193
+ type: :development
194
+ prerelease: false
195
+ version_requirements: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: 2.12.0
200
+ - !ruby/object:Gem::Dependency
201
+ name: rubocop-rake
202
+ requirement: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: 0.6.0
207
+ type: :development
208
+ prerelease: false
209
+ version_requirements: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: 0.6.0
214
+ - !ruby/object:Gem::Dependency
215
+ name: rubocop-rspec
216
+ requirement: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - "~>"
219
+ - !ruby/object:Gem::Version
220
+ version: 2.6.0
35
221
  type: :development
36
222
  prerelease: false
37
223
  version_requirements: !ruby/object:Gem::Requirement
38
224
  requirements:
39
225
  - - "~>"
40
226
  - !ruby/object:Gem::Version
41
- version: '12.0'
227
+ version: 2.6.0
42
228
  description: |2
43
- Rails 4 and 5 provide no option to generate both digest and non-digest
229
+ Rails provides no option to generate both digest and non-digest
44
230
  assets. Installing this gem automatically creates both digest and
45
231
  non-digest assets which are useful for many reasons.
46
232
  email:
@@ -55,8 +241,9 @@ files:
55
241
  homepage: http://github.com/mvz/non-digest-assets
56
242
  licenses:
57
243
  - MIT
58
- metadata: {}
59
- post_install_message:
244
+ metadata:
245
+ rubygems_mfa_required: 'true'
246
+ post_install_message:
60
247
  rdoc_options: []
61
248
  require_paths:
62
249
  - lib
@@ -64,17 +251,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
251
  requirements:
65
252
  - - ">="
66
253
  - !ruby/object:Gem::Version
67
- version: '2.0'
254
+ version: '2.6'
68
255
  required_rubygems_version: !ruby/object:Gem::Requirement
69
256
  requirements:
70
257
  - - ">="
71
258
  - !ruby/object:Gem::Version
72
259
  version: '0'
73
260
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.7.6
76
- signing_key:
261
+ rubygems_version: 3.2.33
262
+ signing_key:
77
263
  specification_version: 4
78
- summary: Fix the Rails 4 and 5 asset pipeline to generate non-digest along with digest
79
- assets
264
+ summary: Make the Rails asset pipeline generate non-digest along with digest assets
80
265
  test_files: []