From c99bb27e27e3c32ca5aa174de238fe3adf089310 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Thu, 25 Jan 2024 05:38:33 +0000 Subject: 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 --- config/initializers/10-patches.rb | 70 +++++++++++++-------------------------- 1 file changed, 23 insertions(+), 47 deletions(-) (limited to 'config/initializers/10-patches.rb') 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 -- cgit v1.2.3