Skip to content

Commit

Permalink
fixed for redmine 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadli authored Sep 16, 2022
1 parent 24b66f5 commit 6727184
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
24 changes: 18 additions & 6 deletions init.rb
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
Original file line number Diff line number Diff line change
@@ -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
21 changes: 12 additions & 9 deletions lib/redmine_ckeditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions lib/redmine_ckeditor/pdf_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module RedmineCkeditor
module PDFPatch
module PdfPatch
def formatted_text(text)
html = super
html = HTMLEntities.new.decode(html) if RedmineCkeditor.enabled?
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/redmine_ckeditor/wiki_formatting/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module RedmineCkeditor::WikiFormatting
class Formatter
include Redmine::WikiFormatting::LinksHelper
include ActionView::Helpers::SanitizeHelper

def initialize(text)
@text = text
Expand All @@ -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
)
Expand Down

0 comments on commit 6727184

Please sign in to comment.