diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2024-01-25 05:38:33 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2024-01-25 05:38:33 +0000 |
commit | c99bb27e27e3c32ca5aa174de238fe3adf089310 (patch) | |
tree | 08c94446e85ecba3bec0167ce4571260fb9652a3 /config/initializers/10-patches.rb | |
parent | f803778cde85c6d58f1e5d8740d3e46852f39a0e (diff) | |
download | redmine-c99bb27e27e3c32ca5aa174de238fe3adf089310.tar.gz redmine-c99bb27e27e3c32ca5aa174de238fe3adf089310.zip |
Add Propshaft library to enable the asset pipeline without modifying existing assets (#39111).
Patch by Takashi Kato (@tohosaku).
git-svn-id: https://svn.redmine.org/redmine/trunk@22626 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'config/initializers/10-patches.rb')
-rw-r--r-- | config/initializers/10-patches.rb | 70 |
1 files changed, 23 insertions, 47 deletions
diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index 933da218e..1d932eb1f 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -147,53 +147,29 @@ end Mime::SET << 'api' -# Adds asset_id parameters to assets like Rails 3 to invalidate caches in browser -module ActionView - module Helpers - module AssetUrlHelper - @@cache_asset_timestamps = Rails.env.production? - @@asset_timestamps_cache = {} - @@asset_timestamps_cache_guard = Mutex.new - - def asset_path_with_asset_id(source, options = {}) - asset_id = rails_asset_id(source, options) - unless asset_id.blank? - source += "?#{asset_id}" - end - asset_path(source, options.merge(skip_pipeline: true)) - end - alias :path_to_asset :asset_path_with_asset_id - - def rails_asset_id(source, options = {}) - if asset_id = ENV["RAILS_ASSET_ID"] - asset_id - else - if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source]) - asset_id - else - extname = compute_asset_extname(source, options) - path = File.join(Rails.public_path, "#{source}#{extname}") - exist = false - if File.exist? path - exist = true - else - path = File.join(Rails.public_path, public_compute_asset_path("#{source}#{extname}", options)) - if File.exist? path - exist = true - end - end - asset_id = exist ? File.mtime(path).to_i.to_s : '' - - if @@cache_asset_timestamps - @@asset_timestamps_cache_guard.synchronize do - @@asset_timestamps_cache[source] = asset_id - end - end - - asset_id - end - end +module Propshaft + Assembly.prepend(Module.new do + def initialize(config) + super + if Rails.application.config.assets.redmine_detect_update && (!manifest_path.exist? || manifest_outdated?) + processor.process end end - end + + def manifest_outdated? + !!load_path.asset_files.detect{|f| f.mtime > manifest_path.mtime} + end + + def load_path + @load_path ||= Redmine::AssetLoadPath.new(config) + end + end) + + Helper.prepend(Module.new do + def compute_asset_path(path, options = {}) + super + rescue MissingAssetError => e + File.join Rails.application.assets.resolver.prefix, path + end + end) end |