non-digest-assets 1.0.10
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 +7 -0
- data/LICENSE +23 -0
- data/README.md +56 -0
- data/lib/non-digest-assets.rb +51 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a6f2e6bcaaa60b866e82924300c9790b2d5e9e343b08ac64e10887b877faec9
|
4
|
+
data.tar.gz: 565990905711447148dba9b25d400786f11fc08b8f8034811132ae15da46e12a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3d71ebaeb3118d2cd1bfc9211f5f780ebfab7068f3210ce791092fa88b6c3911028089ad5ef7fa4e0e0730beba162d3aa0b70b056c17240e23889e21d2c688b
|
7
|
+
data.tar.gz: e6d6b2218de83949c7dd82dc89f9b14970eb40df649cc913487d2ab1e693b76ef7009b7c182dd885b027740688691b23c583fa4a534847b9ff77651daef627e0
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Alex Speller
|
4
|
+
Copyright (c) 2018 Matijs van Zuijlen
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Non-digest assets in Rails 4 and 5
|
2
|
+
==================================
|
3
|
+
|
4
|
+
What is it?
|
5
|
+
-----------
|
6
|
+
|
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.
|
11
|
+
|
12
|
+
How do I install it?
|
13
|
+
--------------------
|
14
|
+
|
15
|
+
Just put it in your Gemfile
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem "non-digest-assets"
|
19
|
+
```
|
20
|
+
|
21
|
+
If you want to whitelist non-digest assets for only certain files, you can configure a whitelist like this:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/initializers/non_digest_assets.rb
|
25
|
+
|
26
|
+
NonDigestAssets.whitelist += [/tinymce\/.*/, "image.png"]
|
27
|
+
```
|
28
|
+
|
29
|
+
Be sure to give either a regex that will match the right assets or the logical path of the asset in question.
|
30
|
+
|
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`
|
32
|
+
|
33
|
+
But shouldn't I always use the Rails asset helpers anyway?
|
34
|
+
----------------------------------------------------------
|
35
|
+
|
36
|
+
Yes. But there are some obvious cases where you can't do this:
|
37
|
+
|
38
|
+
* Third party libraries in `vendor/assets` that need to include e.g. css / images
|
39
|
+
* In a static error page, e.g. a 404 page or a 500 page
|
40
|
+
* Referencing the assets from outside your rails application
|
41
|
+
|
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.
|
45
|
+
|
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.
|
47
|
+
|
48
|
+
Why do I need digest assets at all?
|
49
|
+
-----------------------------------
|
50
|
+
|
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.
|
52
|
+
|
53
|
+
Why is this not the default or a config option in Rails 4 and 5?
|
54
|
+
----------------------------------------------------------------
|
55
|
+
|
56
|
+
The sprockets-rails developers do not want to support it. [Read the discussion here](https://github.com/rails/sprockets-rails/issues/49)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "sprockets/manifest"
|
2
|
+
|
3
|
+
module NonDigestAssets
|
4
|
+
mattr_accessor :whitelist
|
5
|
+
@@whitelist = []
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def assets(assets)
|
9
|
+
return assets if whitelist.empty?
|
10
|
+
whitelisted_assets(assets)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
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
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module CompileWithNonDigest
|
25
|
+
def compile *args
|
26
|
+
paths = super
|
27
|
+
NonDigestAssets.assets(assets).each do |(logical_path, digest_path)|
|
28
|
+
full_digest_path = File.join dir, digest_path
|
29
|
+
full_digest_gz_path = "#{full_digest_path}.gz"
|
30
|
+
full_non_digest_path = File.join dir, logical_path
|
31
|
+
full_non_digest_gz_path = "#{full_non_digest_path}.gz"
|
32
|
+
|
33
|
+
if File.exists? full_digest_path
|
34
|
+
logger.debug "Writing #{full_non_digest_path}"
|
35
|
+
FileUtils.copy_file full_digest_path, full_non_digest_path, :preserve_attributes
|
36
|
+
else
|
37
|
+
logger.debug "Could not find: #{full_digest_path}"
|
38
|
+
end
|
39
|
+
if File.exists? full_digest_gz_path
|
40
|
+
logger.debug "Writing #{full_non_digest_gz_path}"
|
41
|
+
FileUtils.copy_file full_digest_gz_path, full_non_digest_gz_path, :preserve_attributes
|
42
|
+
else
|
43
|
+
logger.debug "Could not find: #{full_digest_gz_path}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
paths
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Sprockets::Manifest.send(:prepend, NonDigestAssets::CompileWithNonDigest)
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: non-digest-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Speller
|
8
|
+
- Matijs van Zuijlen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-06-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sprockets
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '12.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '12.0'
|
42
|
+
description: |2
|
43
|
+
Rails 4 and 5 provide no option to generate both digest and non-digest
|
44
|
+
assets. Installing this gem automatically creates both digest and
|
45
|
+
non-digest assets which are useful for many reasons.
|
46
|
+
email:
|
47
|
+
- matijs@matijs.net
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- lib/non-digest-assets.rb
|
55
|
+
homepage: http://github.com/mvz/non-digest-assets
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.7.6
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Fix the Rails 4 and 5 asset pipeline to generate non-digest along with digest
|
79
|
+
assets
|
80
|
+
test_files: []
|