{"id":13427808,"url":"https://github.com/galetahub/ckeditor","last_synced_at":"2025-05-14T08:05:11.275Z","repository":{"id":626716,"uuid":"1942140","full_name":"galetahub/ckeditor","owner":"galetahub","description":"Ckeditor 4.x integration gem for rails","archived":false,"fork":false,"pushed_at":"2025-01-23T13:42:18.000Z","size":10395,"stargazers_count":2229,"open_issues_count":14,"forks_count":880,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-05-14T08:03:36.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ckeditor.com/ckeditor-4/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galetahub.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-06-23T15:04:32.000Z","updated_at":"2025-04-17T21:21:04.000Z","dependencies_parsed_at":"2024-09-21T06:01:43.294Z","dependency_job_id":"194a48a0-8262-4b19-922c-45c95fa48b85","html_url":"https://github.com/galetahub/ckeditor","commit_stats":{"total_commits":391,"total_committers":137,"mean_commits":2.854014598540146,"dds":0.5012787723785166,"last_synced_commit":"8200ccdbf789669d154b800aab329db8f46aabdc"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galetahub%2Fckeditor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galetahub%2Fckeditor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galetahub%2Fckeditor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galetahub%2Fckeditor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galetahub","download_url":"https://codeload.github.com/galetahub/ckeditor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101588,"owners_count":22014907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T01:00:40.732Z","updated_at":"2025-05-14T08:05:11.236Z","avatar_url":"https://github.com/galetahub.png","language":"Ruby","funding_links":[],"categories":["Plugins","基于 Ruby","Web 后端","插件","For Ruby"],"sub_categories":["Omniauth"],"readme":"# Ckeditor\n\n[![Build Status](https://galetahub.semaphoreci.com/badges/ckeditor/branches/master.svg?style=shields\u0026key=eabcab57-9b51-4460-9b27-9c61c28efcdb)](https://galetahub.semaphoreci.com/projects/ckeditor)\n[![Code Climate](https://codeclimate.com/github/galetahub/ckeditor/badges/gpa.svg)](https://codeclimate.com/github/galetahub/ckeditor)\n[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)\n\n\nCKEditor is a WYSIWYG text editor designed to simplify web content creation. It brings common word processing features directly to your web pages. Enhance your website experience with our\ncommunity maintained editor. Currently this gem supports [ckeditor 4](https://ckeditor.com/ckeditor-4/) only.\n\n[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://stand-with-ukraine.pp.ua)\n\n## Features\n\n* CKEditor version 5 (\u003chttps://ckeditor.com/ckeditor-5/download/\u003e)\n* Rails 7.x, 6.x, 5.x, 4.x integration\n* Files browser\n* HTML5 file uploader\n* Hooks for formtastic and simple_form forms generators\n* Integrated with authorization frameworks [CanCanCan](https://github.com/CanCanCommunity/cancancan) and [Pundit](https://github.com/varvet/pundit)\n\n## Installation\n\nFor basic usage just include the ckeditor gem:\n\n```\ngem 'ckeditor'\n```\n\nor if you'd like to use the latest version from Github:\n\n```\ngem 'ckeditor', github: 'galetahub/ckeditor'\n```\n\nInclude this inside your `config/initializers/assets.rb`:\n\n```\nRails.application.config.assets.precompile += %w[ckeditor/config.js]\n```\n\nFor file upload support, you must generate the necessary file storage models.\nThe currently supported backends are:\n\n* ActiveRecord (active_storage, paperclip, carrierwave, dragonfly)\n* Mongoid (paperclip, carrierwave, dragonfly)\n\n### How to generate models to store uploaded files\n\n#### ActiveRecord + paperclip\n\nTo use the active_record orm with paperclip (i.e. the default settings):\n\n```\ngem 'paperclip'\n\nrails generate ckeditor:install --orm=active_record --backend=paperclip\n```\n\n#### ActiveRecord + active_storage\n\n```\ngem \"mini_magick\"\n\nrails active_storage:install # if you haven't installed active_storage yet\nrails generate ckeditor:install --orm=active_record --backend=active_storage\n```\n\n#### ActiveRecord + carrierwave\n\n```\ngem 'carrierwave'\ngem 'mini_magick'\n\nrails generate ckeditor:install --orm=active_record --backend=carrierwave\n```\n\n#### ActiveRecord + dragonfly\n\nRequires Dragonfly 1.0 or higher.\n\n```\ngem 'dragonfly'\n\nrails generate ckeditor:install --orm=active_record --backend=dragonfly\n```\n\n#### Mongoid + paperclip\n\n```\ngem 'mongoid-paperclip', require: 'mongoid_paperclip'\n\nrails generate ckeditor:install --orm=mongoid --backend=paperclip\n```\n\n#### Mongoid + active_storage\n\nActive Storage support **only** Active Record, see for [more info](https://github.com/rails/rails/issues/31408#issuecomment-351128111)\n\n#### Mongoid + carrierwave\n\n```\ngem 'carrierwave-mongoid', require: 'carrierwave/mongoid'\ngem 'mini_magick'\n\nrails generate ckeditor:install --orm=mongoid --backend=carrierwave\n```\n\n#### Load generated models\n\nAll ckeditor models will be generated in the app/models/ckeditor directory.\nModels are autoloaded in Rails 4. For earlier Rails versions, you need to add them to the autoload path (in application.rb):\n\n```ruby\nconfig.autoload_paths += %w(#{config.root}/app/models/ckeditor)\n```\n\nMount the Ckeditor::Engine to your routes (config/routes.rb):\n\n```ruby\nmount Ckeditor::Engine =\u003e '/ckeditor'\n```\n\n## Usage\n\n### Load editor via CKEditor CDN\n\nSetup editor version to load (more info here \u003chttp://cdn.ckeditor.com/\u003e)\n\n```ruby\n# in config/initializers/ckeditor.rb\n\nCkeditor.setup do |config|\n  # //cdn.ckeditor.com/\u003cversion.number\u003e/\u003cdistribution\u003e/ckeditor.js\n  config.cdn_url = \"//cdn.ckeditor.com/4.6.1/basic/ckeditor.js\"\nend\n```\n\nIn view template include ckeditor CDN:\n\n```slim\n= javascript_include_tag Ckeditor.cdn_url\n```\n\nPrecompile ckeditor/config.js:\n\n```ruby\n# in config/initializers/assets.rb\n\nRails.application.config.assets.precompile += %w[ckeditor/config.js]\n```\n\n### Form helpers\n\n```slim\n= form_for @page do |form|\n  = form.cktext_area :notes, class: 'someclass', ckeditor: { language: 'uk'}\n  = form.cktext_area :content, value: 'Default value', id: 'sometext'\n  = cktext_area :page, :info, cols: 40, ckeditor: { uiColor: '#AADC6E', toolbar: 'mini' }\n```\n\n*It also works with bootstrap-form*\n\n```slim\n= bootstrap_form_for resource do |form|\n  = form.cktext_area :text, ckeditor: { language: 'uk'}\n```\n\n### Customize ckeditor\n\nAll ckeditor options can be found [here](http://docs.ckeditor.com/#!/api/CKEDITOR.config)\n\nIn order to configure the ckeditor default options, create the following files:\n\n```\napp/assets/javascripts/ckeditor/config.js\n\napp/assets/javascripts/ckeditor/contents.css\n```\n\n#### Custom toolbars example\n\nAdding a custom toolbar:\n\n```javascript\n# in app/assets/javascripts/ckeditor/config.js\n\nCKEDITOR.editorConfig = function (config) {\n  // ... other configuration ...\n\n  config.toolbar_mini = [\n    [\"Bold\",  \"Italic\",  \"Underline\",  \"Strike\",  \"-\",  \"Subscript\",  \"Superscript\"],\n  ];\n  config.toolbar = \"mini\";\n\n  // ... rest of the original config.js  ...\n}\n```\n\nWhen overriding the default `config.js` file, you must set all configuration options yourself as the bundled `config.js` will not be loaded. To see the default configuration, run `bundle open ckeditor`, copy `app/assets/javascripts/ckeditor/config.js` into your project and customize it to your needs.\n\n#### Install additional plugins\n\nYou should download necessary plugins with all dependencies and extract them in `app/assets/javascripts/ckeditor/plugins/`.\nAfter that you can include your plugins in `app/assets/javascripts/ckeditor/config.js` in this way:\n\n```javascript\nCKEDITOR.editorConfig = function (config) {\n  config.extraPlugins = 'eqneditor,autosave,';\n}\n```\n\n### AJAX\n\njQuery sample:\n\n```html\n\u003cscript type='text/javascript' charset='UTF-8'\u003e\n  $(document).ready(function(){\n    $('form[data-remote]').bind('ajax:before', function(){\n      for (instance in CKEDITOR.instances){\n        CKEDITOR.instances[instance].updateElement();\n      }\n    });\n  });\n\u003c/script\u003e\n```\n\n### Formtastic integration\n\n```slim\n= form.input :content, as: :ckeditor\n= form.input :content, as: :ckeditor, input_html: { ckeditor: { height: 400 } }\n```\n\n### SimpleForm integration\n\nNote that the toolbar option should match the case specified in the config. If the config is not found it defaults to all available toolbar items.\n\ni.e. config.toolbar_mini becomes {toolbar: 'mini'} in the form.\n\n```slim\n= form.input :content, as: :ckeditor, input_html: { ckeditor: { toolbar: 'Full' } }\n```\n\n### Turbolink integration\n\nCreate a file app/assets/javascripts/init_ckeditor.coffee\n\n```coffee\nready = -\u003e\n  $('.ckeditor').each -\u003e\n    CKEDITOR.replace $(this).attr('id')\n\n$(document).ready(ready)\n$(document).on('page:load', ready)\n```\n\nMake sure the file is loaded from your app/assets/javascripts/application.js\n\n### CanCanCan integration\n\nTo use cancan with Ckeditor, add this to an initializer:\n\n```ruby\n# in config/initializers/ckeditor.rb\n\nCkeditor.setup do |config|\n  config.authorize_with :cancancan\nend\n```\n\nAt this point, all authorization will fail and no one will be able to access the filebrowser pages.\nTo grant access, add the following abilities (usually `ability.rb`)\n\n```ruby\n# Always performed\ncan :access, :ckeditor   # needed to access Ckeditor filebrowser\n\n# Performed checks for actions:\ncan [:read, :create, :destroy], Ckeditor::Picture\ncan [:read, :create, :destroy], Ckeditor::AttachmentFile\n```\n\n### Pundit or Action Policy Integration\n\nSetup Pundit and Action Policy similar.\nJust like CanCanCan, you can write this code in your config/initializers/ckeditor.rb file:\n\n```ruby\nCkeditor.setup do |config|\n  config.authorize_with :pundit # or :action_policy\nend\n```\n\nThen, generate the policy files for model **Picture** and **AttachmentFile**\n\n```\nrails g ckeditor:pundit_policy # or ckeditor:action_policy\n```\n\nBy this command, you will got two files:\n\u003e app/policies/ckeditor/picture_policy.rb\napp/policies/ckeditor/attachment_file_policy.rb\n\nBy default, only the user that logged in can access the models.\n\nYou can customize these two policy files as you like.\n\n## Engine configuration\n\n* To override the default CKEditor routes create a [config.js](https://github.com/galetahub/ckeditor/blob/master/app/assets/javascripts/ckeditor/config.js) file within the host application at `app/assets/javascripts/ckeditor/config.js`\n\n* By default, the engine inherits from `ApplicationController`. To override the default parent controller:\n\n```\n# in config/initializers/ckeditor.rb\n\nCkeditor.setup do |config|\n  config.parent_controller = 'MyCKEditorBaseController'\nend\n```\n\nBased on this, if you want to secure CKEditor controller actions and you can't authenticate in ApplicationController, you could do so with a custom controller after configuring the override above, like so:\n\n```\nclass MyCKEditorBaseController \u003c ActionController::Base\n\n  before_action :authenticate_user! # or some other auth/permission logic here, like Pundit\n\nend\n```\n\n## I18n\n\n```yml\nen:\n  ckeditor:\n    page_title: 'CKEditor Files Manager'\n    confirm_delete: 'Delete file?'\n    buttons:\n      cancel: 'Cancel'\n      upload: 'Upload'\n      delete: 'Delete'\n      next: 'Next'\n```\n\n## Tests\n\n```bash\n$\u003e rake test CKEDITOR_BACKEND=paperclip\n$\u003e rake test CKEDITOR_BACKEND=active_storage\n$\u003e rake test CKEDITOR_BACKEND=carrierwave\n$\u003e rake test CKEDITOR_BACKEND=dragonfly\n$\u003e rake test CKEDITOR_BACKEND=shrine\n$\u003e rake test CKEDITOR_ORM=mongoid\n\n$\u003e rake test:controllers\n$\u003e rake test:generators\n$\u003e rake test:integration\n$\u003e rake test:models\n```\n\nThis project rocks and uses the MIT-LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaletahub%2Fckeditor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaletahub%2Fckeditor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaletahub%2Fckeditor/lists"}