@checklist = [
[:text_default_administrator_account_changed, User.default_admin_account_changed?],
[:text_file_repository_writable, File.writable?(Attachment.storage_path)],
- ["#{l :text_plugin_assets_writable} (./public/plugin_assets)", File.writable?(Redmine::Plugin.public_directory)],
[:text_all_migrations_have_been_run, !ActiveRecord::Base.connection.migration_context.needs_migration?],
[:text_minimagick_available, Object.const_defined?(:MiniMagick)],
[:text_convert_available, Redmine::Thumbnail.convert_available?],
@dir
end
- def mirror_assets
- return unless has_assets_dir?
-
- destination = File.join(PluginLoader.public_directory, File.basename(@dir))
-
- source_files = Dir["#{assets_dir}/**/*"]
- source_dirs = source_files.select { |d| File.directory?(d)}
- source_files -= source_dirs
- unless source_files.empty?
- base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(assets_dir, ''))
- begin
- FileUtils.mkdir_p(base_target_dir)
- rescue => e
- raise "Could not create directory #{base_target_dir}: " + e.message
- end
- end
-
- source_dirs.each do |dir|
- # strip down these paths so we have simple, relative paths we can
- # add to the destination
- target_dir = File.join(destination, dir.gsub(assets_dir, ''))
- begin
- FileUtils.mkdir_p(target_dir)
- rescue => e
- raise "Could not create directory #{target_dir}: " + e.message
- end
- end
- source_files.each do |file|
- target = File.join(destination, file.gsub(assets_dir, ''))
- unless File.exist?(target) && FileUtils.identical?(file, target)
- FileUtils.cp(file, target)
- end
- rescue => e
- raise "Could not copy #{file} to #{target}: " + e.message
- end
- end
-
def has_assets_dir?
File.directory?(@assets_dir)
end
cattr_accessor :public_directory
self.public_directory = Rails.public_path.join('plugin_assets')
- def self.create_assets_reloader
- plugin_assets_dirs = {}
- directories.each do |dir|
- plugin_assets_dirs[dir.assets_dir] = ['*']
- end
- ActiveSupport::FileUpdateChecker.new([], plugin_assets_dirs) do
- mirror_assets
- end
- end
-
def self.load
setup
add_autoload_paths
def self.directories
@plugin_directories
end
-
- def self.mirror_assets(name=nil)
- if name.present?
- directories.find{|d| d.to_s == File.join(directory, name)}.mirror_assets
- else
- directories.each(&:mirror_assets)
- end
- end
end
end
@klass = Redmine::PluginLoader
@klass.directory = Rails.root.join('test/fixtures/plugins')
- @klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
@klass.load
end
clear_public
end
- def test_create_assets_reloader
- plugin_assets = @klass.create_assets_reloader
- plugin_assets.execute.inspect
-
- assert File.exist?("#{@klass.public_directory}/foo_plugin")
- assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
- end
-
- def test_mirror_assets
- Redmine::PluginLoader.mirror_assets
-
- assert File.exist?("#{@klass.public_directory}/foo_plugin")
- assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
- end
-
- def test_mirror_assets_with_plugin_name
- Redmine::PluginLoader.mirror_assets('foo_plugin')
-
- assert File.exist?("#{@klass.public_directory}/foo_plugin")
- assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
- end
-
def clear_public
FileUtils.rm_rf 'tmp/public'
end