All Projects → igorkasyanchuk → new_ckeditor

igorkasyanchuk / new_ckeditor

Licence: MIT license
Ruby on Rails + CKEditor 5

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to new ckeditor

Ckeditor5
Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
Stars: ✭ 5,406 (+19922.22%)
Mutual labels:  wysiwyg, ckeditor, ckeditor5
Ckeditor4 Releases
Official distribution releases of CKEditor 4.
Stars: ✭ 511 (+1792.59%)
Mutual labels:  wysiwyg, ckeditor
html-integrations
The official JavaScript library for MathType, the leading formula editor and equation writer for the web by Wiris
Stars: ✭ 36 (+33.33%)
Mutual labels:  wysiwyg, ckeditor
Ckeditor4
The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
Stars: ✭ 5,502 (+20277.78%)
Mutual labels:  wysiwyg, ckeditor
Laravel Filemanager Example 5.3
Demo integration for laravel-filemanager (https://github.com/UniSharp/laravel-filemanager).
Stars: ✭ 100 (+270.37%)
Mutual labels:  wysiwyg, ckeditor
iOS-HTMLTextEditor
A simple implementation of an HTML Editor using CKEditor in a web view.
Stars: ✭ 57 (+111.11%)
Mutual labels:  wysiwyg, ckeditor
Laravel Filemanager
Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
Stars: ✭ 1,688 (+6151.85%)
Mutual labels:  wysiwyg, ckeditor
ckeditor5-math
Math feature for CKEditor 5.
Stars: ✭ 51 (+88.89%)
Mutual labels:  ckeditor, ckeditor5
eclipse-asciidoctor-editor
An eclipse editor for asciidoctor files
Stars: ✭ 45 (+66.67%)
Mutual labels:  wysiwyg
Text to MD
Convert your docs to markdown format.
Stars: ✭ 15 (-44.44%)
Mutual labels:  ckeditor
tui editor
Implementiert den TOASTUI Markdown Editor
Stars: ✭ 21 (-22.22%)
Mutual labels:  wysiwyg
draftjs-filters
Filter Draft.js content to preserve only the formatting you allow
Stars: ✭ 53 (+96.3%)
Mutual labels:  wysiwyg
MarkDEditor
A WYSIWYG MarkDown editor for Android.
Stars: ✭ 76 (+181.48%)
Mutual labels:  wysiwyg
summernote-templates
Summernote Toolbar Buttons to Add Page and Block Templates.
Stars: ✭ 21 (-22.22%)
Mutual labels:  wysiwyg
summernote-themes
Addon Themes for Summernote Lite WYSIWYG Editor
Stars: ✭ 42 (+55.56%)
Mutual labels:  wysiwyg
squint
Search PostgreSQL jsonb and hstore columns
Stars: ✭ 26 (-3.7%)
Mutual labels:  ruby-on-rails
rls rails
Row Level Security for Ruby on Rails
Stars: ✭ 50 (+85.19%)
Mutual labels:  ruby-on-rails
django-text
Intuitive text editing for humans using Django.
Stars: ✭ 80 (+196.3%)
Mutual labels:  wysiwyg
preact-rpc
React Pre-Rendering via RPC
Stars: ✭ 28 (+3.7%)
Mutual labels:  ruby-on-rails
kwig
KIWG is a WYSIWYG editor for WinForm based on summernote.
Stars: ✭ 36 (+33.33%)
Mutual labels:  wysiwyg

Rails + CKEditor 5

RailsJazz https://www.patreon.com/igorkasyanchuk

DEMO: https://new-ckeditor-demo.herokuapp.com/

Simple way to integrate Ruby on Rails application with CKEditor 5. This is the latest version of CKEditor which has more modern UI and cool toolbars. Main features:

  • Inline editor
  • Balloon editor
  • Classic editor
  • File uploads (custom controller & uploader)
  • Tables, Media, and other toolbar buttons
  • (requires maybe 10-15 minutes to configure gem, but works fine, better to clone and check source of demo)

Demo >> Demo site

Usage

1. Add gem
2. bundle
3. rails g new_ckeditor # to generate toolbars & configs
4. add js in application.js, or to the assets pipeline
5. in your form
  # to load CKEditor JS
  = javascript_include_tag 'new_ckeditor/classic/ckeditor', 'data-turbolinks-track': 'reload'
  
  # form control
  = f.ckeditor :description

Inline/Balloon

For inline/balloon editor you need to define a saver function, example is: app.js

  <p>
    <%= ckeditor_tag :content, @post.content, editor: { template: :balloon, type: :balloon, js: "sendData('#{update_inline_post_path(@post)}', editorHiddenField.value)" } %>
  </p>

Options:

  • teamplte - file with configuration for CKEditor, toolbar, path to upload files, etc
  • type - type of editor, depending on the type behavior is a little different. Balloon and inline editors works almost the same way. Classic works better as form field.

File uploads

Define logic for saving file (controller/uploader).

Sample: https://github.com/igorkasyanchuk/new_ckeditor_demo/blob/master/app/controllers/posts_controller.rb#L10-L23

You need also to configure your CKEditor editor config, sample: https://github.com/igorkasyanchuk/new_ckeditor_demo/blob/master/app/views/new_ckeditor/shared/_inline.html.erb#L50-L54

You need to define path to which send file and also CSRF token for security purposes. You can see how it works in example above.

Installation

Add this line to your application's Gemfile and run bundle:

gem 'new_ckeditor'

Configuration

File Upload with CKEditor 5

Gem doesn't have any strict dependency on any library. It's implemented this way on purpose to let developer use gem which he wants. Maybe in the future we can improve it.

But you can get a base skeleton where you can put your own logic.

Below I'll put an example of code which works with CKEditor.

  1. Let's start with new controller rails g controller file_uploads upload
class FileUploadsController < ApplicationController
  # note
  # that method must return json with URL to an uploaded image
  # or error message
  def upload
    image = CkEditorImage.new(file: params["upload"])
    if image.save
      render json: {
        url: image.file.url
      }
    else
      render json: {
        "error": {
          "message": image.errors.full_messages.join(", ")
        }
      }
    end
  end
end
  1. Create a new model where images will be stored: rails g model CkEditorImage file:string user_id:integer parent_id:integer parent_type:string
class CkEditorImage < ApplicationRecord
  mount_uploader :file, CkEditorImageUploader
  belongs_to :user, optional: true
  validates_presence_of :file
end

Code of migration may look like:

class CreateCkEditorImages < ActiveRecord::Migration[6.0]
  def change
    create_table :ck_editor_images do |t|
      t.string :file
      t.integer :user_id, index: true
      t.integer :parent_id
      t.string :parent_type

      t.datetime :created_at
      t.datetime :updated_at
    end
    add_index :ck_editor_images, :user_id
    add_index :ck_editor_images, [:parent_id, :parent_type]
  end
end

Run this migration.

  1. Create Carrierwave uploader rails g uploader CkEditorImage. Open and edit it if needed.

  2. Open again controller, edit logic, check user, check params, etc. You have a full control how to implement logic of storing files.

CKEditor 5 Toolbar Customization

You can edit in appropriate JS file, for example:

    toolbar: {
      items: [
        'heading',
        '|',
        'bold',
        'italic',
        'underline',
        'strikethrough',
        'link',
        'bulletedList',
        'numberedList',
        'alignment',
        '|',
        'indent',
        ...

You can create a copy of each classic, balloon', inline .js file and use. Or even creae custom build on ckeditor.com site and put in your app.

After that you can specify which exactly editor type and template with toolbar configuration to use:

<%= form.ckeditor :description, editor: { template: :inline, type: :inline } %>

Output

Output RAW HTML from CKEditor

To use same CSS as in editor, to keep consistent UI:

Require CSS file in application.css:

 *= require new_ckeditor/ckeditor.css

And in the view wrap output in .ck-content class:

<p>
  <strong>About:</strong>
  <div class="ck-content">
    <%= raw @user.about %>
  </div>
</p>

More documentation: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/content-styles.html

Styling

CKEditor 5 set min-height, height, width

.ck-editor__editable {
  min-height: 500px;
}

You can editor in some parent div and set height explicitly for editor inside.

TODO

  • configuration to specify toolbar
  • generators?
  • better and better readme
  • gif with demo
  • tests
  • check how it works with turbolinks?
  • fix issue fix JS map files
  • easier configuration
  • saver function to save inline/balloon editor

Customization

https://ckeditor.com/ckeditor-5/online-builder/

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].