From f471cc9459f80b67e0965e0ed71a86fcbb156e4f Mon Sep 17 00:00:00 2001 From: Takashi Kato Date: Sun, 10 Nov 2024 14:47:40 +0000 Subject: [PATCH] Support plugin multiple asset path --- config/initializers/30-redmine.rb | 5 +++-- lib/redmine/plugin.rb | 8 +++++--- lib/redmine/plugin_loader.rb | 6 ++++-- .../plugins/foo_plugin/app/assets/javascripts/foo.js | 0 test/unit/lib/redmine/plugin_test.rb | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/plugins/foo_plugin/app/assets/javascripts/foo.js diff --git a/config/initializers/30-redmine.rb b/config/initializers/30-redmine.rb index cf13cab204..45f75c10fc 100644 --- a/config/initializers/30-redmine.rb +++ b/config/initializers/30-redmine.rb @@ -34,8 +34,9 @@ Rails.application.config.to_prepare do end Redmine::Plugin.all.each do |plugin| - paths = plugin.asset_paths - Rails.application.config.assets.redmine_extension_paths << paths if paths.present? + plugin.asset_paths.each do |paths| + Rails.application.config.assets.redmine_extension_paths << paths if paths.present? + end end Redmine::Themes.themes.each do |theme| diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 223b3927ac..3d5cd351ed 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -192,9 +192,11 @@ module Redmine def asset_paths return unless path.has_assets_dir? - base_dir = Pathname.new(path.assets_dir) - paths = base_dir.children.select(&:directory?) - Redmine::AssetPath.new(base_dir, paths, asset_prefix) + path.assets_dir.map do |dir| + base_dir = Pathname.new(dir) + paths = base_dir.children.select(&:directory?) + Redmine::AssetPath.new(base_dir, paths, asset_prefix) + end end def <=>(plugin) diff --git a/lib/redmine/plugin_loader.rb b/lib/redmine/plugin_loader.rb index 9fc634a6dd..30808b0cf7 100644 --- a/lib/redmine/plugin_loader.rb +++ b/lib/redmine/plugin_loader.rb @@ -21,9 +21,11 @@ module Redmine class PluginPath attr_reader :assets_dir, :initializer + ASSET_PATHS = ['assets', 'app/assets'] + def initialize(dir) @dir = dir - @assets_dir = File.join dir, 'assets' + @assets_dir = ASSET_PATHS.map{|asset_path| File.join dir, asset_path}.select{|dir| File.directory? dir} @initializer = File.join dir, 'init.rb' end @@ -36,7 +38,7 @@ module Redmine end def has_assets_dir? - File.directory?(@assets_dir) + assets_dir.any?{|dir| File.directory?(dir)} end def has_initializer? diff --git a/test/fixtures/plugins/foo_plugin/app/assets/javascripts/foo.js b/test/fixtures/plugins/foo_plugin/app/assets/javascripts/foo.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/lib/redmine/plugin_test.rb b/test/unit/lib/redmine/plugin_test.rb index e6945c4d8a..d90548a631 100644 --- a/test/unit/lib/redmine/plugin_test.rb +++ b/test/unit/lib/redmine/plugin_test.rb @@ -59,7 +59,8 @@ class Redmine::PluginTest < ActiveSupport::TestCase assert_equal 'http://example.net/jsmith', plugin.author_url assert_equal 'This is a test plugin', plugin.description assert_equal '0.0.1', plugin.version - assert_equal File.join(@klass.directory, 'foo_plugin', 'assets'), plugin.assets_directory + assert plugin.assets_directory.find{|dir| dir == File.join(@klass.directory, 'foo_plugin', 'assets')} + assert plugin.assets_directory.find{|dir| dir == File.join(@klass.directory, 'foo_plugin', 'app', 'assets')} end ::FooModel = Class.new(ApplicationRecord) -- 2.39.2