{"id":13815569,"url":"https://github.com/Macrow/rails_kindeditor","last_synced_at":"2025-05-15T09:32:36.672Z","repository":{"id":56890604,"uuid":"1883845","full_name":"Macrow/rails_kindeditor","owner":"Macrow","description":"Kindeditor for Ruby on Rails","archived":false,"fork":false,"pushed_at":"2018-05-11T03:06:30.000Z","size":1059,"stargazers_count":260,"open_issues_count":8,"forks_count":108,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-11-15T04:56:38.587Z","etag":null,"topics":["kindeditor","rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Macrow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-06-12T07:13:43.000Z","updated_at":"2023-09-21T02:48:07.000Z","dependencies_parsed_at":"2022-08-20T16:00:52.939Z","dependency_job_id":null,"html_url":"https://github.com/Macrow/rails_kindeditor","commit_stats":null,"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Macrow%2Frails_kindeditor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Macrow%2Frails_kindeditor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Macrow%2Frails_kindeditor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Macrow%2Frails_kindeditor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Macrow","download_url":"https://codeload.github.com/Macrow/rails_kindeditor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225342794,"owners_count":17459474,"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":["kindeditor","rails"],"created_at":"2024-08-04T04:03:36.456Z","updated_at":"2024-11-19T11:30:44.798Z","avatar_url":"https://github.com/Macrow.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Kindeditor for Ruby on Rails  [![Gem Version](https://badge.fury.io/rb/rails_kindeditor.png)](http://badge.fury.io/rb/rails_kindeditor)\n\nKindeditor is a WYSIWYG javascript editor, visit http://www.kindsoft.net for details.\nrails_kindeditor will helps your rails app integrate with kindeditor, includes images and files uploading.\n\n\u003cimg src=\"https://github.com/Macrow/rails_kindeditor/raw/master/screenshots/rails_kindeditor.png\" alt=\"rails_indeditor\"\u003e\n\n## Installation and usage\n\n### Add this to your Gemfile\n\n```ruby\n  gem 'jquery-rails'\n  gem 'rails_kindeditor'\n```\nnotice: Rails 5.1 has dropped dependency on jQuery from the default,but rails_kindeditor need 'jquery-rails'.\n\n### Run \"bundle\" command.\n\n```bash\n  bundle\n```\n\n### Run install generator:\n\n```bash\n  rails g rails_kindeditor:install\n```\nnotice: rails_kindeditor needs applications.js in your project.\n\n### Production mode\n\nPrecompiling assets no longer automatically copies non-JS/CSS assets from vendor/assets and lib/assets. see https://github.com/rails/rails/pull/7968\nplease run 'rails kindeditor:assets', this method just copy kindeditor into public folder.\n\n```bash\n  rails kindeditor:assets\n```\n\n### Usage:\n\n```ruby\n  1. \u003c%= kindeditor_tag :content, 'default content value' %\u003e\n     # or \u003c%= kindeditor_tag :content, 'default content value', :width =\u003e 800, :height =\u003e 300 %\u003e\n     # or \u003c%= kindeditor_tag :content, 'default content value', :allowFileManager =\u003e false %\u003e\n```\n\n```ruby\n  2. \u003c%= form_for @article do |f| %\u003e\n       ...\n       \u003c%= f.kindeditor :content %\u003e\n       # or \u003c%= f.kindeditor :content, :width =\u003e 800, :height =\u003e 300 %\u003e\n       # or \u003c%= f.kindeditor :content, :allowFileManager =\u003e false %\u003e\n       ...\n     \u003c% end %\u003e\n```\nYou can use kindeditor's initial parameters as usual, please visit http://www.kindsoft.net/docs/option.html for details.\n\nadditionally, rails_kindeditor provides one \"simple_mode\" parameter for render simple mode quickly.\n\n\u003cimg src=\"https://github.com/Macrow/rails_kindeditor/raw/master/screenshots/simple_mode.png\" alt=\"simple mode\"\u003e\n\n```ruby\n  kindeditor_tag :content, 'default content value', :simple_mode =\u003e true\n  f.kindeditor :content, :simple_mode =\u003e true\n  f.input :content, :as =\u003e :kindeditor, :input_html =\u003e { :simple_mode =\u003e true } # simple_form \u0026 formtastic\n```\n\nThat's all.\n\n### Work with Turbolinks5\n\nCreate a file app/assets/javascripts/load_kindeditor.coffee\n\n```coffeescript\n  # coffeescript code\n  $(document).on 'turbolinks:before-cache', -\u003e\n    KindEditor.remove('.rails_kindeditor')\n\n  $(document).on 'turbolinks:load', -\u003e\n    $('.rails_kindeditor').each -\u003e\n      KindEditor.create \"##{$(this).attr('id')}\", \"allowFileManager\": true, \"uploadJson\": $(this).data('upload'), \"fileManagerJson\": $(this).data('filemanager'), \"width\": '100%', \"height\": '300'\n```\n\nsimple mode\n```coffeescript\n  # coffeescript code\n  $(document).on 'turbolinks:before-cache', -\u003e\n    KindEditor.remove('.rails_kindeditor')\n\n  $(document).on 'turbolinks:load', -\u003e\n    $('.rails_kindeditor').each -\u003e\n      KindEditor.create \"##{$(this).attr('id')}\", \"allowFileManager\": true, \"uploadJson\": $(this).data('upload'), \"fileManagerJson\": $(this).data('filemanager'), \"width\": '100%', \"height\": '300', \"items\":[\"fontname\",\"fontsize\",\"|\",\"forecolor\",\"hilitecolor\",\"bold\",\"italic\",\"underline\",\"removeformat\",\"|\",\"justifyleft\",\"justifycenter\",\"justifyright\",\"insertorderedlist\",\"insertunorderedlist\",\"|\",\"emoticons\",\"image\",\"link\"]\n```\n\nMake sure the file is loaded from your app/assets/javascripts/application.js\n\n### Include javascript files at bottom ? Not in the head tag ? How can I load kindeditor correctly ?\n\nFor some reasons, you includes javascript files at bottom in your template, rails_kindeditor provides a options for lazyload:\n\n```ruby\n  \u003c%= f.kindeditor :content, :window_onload =\u003e true %\u003e\n```\n\nWarning: Kindeditor will be load when the others have been loaded.\n\n## SimpleForm and Formtastic integration\n\n### simple_form:\n\n```ruby\n  \u003c%= form.input :content, :as =\u003e :kindeditor %\u003e\n  # or\n  \u003c%= form.input :content, :as =\u003e :kindeditor, :label =\u003e false, :input_html =\u003e { :width =\u003e 800, :height =\u003e 300 } %\u003e\n```\n\n### formtastic:\n\n```ruby\n  \u003c%= form.input :content, :as =\u003e :kindeditor %\u003e\n  # or\n  \u003c%= form.input :content, :as =\u003e :kindeditor, :input_html =\u003e { :height =\u003e 300 } %\u003e\n```\n\n## How to get kindeditor's content\n\n```ruby\n  \u003c%= form_for @article do |f| %\u003e\n    \u003c%= f.kindeditor :content, :editor_id =\u003e 'my_editor' %\u003e\n  \u003c% end %\u003e\n```\n\nYou can get content like this:\n\n```javascript\n  // Javascript code\n  my_editor.html();\n```\n\n## Upload options configuration\n\nWhen you run \"rails generate rails_kindeditor:install\", installer will copy configuration files in config/initializers folder.\nYou can customize some option for uploading.\n\n```ruby\n  # Specify the subfolders in public directory.\n  # You can customize it , eg: config.upload_dir = 'this/is/my/folder'\n  config.upload_dir = 'uploads'\n\n  # Allowed file types for upload.\n  config.upload_image_ext = %w[gif jpg jpeg png bmp]\n  config.upload_flash_ext = %w[swf flv]\n  config.upload_media_ext = %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb]\n  config.upload_file_ext = %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]\n\n  # Porcess upload image size, need mini_magick\n  #     before    =\u003e after\n  # eg: 1600x1600 =\u003e 800x800\n  #     1600x800  =\u003e 800x400\n  #     400x400   =\u003e 400x400 # No Change\n  # config.image_resize_to_limit = [800, 800]\n```\n\n## Asset host options configuration\n\n```ruby\n  # if you have config in your rails application like this:\n  # /config/enviroments/production.rb\n  #   # config.action_controller.asset_host = \"http://asset.example.com\"\n  #   # config.assets.prefix = \"assets_prefx\"\n  # then you should:\n  #\n  config.asset_url_prefix = \"http://asset.example.com/assets_prefx/\" if Rails.env.production?\n```\n\n\n## Save upload file information into database(optional)\n\nrails_kindeditor can save upload file information into database.\n\n### Just run migration generate, there are two ORM options for you: 1.active_record 2.mongoid, default is active_record.\n\n```bash\n  rails generate rails_kindeditor:migration\n  or\n  rails generate rails_kindeditor:migration -o mongoid\n```\n\n### The generator will copy model and migration to your application. When you are done, remember run rake db:migrate:\n\n```bash\n  rake db:migrate\n```\n\n### Delete uploaded files automatically (only for active_record)\n\nYou can specify the owner for uploaded files, when the owner was destroying, all the uploaded files(belongs to the owner) will be destroyed automatically.\n\n###1. specify the owner_id for kindeditor\n\n```ruby\n   \u003c%= form_for @article do |f| %\u003e\n     ...\n     \u003c%= f.kindeditor :content, :owner =\u003e @article  %\u003e\n     ...\n   \u003c% end %\u003e\n```\n\n```ruby\nWarnning: the @article must be created before this scene, the @article.id should not be empty.\n```\n\n###2. add has_many_kindeditor_assets in your own model\n\n```ruby\n  class Article \u003c ActiveRecord::Base\n    has_many_kindeditor_assets :attachments, :dependent =\u003e :destroy\n    # has_many_kindeditor_assets :attachments, :dependent =\u003e :nullify\n    # has_many_kindeditor_assets :your_name, :dependent =\u003e :destroy\n  end\n```\n\n###3. relationship\n\n```ruby\n  article = Article.first\n  article.attachments # =\u003e the article's assets uploaded by kindeditor\n  asset = article.attachments.first\n  asset.owner # =\u003e aritcle\n```\n\n### If you're using mongoid, please add 'gem \"carrierwave-mongoid\"' in your Gemfile\n\n```ruby\n  gem 'carrierwave-mongoid'\n```\n\n## License\n\nMIT License.\n\n\n\n# Kindeditor for Ruby on Rails 中文文档\n\nKindeditor是国产的所见即所得javascript富文本编辑器, 访问 http://www.kindsoft.net 获取更多信息.\nrails_kindeditor可以帮助你的rails程序集成kindeditor,包括了图片和附件上传功能，文件按照类型、日期进行存储。\n\n## 安装及使用\n\n### 将下面代码加入Gemfile：\n\n```ruby\n  gem 'jquery-rails'\n  gem 'rails_kindeditor'\n```\n注意：Rails 5.1 已没有将jQuery作为默认设置,但rails_kindeditor需要'jquery-rails'.\n\n### 运行\"bundle\"命令：\n\n```bash\n  bundle\n```\n\n### 安装Kindeditor，运行下面的代码：\n\n```bash\n  rails g rails_kindeditor:install\n```\n注意： 在你的工程中需要有application.js文件。\n\n### Production mode\n\nPrecompiling assets不再自动从vendor/assets和lib/assets拷贝非JS/CSS文件. 参见 https://github.com/rails/rails/pull/7968\n如果要使用生产模式，请运行'rails kindeditor:assets', 此方法可将kindeditor自动拷贝到你的public/assets目录.\n\n```bash\n  rails kindeditor:assets\n```\n\n### 使用方法:\n\n```ruby\n  1. \u003c%= kindeditor_tag :content, 'default content value' %\u003e\n     # or \u003c%= kindeditor_tag :content, 'default content value', :width =\u003e 800, :height =\u003e 300 %\u003e\n     # or \u003c%= kindeditor_tag :content, 'default content value', :allowFileManager =\u003e false %\u003e\n```\n\n```ruby\n  2. \u003c%= form_for @article do |f| -%\u003e\n       ...\n       \u003c%= f.kindeditor :content %\u003e\n       # or \u003c%= f.kindeditor :content, :width =\u003e 800, :height =\u003e 300 %\u003e\n       # or \u003c%= f.kindeditor :content, :allowFileManager =\u003e false %\u003e\n       ...\n     \u003c% end -%\u003e\n```\n你可以像往常那样使用kindeditor自身的初始化参数，请访问 http://www.kindsoft.net/docs/option.html 查看更多参数。\n\n另外，rails_kindeditor还额外提供一个\"simple_mode\"参数，以便快捷使用简单模式的kindeditor。\n\n```ruby\n  kindeditor_tag :content, 'default content value', :simple_mode =\u003e true\n  f.kindeditor :content, :simple_mode =\u003e true\n  f.input :content, :as =\u003e :kindeditor, :input_html =\u003e { :simple_mode =\u003e true } # simple_form \u0026 formtastic  \n```\n\n完毕！\n\n### 如何在Turbolinks5下使用\n\n创建如下文件 app/assets/javascripts/load_kindeditor.coffee\n\n```coffeescript\n  # coffeescript code\n  $(document).on 'turbolinks:before-cache', -\u003e\n    KindEditor.remove('.rails_kindeditor')\n\n  $(document).on 'turbolinks:load', -\u003e\n    $('.rails_kindeditor').each -\u003e\n      KindEditor.create \"##{$(this).attr('id')}\", \"allowFileManager\": true, \"uploadJson\": $(this).data('upload'), \"fileManagerJson\": $(this).data('filemanager'), \"width\": '100%', \"height\": '300'\n```\n\n简单编辑模式\n```coffeescript\n  # coffeescript code\n  $(document).on 'turbolinks:before-cache', -\u003e\n    KindEditor.remove('.rails_kindeditor')\n\n  $(document).on 'turbolinks:load', -\u003e\n    $('.rails_kindeditor').each -\u003e\n      KindEditor.create \"##{$(this).attr('id')}\", \"allowFileManager\": true, \"uploadJson\": $(this).data('upload'), \"fileManagerJson\": $(this).data('filemanager'), \"width\": '100%', \"height\": '300', \"items\":[\"fontname\",\"fontsize\",\"|\",\"forecolor\",\"hilitecolor\",\"bold\",\"italic\",\"underline\",\"removeformat\",\"|\",\"justifyleft\",\"justifycenter\",\"justifyright\",\"insertorderedlist\",\"insertunorderedlist\",\"|\",\"emoticons\",\"image\",\"link\"]\n```\n\n请确保以上文件被app/assets/javascripts/application.js正确加载\n\n### 把javascript放在模板最下方，不放在head里面，如何正确加载kindeditor？\n\n有时候，为了加快页面载入速度，也许你会把javascript引用放在template的底部，rails_kindeditor提供了一个参数可以确保正常加载：\n\n```ruby\n  \u003c%= f.kindeditor :content, :window_onload =\u003e true %\u003e\n```\n\n警告：Kindeditor会在页面所有的内容加载完毕后才进行加载，所以需谨慎使用\n\n## SimpleForm与Formtastic集成：\n\n### simple_form:\n\n```ruby\n  \u003c%= form.input :content, :as =\u003e :kindeditor, :label =\u003e false, :input_html =\u003e { :width =\u003e 800, :height =\u003e 300 } %\u003e\n```\n\n### formtastic:\n\n```ruby\n  \u003c%= form.input :content, :as =\u003e :kindeditor %\u003e\n  \u003c%= form.input :content, :as =\u003e :kindeditor, :input_html =\u003e { :height =\u003e 300 } %\u003e\n```\n## 如何获取kindeditor的内容\n\n```ruby\n  \u003c%= form_for @article do |f| %\u003e\n    \u003c%= f.kindeditor :content, :editor_id =\u003e 'my_editor' %\u003e\n  \u003c% end %\u003e\n```\n\n可通过下面的Javascript代码获取内容:\n\n```javascript\n  // Javascript code\n  my_editor.html();\n```\n\n## 上传图片及文件配置\n\n当你运行\"rails generate rails_kindeditor:install\"的时候，安装器会将配置文件拷贝到config/initializers文件夹。\n你可以配置以下上传选项：\n\n```ruby\n  # 指定上传目录，目录可以指定多级，都存储在public目录下.\n  # You can customize it , eg: config.upload_dir = 'this/is/my/folder'\n  config.upload_dir = 'uploads'\n\n  # 指定允许上传的文件类型.\n  config.upload_image_ext = %w[gif jpg jpeg png bmp]\n  config.upload_flash_ext = %w[swf flv]\n  config.upload_media_ext = %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb]\n  config.upload_file_ext = %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]\n\n  # 处理上传文件，需要mini_magick\n  #     处理以前      =\u003e 处理以后\n  # eg: 1600x1600 =\u003e 800x800\n  #     1600x800  =\u003e 800x400\n  #     400x400   =\u003e 400x400 # 图片小于该限制尺寸则不作处理\n  # config.image_resize_to_limit = [800, 800]\n```\n\n## 静态资源地址配置\n\n```ruby\n  # if you have config in your rails application like this:\n  # /config/enviroments/production.rb\n  #   # config.action_controller.asset_host = \"http://asset.example.com\"\n  #   # config.assets.prefix = \"assets_prefx\"\n  # then you should:\n  #\n  config.asset_url_prefix = \"http://asset.example.com/assets_prefx/\" if Rails.env.production?\n```\n\n\n## 将上传文件信息记录入数据库（可选）\n\nrails_kindeditor 可以将上传文件信息记录入数据库，以便扩展应用.\n\n### 运行下面的代码，有两项选项：1.active_record 2.mongoid，默认是active_record。\n\n```bash\n  rails generate rails_kindeditor:migration\n  or\n  rails generate rails_kindeditor:migration -o mongoid\n```\n\n### 运行下面的代码：\n\n```bash\n  rake db:migrate\n```\n\n### 自动删除上传的文件(仅在active_record下工作)\n\n你可以为上传的文件指定归属，比如一名用户，或者一篇文章，当用户或者文章被删除时，所有属于该用户或者该文章的上传文件将会被自动删除。\n\n###1. 为kindeditor指定owner_id\n\n```ruby\n   \u003c%= form_for @article do |f| %\u003e\n     ...\n     \u003c%= f.kindeditor :content, :owner =\u003e @article  %\u003e\n     ...\n   \u003c% end %\u003e\n```\n\n```ruby\n警告: @article应该事先被创建，@article.id不应该是空的。\n```\n\n###2. 在你自己的模型里加入has_many_kindeditor_assets\n\n```ruby\n  class Article \u003c ActiveRecord::Base\n    has_many_kindeditor_assets :attachments, :dependent =\u003e :destroy\n    # has_many_kindeditor_assets :attachments, :dependent =\u003e :nullify\n    # has_many_kindeditor_assets :your_name, :dependent =\u003e :destroy\n  end\n```\n\n###3. 相互关系\n\n```ruby\n  article = Article.first\n  article.attachments # =\u003e the article's assets uploaded by kindeditor\n  asset = article.attachments.first\n  asset.owner # =\u003e aritcle\n```\n\n### 如果你使用的是mongoid, 请在你的Gemfile里加入'gem \"carrierwave-mongoid\"'\n\n```ruby\n  gem 'carrierwave-mongoid'\n```\n\n## License\n\nMIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMacrow%2Frails_kindeditor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMacrow%2Frails_kindeditor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMacrow%2Frails_kindeditor/lists"}