From 700381cb2ff36694f39e6a982c92f30f53255609 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 1 Feb 2020 00:12:33 -0700 Subject: [PATCH] Add compatibility for Redmine v4.1 Fixes #22 --- README.md | 8 ++++++-- init.rb | 5 +++++ lib/tasks/install.rake | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/tasks/install.rake diff --git a/README.md b/README.md index 9f4610e..49b8cac 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,15 @@ Installation $ rake emoji - 4. Run the plugin rake task to provide the assets (from the Redmine root directory): + 4. If your Redmine version 4.1, run the following rake install. Otherwise, skip to step 5. + + $ rake emojibutton:install + + 5. Run the plugin rake task to provide the assets (from the Redmine root directory): $ rake redmine:plugins:migrate RAILS_ENV=production - 5. Restart redmine + 6. Restart redmine Usage diff --git a/init.rb b/init.rb index 9138dff..8e0a0e6 100644 --- a/init.rb +++ b/init.rb @@ -2,6 +2,11 @@ require 'emojibutton_formatter_textile_patch' require 'emojibutton_formatter_markdown_patch' require 'emojibutton_helper_patch' +require 'sprockets/railtie' unless defined?(Sprockets) + +unless File.exist?(Rails.root.join('app', 'assets', 'config', 'manifest.js')) + `mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js` +end Redmine::Plugin.register :redmine_emojibutton do name 'Redmine Emoji Button' diff --git a/lib/tasks/install.rake b/lib/tasks/install.rake new file mode 100644 index 0000000..16725b0 --- /dev/null +++ b/lib/tasks/install.rake @@ -0,0 +1,15 @@ +desc 'Add requirements for Redmine v4.1+' +namespace :emojibutton do + task :install do + + # Uncomment the sprockets railtie requirement + path = "#{Rake.original_dir}/config/application.rb" + IO.write(path, File.open(path) { |f| f.read.gsub(/^# require 'sprockets\/railtie'$/, "require 'sprockets/railtie'") }) + + # Add a blank manifest file for sprockets + unless File.exist?(Rails.root.join('app', 'assets', 'config', 'manifest.js')) + `mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js` + end + + end +end