首页 文章

在Rails应用程序中将CodeSnippet插件添加到CKEditor

提问于
浏览
1

我正在尝试将CodeSnippet plugin添加到CKEditor(使用ckeditor-rails安装在我的Rails应用程序中) . 为此,我首先将CodeSnippet插件文件夹及其所有依赖项添加到目录app> assets> javascripts> ckeditor> plugins(因此我的plugins文件夹包含codesnippet,dialog,dialogui,lineutils和widget的文件夹) .

然后我更新了我的app / assets / javascripts / ckeditor / config.js.coffee以包含以下内容:

CKEDITOR.editorConfig = (config) ->
  config.startupShowBorders = true
  config.resize_enabled = false
  config.scayt_autoStartup = true

  config.language = 'en'
  config.width = '445px'
  config.extraPlugins = 'widget,dialog,dialogui,lineutils,codesnippet'

  config.toolbar_Default = [
    { name: 'basicstyles', items: [ 'Bold','Italic','Underline', '-', 'NumberedList','BulletedList', 'Link','Unlink', 'CodeSnippet','RemoveFormat' ] }
  ]
  config.toolbar = 'Default'
  true

当我尝试使用CKEditor加载网页时,我的javascript控制台中出现以下错误:

Uncaught TypeError: undefined is not a function

引用这行小部件/ plugin.js:

CKEDITOR.style.addCustomHandler( {

和同样的错误

Uncaught TypeError: undefined is not a function

引用这行codesnippets / plugin.js:

editor.addContentsCss( path + 'lib/highlight/styles/' + editor.config.codeSnippet_theme + '.css' );

是否有人能够配置此CKEditor以在Rails应用程序中使用CodeSnippet插件?

1 回答

  • 2

    我无法使用任何ckeditor宝石来完成这项工作 . 结果,我完全删除了ck_editor rails gem并直接从ckeditor网站下载了我想要添加的插件 .

    然后我将整个ckeditors文件夹放入我的app> assets> javascripts文件夹中,并将以下内容添加到application.js中

    // =需要ckeditor / ckeditor.js

    我最终不得不通过直接编辑ckeditor / ckeditor.js来进行一些自定义,但我终于能够以这种方式获得CodeSnippet插件 .

    希望这有助于某人!

相关问题