Skip to content

Commit 4fc5380

Browse files
authored
Merge pull request #2430 from adnotam/iss2426
Integrate non_stupid_digest_assets gem
2 parents 4c0e923 + b6a4bb8 commit 4fc5380

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

alchemy_cms.gemspec

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Gem::Specification.new do |gem|
4545
gem.add_runtime_dependency "jquery-ui-rails", ["~> 6.0"]
4646
gem.add_runtime_dependency "kaminari", ["~> 1.1"]
4747
gem.add_runtime_dependency "originator", ["~> 3.1"]
48-
gem.add_runtime_dependency "non-stupid-digest-assets", ["~> 1.0.8"]
4948
gem.add_runtime_dependency "ransack", [">= 1.8", "< 4.0"]
5049
gem.add_runtime_dependency "request_store", ["~> 1.2"]
5150
gem.add_runtime_dependency "responders", [">= 2.0", "< 4.0"]

lib/alchemy_cms.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
require "jquery-rails"
1616
require "jquery-ui-rails"
1717
require "kaminari"
18-
require "non-stupid-digest-assets"
18+
require "non_stupid_digest_assets"
1919
require "ransack"
2020
require "request_store"
2121
require "responders"

lib/non_stupid_digest_assets.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require "sprockets/manifest"
4+
5+
module NonStupidDigestAssets
6+
mattr_accessor :whitelist
7+
@@whitelist = []
8+
9+
class << self
10+
def assets(assets)
11+
return assets if whitelist.empty?
12+
13+
whitelisted_assets(assets)
14+
end
15+
16+
private
17+
18+
def whitelisted_assets(assets)
19+
assets.select do |logical_path, _digest_path|
20+
whitelist.any? do |item|
21+
item == logical_path
22+
end
23+
end
24+
end
25+
end
26+
27+
module CompileWithNonDigest
28+
def compile(*args)
29+
paths = super
30+
NonStupidDigestAssets.assets(assets).each do |(logical_path, digest_path)|
31+
full_digest_path = File.join dir, digest_path
32+
full_digest_gz_path = "#{full_digest_path}.gz"
33+
full_non_digest_path = File.join dir, logical_path
34+
full_non_digest_gz_path = "#{full_non_digest_path}.gz"
35+
36+
if File.exist? full_digest_path
37+
logger.debug "Writing #{full_non_digest_path}"
38+
FileUtils.copy_file full_digest_path, full_non_digest_path, :preserve_attributes
39+
else
40+
logger.debug "Could not find: #{full_digest_path}"
41+
end
42+
if File.exist? full_digest_gz_path
43+
logger.debug "Writing #{full_non_digest_gz_path}"
44+
FileUtils.copy_file full_digest_gz_path, full_non_digest_gz_path, :preserve_attributes
45+
else
46+
logger.debug "Could not find: #{full_digest_gz_path}"
47+
end
48+
end
49+
paths
50+
end
51+
end
52+
end
53+
54+
Sprockets::Manifest.prepend NonStupidDigestAssets::CompileWithNonDigest

0 commit comments

Comments
 (0)