diff --git a/Gemfile b/Gemfile index 74e55614..9764c09a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rich', git: 'https://github.com/a-ono/rich.git', tag: '1.5.2' +gem 'rich', git: 'https://github.com/nomadli/rich.git', tag: '1.5.3' gem 'kaminari' gem 'htmlentities' gem 'paperclip', '~> 6.1.0' diff --git a/init.rb b/init.rb index 0b4a1b82..90d3ecee 100644 --- a/init.rb +++ b/init.rb @@ -1,17 +1,29 @@ require 'redmine' -require 'redmine_ckeditor' -ActiveSupport::Reloader.to_prepare do - RedmineCkeditor.apply_patch +plugin_name = :redmine_ckeditor +plugin_root = File.dirname(__FILE__) + +unless defined?(SmileTools) + require plugin_root + '/lib/redmine_ckeditor' +end + +if Rails.version > '6.0' && Rails.autoloaders.zeitwerk_enabled? + Rails.application.config.after_initialize do + RedmineCkeditor.apply_patch + end +else + Rails.configuration.to_prepare do + RedmineCkeditor.apply_patch + end end Redmine::Plugin.register :redmine_ckeditor do name 'Redmine CKEditor plugin' author 'Akihiro Ono' description 'This is a CKEditor plugin for Redmine' - version '1.2.3' - requires_redmine :version_or_higher => '4.0.0' - url 'http://github.com/a-ono/redmine_ckeditor' + version '1.2.4' + requires_redmine :version_or_higher => '5.0.0' + url 'https://github.com/nomadli/redmine_ckeditor' settings(:partial => 'settings/ckeditor') diff --git a/lib/generators/redmine_ckeditor/rich_assets/rich_assets_generator.rb b/lib/generators/redmine_ckeditor/rich_assets/rich_assets_generator.rb index 03e45cd1..65a0c15e 100644 --- a/lib/generators/redmine_ckeditor/rich_assets/rich_assets_generator.rb +++ b/lib/generators/redmine_ckeditor/rich_assets/rich_assets_generator.rb @@ -1,36 +1,40 @@ require 'rake' require 'rails/generators' -module RedmineCkeditor - class RichAssetsGenerator < Rails::Generators::Base - source_root File.expand_path('../templates', __FILE__) - desc "Generate rich asset files for Redmine" - def create_assets - rake "redmine_ckeditor:assets:copy" +module Generators + module RedmineCkeditor + module RichAssets + class RichAssetsGenerator < Rails::Generators::Base + source_root File.expand_path('../templates', __FILE__) + desc "Generate rich asset files for Redmine" + def create_assets + rake "redmine_ckeditor:assets:copy" - gsub_file RedmineCkeditor.root.join("assets/ckeditor-contrib/plugins/richfile/plugin.js"), - "/assets/rich/", "../images/" + gsub_file RedmineCkeditor.root.join("assets/ckeditor-contrib/plugins/richfile/plugin.js"), + "/assets/rich/", "../images/" - application_js = RedmineCkeditor.root.join("assets/javascripts/application.js") - browser_js = RedmineCkeditor.root.join("assets/javascripts/browser.js") + application_js = RedmineCkeditor.root.join("assets/javascripts/application.js") + browser_js = RedmineCkeditor.root.join("assets/javascripts/browser.js") - gsub_file browser_js, "opt=opt.split(',');", "opt=opt ? opt.split(',') : [];" + gsub_file browser_js, "opt=opt.split(',');", "opt=opt ? opt.split(',') : [];" - gsub_file application_js, /var CKEDITOR_BASEPATH.+$/, "" + gsub_file application_js, /var CKEDITOR_BASEPATH.+$/, "" - gsub_file application_js, /CKEDITOR.plugins.addExternal.+$/, "" + gsub_file application_js, /CKEDITOR.plugins.addExternal.+$/, "" - gsub_file browser_js, '"/rich/files/"+', "" + gsub_file browser_js, '"/rich/files/"+', "" - inject_into_file browser_js, - "\t\turl = $(item).data('relative-url-root') + url;\n", - :after => "data('uris')[this._options.currentStyle];\n" + inject_into_file browser_js, + "\t\turl = $(item).data('relative-url-root') + url;\n", + :after => "data('uris')[this._options.currentStyle];\n" - gsub_file RedmineCkeditor.root.join("assets/stylesheets/application.css"), - 'image-url("rich/', 'url("../images/' + gsub_file RedmineCkeditor.root.join("assets/stylesheets/application.css"), + 'image-url("rich/', 'url("../images/' - append_to_file RedmineCkeditor.root.join("assets/stylesheets/editor.css"), - "\nhtml, body {\n height: 100%;\n}\n" + append_to_file RedmineCkeditor.root.join("assets/stylesheets/editor.css"), + "\nhtml, body {\n height: 100%;\n}\n" + end + end end end end diff --git a/lib/redmine_ckeditor.rb b/lib/redmine_ckeditor.rb index 54de23a2..9421e41c 100644 --- a/lib/redmine_ckeditor.rb +++ b/lib/redmine_ckeditor.rb @@ -138,12 +138,15 @@ def apply_patch end end -require 'redmine_ckeditor/helper' -require 'redmine_ckeditor/application_helper_patch' -require 'redmine_ckeditor/queries_helper_patch' -require 'redmine_ckeditor/rich_files_helper_patch' -require 'redmine_ckeditor/journals_controller_patch' -require 'redmine_ckeditor/messages_controller_patch' -require 'redmine_ckeditor/mail_handler_patch' -require 'redmine_ckeditor/pdf_patch' -require 'redmine_ckeditor/tempfile_patch' +plugin_name = :redmine_ckeditor +plugin_root = File.dirname(__FILE__) + +require plugin_root + '/redmine_ckeditor/helper' +require plugin_root + '/redmine_ckeditor/application_helper_patch' +require plugin_root + '/redmine_ckeditor/queries_helper_patch' +require plugin_root + '/redmine_ckeditor/rich_files_helper_patch' +require plugin_root + '/redmine_ckeditor/journals_controller_patch' +require plugin_root + '/redmine_ckeditor/messages_controller_patch' +require plugin_root + '/redmine_ckeditor/mail_handler_patch' +require plugin_root + '/redmine_ckeditor/pdf_patch' +require plugin_root + '/redmine_ckeditor/tempfile_patch' diff --git a/lib/redmine_ckeditor/pdf_patch.rb b/lib/redmine_ckeditor/pdf_patch.rb index 2ebd10fb..7e46ad22 100644 --- a/lib/redmine_ckeditor/pdf_patch.rb +++ b/lib/redmine_ckeditor/pdf_patch.rb @@ -1,5 +1,5 @@ module RedmineCkeditor - module PDFPatch + module PdfPatch def formatted_text(text) html = super html = HTMLEntities.new.decode(html) if RedmineCkeditor.enabled? @@ -48,4 +48,4 @@ def get_image_filename(attrname) end end -Redmine::Export::PDF::ITCPDF.prepend RedmineCkeditor::PDFPatch +Redmine::Export::PDF::ITCPDF.prepend RedmineCkeditor::PdfPatch diff --git a/lib/redmine_ckeditor/wiki_formatting/formatter.rb b/lib/redmine_ckeditor/wiki_formatting/formatter.rb index da20cff1..016cee40 100644 --- a/lib/redmine_ckeditor/wiki_formatting/formatter.rb +++ b/lib/redmine_ckeditor/wiki_formatting/formatter.rb @@ -1,6 +1,7 @@ module RedmineCkeditor::WikiFormatting class Formatter include Redmine::WikiFormatting::LinksHelper + include ActionView::Helpers::SanitizeHelper def initialize(text) @text = text @@ -24,7 +25,7 @@ def to_html(&block) } auto_link!(text) - text = ActionView::Base.white_list_sanitizer.sanitize(text, + text = ActionController::Base.helpers.sanitize(text, :tags => RedmineCkeditor.allowed_tags, :attributes => RedmineCkeditor.allowed_attributes )