-
Notifications
You must be signed in to change notification settings - Fork 87
/
non-stupid-digest-assets.rb
51 lines (44 loc) · 1.46 KB
/
non-stupid-digest-assets.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "sprockets/manifest"
module NonStupidDigestAssets
mattr_accessor :whitelist
@@whitelist = []
class << self
def assets(assets)
return assets if whitelist.empty?
whitelisted_assets(assets)
end
private
def whitelisted_assets(assets)
assets.select do |logical_path, digest_path|
whitelist.any? do |item|
item === logical_path
end
end
end
end
module CompileWithNonDigest
def compile *args
paths = super
NonStupidDigestAssets.assets(assets).each do |(logical_path, digest_path)|
full_digest_path = File.join dir, digest_path
full_digest_gz_path = "#{full_digest_path}.gz"
full_non_digest_path = File.join dir, logical_path
full_non_digest_gz_path = "#{full_non_digest_path}.gz"
if File.exist? full_digest_path
logger.debug "Writing #{full_non_digest_path}"
FileUtils.copy_file full_digest_path, full_non_digest_path, :preserve_attributes
else
logger.debug "Could not find: #{full_digest_path}"
end
if File.exist? full_digest_gz_path
logger.debug "Writing #{full_non_digest_gz_path}"
FileUtils.copy_file full_digest_gz_path, full_non_digest_gz_path, :preserve_attributes
else
logger.debug "Could not find: #{full_digest_gz_path}"
end
end
paths
end
end
end
Sprockets::Manifest.send(:prepend, NonStupidDigestAssets::CompileWithNonDigest)