diff --git a/plugins/redmine_ckeditor/Gemfile b/plugins/redmine_ckeditor/Gemfile new file mode 100644 index 0000000..d7903df --- /dev/null +++ b/plugins/redmine_ckeditor/Gemfile @@ -0,0 +1,8 @@ +gem 'rich', git: 'https://github.com/a-ono/rich.git' +gem 'kaminari' +gem 'htmlentities' +gem 'paperclip', '~> 4.2.1' +gem 'pandoc-ruby' + +# It is needed for upgrading CKEditor +#gem 'sprockets-rails', '< 3.0.0' diff --git a/plugins/redmine_ckeditor/README.rdoc b/plugins/redmine_ckeditor/README.rdoc new file mode 100644 index 0000000..f52092c --- /dev/null +++ b/plugins/redmine_ckeditor/README.rdoc @@ -0,0 +1,100 @@ += Redmine CKEditor plugin + +This plugin adds the text formatting for using CKEditor to Redmine. + +Since version 1.0.0, it includes {Rich}[https://github.com/bastiaanterhorst/rich] and supports image uploads. + +== What is CKEditor? + +CKEditor is a WYSIWYG text editor. +See {the official site}[http://ckeditor.com/] for more details. + +== Requirements + +{ImageMagick}[http://www.imagemagick.org/] (Since version 1.0.0) + # Ubuntu + apt-get install imagemagick + # Mac OS X + brew install imagemagick + +* Redmine 3.0.x, (version {1.1.5}[https://github.com/a-ono/redmine_ckeditor/releases/tag/1.1.5]) + +* Redmine 2.3.x, Ruby 1.9.2 or higher (version {1.0.20}[https://github.com/a-ono/redmine_ckeditor/releases/tag/1.0.20]) + +* Redmine 2.3.x (version {0.4.0}[https://github.com/a-ono/redmine_ckeditor/releases/tag/0.4.0]) + +* Redmine 2.2.x (version {0.3.0}[https://github.com/a-ono/redmine_ckeditor/releases/tag/0.3.0]) + +* Redmine 2.1.x (version {0.2.1}[https://github.com/a-ono/redmine_ckeditor/releases/tag/0.2.1]) + +* Redmine 2.0.x (version {0.1.1}[https://github.com/a-ono/redmine_ckeditor/releases/tag/0.1.1]) + +* Redmine 1.1.0 - 1.4.2 (version {0.0.6}[https://github.com/a-ono/redmine_ckeditor/releases/tag/0.0.6]) + +== Plugin installation and setup + +1. Copy the plugin directory into the plugins directory (make sure the name is redmine_ckeditor) +2. Install the required gems (in the Redmine root directory) + bundle install --without development test +3. Execute migration + rake redmine:plugins:migrate RAILS_ENV=production +4. Start Redmine +5. Change the text formatting (Administration > Settings > General > Text formatting) to CKEditor +6. Configure the plugin (Administration > Plugins > Configure) + +=== Upgrade + +1. Replace the plugin directory (plugins/redmine_ckeditor) +2. Install the required gems + bundle install --without development test +3. Execute migration + rake redmine:plugins:migrate RAILS_ENV=production +4. Delete old assets + rm -r public/plugin_assets/redmine_ckeditor +5. Restart Redmine + +=== Uninstall + +1. Change the text formatting (Administration > Settings > General > Text formatting) to textile +2. Rollback the migration + + rake redmine:plugins:migrate NAME=redmine_ckeditor VERSION=0 RAILS_ENV=production + +3. Delete the plugin directory (plugins/redmine_ckeditor) + +== CKEditor customization + +=== Plugins + +You can download plugins from {Add-ons Repository}[http://ckeditor.com/addons/plugins/all]. +To activate the plugin you have to copy the plugin directory into assets/ckeditor-contrib/plugins and restart Redmine, then configure toolbar settings. + +=== Skins + +You can select third-party skins placed in assets/ckeditor-contrib/skins directory. + +=== Configuration + +You can configure {CKEditor settings}[http://docs.ckeditor.com/#!/api/CKEDITOR.config] and HTML sanitizer by using the REDMINE_ROOT/config/ckeditor.yml file. + cp plugins/redmine_ckeditor/config/ckeditor.yml.example config/ckeditor.yml + +== Migration notes + +This plugin stores contents in HTML format and renders as is. +If you have old contents, these look weird. + +You can use {redmine_per_project_formatting}[https://github.com/a-ono/redmine_per_project_formatting] plugin for backward compatibility or execute redmine_ckeditor:migrate task for migrating old text to HTML. + rake redmine_ckeditor:migrate RAILS_ENV=production [PROJECT=project_identifier1,project_identifier2] [FROM=textile] [TO=html] +This task requires to {install Pandoc}[http://johnmacfarlane.net/pandoc/installing.html]. + +== Upgrading CKEditor (for development) + +1. Checkout the new version of CKEditor(full package) in the submodule directory + + git submodule update --init + cd app/assets/javascripts/ckeditor-releases + git checkout FULL_VERSION (e.g. full/4.4.6) + +2. Execute generator + + rails generate redmine_ckeditor:rich_assets diff --git a/plugins/redmine_ckeditor/app/assets/javascripts/application.js b/plugins/redmine_ckeditor/app/assets/javascripts/application.js new file mode 100644 index 0000000..8a7148b --- /dev/null +++ b/plugins/redmine_ckeditor/app/assets/javascripts/application.js @@ -0,0 +1,5 @@ +// +//= require rich/editor/ckeditor_path +//= require ckeditor-releases/ckeditor +//= require rich/editor/rich_editor +//= require rich/editor/rich_picker diff --git a/plugins/redmine_ckeditor/app/assets/javascripts/browser.js b/plugins/redmine_ckeditor/app/assets/javascripts/browser.js new file mode 100644 index 0000000..29fa85d --- /dev/null +++ b/plugins/redmine_ckeditor/app/assets/javascripts/browser.js @@ -0,0 +1,4 @@ +//= require fileuploader +//= require rich/browser/extensions +//= require rich/browser/uploader +//= require rich/browser/filebrowser diff --git a/plugins/redmine_ckeditor/app/models/redmine_ckeditor_setting.rb b/plugins/redmine_ckeditor/app/models/redmine_ckeditor_setting.rb new file mode 100644 index 0000000..43a45ee --- /dev/null +++ b/plugins/redmine_ckeditor/app/models/redmine_ckeditor_setting.rb @@ -0,0 +1,69 @@ +class RedmineCkeditorSetting + def self.setting + Setting[:plugin_redmine_ckeditor] || {} + end + + def self.default + ["1", true].include?(setting["default"]) + end + + def self.toolbar_string + setting["toolbar"] || RedmineCkeditor.default_toolbar + end + + def self.toolbar + bars = [] + bar = [] + toolbar_string.split(",").each {|item| + case item + when '/' + bars.push(bar, item) + bar = [] + when '--' + bars.push(bar) + bar = [] + else + bar.push(item) + end + } + + bars.push(bar) unless bar.empty? + bars + end + + def self.skin + setting["skin"] || "moono-lisa" + end + + def self.ui_color + setting["ui_color"] || "#f4f4f4" + end + + def self.enter_mode + (setting["enter_mode"] || 1).to_i + end + + def self.shift_enter_mode + enter_mode == 2 ? 1 : 2 + end + + def self.show_blocks + (setting["show_blocks"] || 1).to_i == 1 + end + + def self.toolbar_can_collapse + setting["toolbar_can_collapse"].to_i == 1 + end + + def self.toolbar_location + setting["toolbar_location"] || "top" + end + + def self.width + setting["width"] + end + + def self.height + setting["height"] || 400 + end +end diff --git a/plugins/redmine_ckeditor/app/views/journals/new_with_ckeditor.js.erb b/plugins/redmine_ckeditor/app/views/journals/new_with_ckeditor.js.erb new file mode 100644 index 0000000..592f9d1 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/journals/new_with_ckeditor.js.erb @@ -0,0 +1,9 @@ +<% + # when quoting a private journal, check the private checkbox + if @journal && @journal.private_notes? +%> +$('#issue_private_notes').attr('checked', true); +<% end %> + +CKEDITOR.instances['issue_notes'].setData(<%= @content.inspect.html_safe %>); +showAndScrollTo("update", "issue_notes"); diff --git a/plugins/redmine_ckeditor/app/views/layouts/rich/application.html.erb b/plugins/redmine_ckeditor/app/views/layouts/rich/application.html.erb new file mode 100644 index 0000000..1640125 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/layouts/rich/application.html.erb @@ -0,0 +1,16 @@ + + + + Rich Browser + <%= javascript_heads %> + <%= stylesheet_link_tag "application", :plugin => "redmine_ckeditor" %> + <%= ckeditor_javascripts %> + <%= javascript_include_tag "browser", :plugin => "redmine_ckeditor" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/plugins/redmine_ckeditor/app/views/messages/quote_with_ckeditor.js.erb b/plugins/redmine_ckeditor/app/views/messages/quote_with_ckeditor.js.erb new file mode 100644 index 0000000..78c9a64 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/messages/quote_with_ckeditor.js.erb @@ -0,0 +1,2 @@ +<%= render :file => "messages/quote" %> +CKEDITOR.instances['message_content'].setData($('#message_content').val()); diff --git a/plugins/redmine_ckeditor/app/views/rich/files/_file.html.erb b/plugins/redmine_ckeditor/app/views/rich/files/_file.html.erb new file mode 100644 index 0000000..5876c09 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/rich/files/_file.html.erb @@ -0,0 +1,12 @@ +
  • + +

    <%= file.rich_file_file_name %>

    + <%= link_to "delete", file.id.to_s, :method => :delete, :remote => true, :data => { :confirm => t(:delete_confirm) }, :class => "delete", :title => t(:delete) %> +
  • diff --git a/plugins/redmine_ckeditor/app/views/settings/_ckeditor.html.erb b/plugins/redmine_ckeditor/app/views/settings/_ckeditor.html.erb new file mode 100644 index 0000000..fefe821 --- /dev/null +++ b/plugins/redmine_ckeditor/app/views/settings/_ckeditor.html.erb @@ -0,0 +1,142 @@ +<%= ckeditor_javascripts %> +<%= stylesheet_link_tag 'editor', :plugin => 'redmine_ckeditor'%> +<%= stylesheet_link_tag 'selector', :plugin => 'redmine_ckeditor'%> +

    + <%= content_tag :label, l(:ckeditor_skin) %> + <%= select_tag "settings[skin]", RedmineCkeditor.skin_options %> +

    +

    + <%= content_tag :label, l(:ckeditor_ui_color) %> + <%= text_field_tag "settings[ui_color]", RedmineCkeditorSetting.ui_color %> +

    +

    + <%= content_tag :label, l(:ckeditor_width) %> + <%= text_field_tag "settings[width]", RedmineCkeditorSetting.width %> +

    +

    + <%= content_tag :label, l(:ckeditor_height) %> + <%= text_field_tag "settings[height]", RedmineCkeditorSetting.height %> +

    +

    + <%= content_tag :label, l(:ckeditor_enter_mode) %> + <%= select_tag "settings[enter_mode]", RedmineCkeditor.enter_mode_options %> +

    +

    + <%= content_tag :label, l(:ckeditor_startup_show_blocks) %> + <%= hidden_field_tag "settings[show_blocks]", 0 %> + <%= check_box_tag "settings[show_blocks]", 1, RedmineCkeditorSetting.show_blocks %> +

    +

    + <%= content_tag :label, l(:ckeditor_toolbar_can_collapse) %> + <%= hidden_field_tag "settings[toolbar_can_collapse]", 0 %> + <%= check_box_tag "settings[toolbar_can_collapse]", 1, RedmineCkeditorSetting.toolbar_can_collapse %> +

    +

    + <%= content_tag :label, l(:ckeditor_toolbar_location) %> + <%= select_tag "settings[toolbar_location]", RedmineCkeditor.toolbar_location_options %> +

    +

    + <%= content_tag :label, l(:ckeditor_toolbar_buttons) %> +

    + +
    + <%= hidden_field_tag "settings[toolbar]", RedmineCkeditorSetting.toolbar_string %> + + + +
    +
    +

    +
    +
    + +
    + + + +
    +
    +
    + +<%= javascript_tag do %> + function moveItem(from, to) { + from = $("#" + from); + to = $("#" + to); + var selected = to.find("option:selected").first(); + from.find("option:selected").remove().each(function() { + if (this.value == '-' || this.value == '--' || this.value == '/') return; + selected.size() ? selected.before(this) : to.append(this); + }); + to.prop("selectedIndex", -1); + changeHandler(); + } + + function addItem(item) { + var option = $("