mirror of
https://github.com/moebooru/moebooru
synced 2025-08-22 09:57:31 +00:00
Fix digest assets sprocket extension to work with ruby 3.2
This commit is contained in:
parent
389e511660
commit
49201c5de4
2
Gemfile
2
Gemfile
@ -6,8 +6,6 @@ gem "sprockets-rails"
|
|||||||
gem "jsbundling-rails"
|
gem "jsbundling-rails"
|
||||||
gem "terser"
|
gem "terser"
|
||||||
|
|
||||||
gem "non-stupid-digest-assets"
|
|
||||||
|
|
||||||
gem "pg"
|
gem "pg"
|
||||||
|
|
||||||
gem "diff-lcs", require: ['diff-lcs', 'diff/lcs/array']
|
gem "diff-lcs", require: ['diff-lcs', 'diff/lcs/array']
|
||||||
|
@ -123,8 +123,6 @@ GEM
|
|||||||
nokogiri (1.13.10)
|
nokogiri (1.13.10)
|
||||||
mini_portile2 (~> 2.8.0)
|
mini_portile2 (~> 2.8.0)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
non-stupid-digest-assets (1.0.9)
|
|
||||||
sprockets (>= 2.0)
|
|
||||||
pg (1.4.3)
|
pg (1.4.3)
|
||||||
pry (0.14.1)
|
pry (0.14.1)
|
||||||
coderay (~> 1.1)
|
coderay (~> 1.1)
|
||||||
@ -212,7 +210,6 @@ DEPENDENCIES
|
|||||||
mini_mime
|
mini_mime
|
||||||
newrelic_rpm
|
newrelic_rpm
|
||||||
nokogiri
|
nokogiri
|
||||||
non-stupid-digest-assets
|
|
||||||
pg
|
pg
|
||||||
pry
|
pry
|
||||||
puma
|
puma
|
||||||
|
@ -1 +1,4 @@
|
|||||||
|
require 'non_stupid_digest_assets'
|
||||||
|
|
||||||
NonStupidDigestAssets.whitelist = ["404.html", "429.html", "500.html"]
|
NonStupidDigestAssets.whitelist = ["404.html", "429.html", "500.html"]
|
||||||
|
Sprockets::Manifest.send(:prepend, NonStupidDigestAssets::CompileWithNonDigest)
|
||||||
|
53
lib/non_stupid_digest_assets.rb
Normal file
53
lib/non_stupid_digest_assets.rb
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Taken from [1] with file existence check updated to work with ruby 3.2
|
||||||
|
# by renaming `File.exists?` to `File.exist?`.
|
||||||
|
#
|
||||||
|
# [1] https://github.com/alexspeller/non-stupid-digest-assets/blob/cb899cc4bad242c9da7c0ef61d4f9e431e020119/lib/non-stupid-digest-assets.rb
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user