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 | |
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')
-rw-r--r-- | config/initializers/10-patches.rb | 70 | ||||
-rw-r--r-- | config/initializers/30-redmine.rb | 22 |
2 files changed, 38 insertions, 54 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 diff --git a/config/initializers/30-redmine.rb b/config/initializers/30-redmine.rb index 62969e4a6..f19373b65 100644 --- a/config/initializers/30-redmine.rb +++ b/config/initializers/30-redmine.rb @@ -21,17 +21,25 @@ if secret.present? end Redmine::PluginLoader.load -plugin_assets_reloader = Redmine::PluginLoader.create_assets_reloader - -Rails.application.reloaders << plugin_assets_reloader -unless Redmine::Configuration['mirror_plugins_assets_on_startup'] == false - plugin_assets_reloader.execute -end Rails.application.config.to_prepare do + default_paths = [] + default_paths << Rails.public_path.join('javascripts') + default_paths << Rails.public_path.join('stylesheets') + default_paths << Rails.public_path.join('images') + Rails.application.config.assets.redmine_default_asset_path = Redmine::AssetPath.new(Rails.public_path, default_paths) + Redmine::FieldFormat::RecordList.subclasses.each do |klass| klass.instance.reset_target_class end - plugin_assets_reloader.execute_if_updated + Redmine::Plugin.all.each do |plugin| + paths = plugin.asset_paths + Rails.application.config.assets.redmine_extension_paths << paths if paths.present? + end + + Redmine::Themes.themes.each do |theme| + paths = theme.asset_paths + Rails.application.config.assets.redmine_extension_paths << paths if paths.present? + end end |