New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can you add plugins to CKEditor for Ruby? #450

Closed
ryanxdrake opened this Issue Jun 4, 2014 · 22 comments

Comments

Projects
None yet
@ryanxdrake
Copy link

ryanxdrake commented Jun 4, 2014

Hi there,

I was just curious which folder to add plugins to for this gem?

Thanks!

@renatosuero

This comment has been minimized.

Copy link

renatosuero commented Jun 4, 2014

Hi @iamryandrake ,

I'm using this plugin http://ckeditor.com/addon/eqneditor

My configurations:

Create a folder in "app/assets/javascripts/ckeditor"
Create a folder in "app/assets/javascripts/ckeditor/plugins"
Create a file in "app/assets/javascripts/ckeditor/config.js"
Paste the plugin in folder plugins and configure your config.js

My config.js
CKEDITOR.editorConfig = function( config )
{
config.extraPlugins = 'eqneditor';
};

my english is bad,but I hope has helped

@zolzaya

This comment has been minimized.

Copy link

zolzaya commented Jun 13, 2014

Hello guys,
I'm trying to use youtube plugin to ckeditor. But when I paste it into app/assets/javascripts/ckeditor/plugins folder it's working fine in development env. But in production env it's not work. I'm did a little research. After rake assets:precompile command youtube plugin is not fully copied to public/assets/ckeditor/plugins folder. It's only copy the images. I don't have any idea?

@ryanxdrake

This comment has been minimized.

Copy link

ryanxdrake commented Jun 13, 2014

Did you include the plugin in your config.js file?

Something like -
config.extraPlugins='youtube';

Also open dev tools and see any comments. Often in dev/prod environments, different comments are spat out into the dev tools.

@zolzaya

This comment has been minimized.

Copy link

zolzaya commented Jun 13, 2014

Yes of course.

@renatosuero

This comment has been minimized.

Copy link

renatosuero commented Jun 20, 2014

@zolzaya

I add my plugin in ckeditor.rake,my file

namespace :ckeditor do
desc 'Create nondigest versions of some ckeditor assets (e.g. moono skin png)'
task :create_nondigest_assets do
fingerprint = /-[0-9a-f]{32}./
for file in Dir['public/assets/ckeditor/contents-.css', 'public/assets/ckeditor/skins/moono/.png','public/assets/ckeditor/plugins/eqneditor/*']
next unless file =~ fingerprint
nondigest = file.sub fingerprint, '.'
FileUtils.cp file, nondigest, verbose: true
end
end
end

###auto run ckeditor:create_nondigest_assets after assets:precompile
Rake::Task['assets:precompile'].enhance do
Rake::Task['ckeditor:create_nondigest_assets'].invoke
end

When run the command rake assets:precompile ,will run this task above.

@jhenkens

This comment has been minimized.

Copy link
Contributor

jhenkens commented Aug 12, 2014

I just thought I'd throw my solution in here. I added the following to the end of ckeditor.rb, after the config.assets_plugins line. It adds the addon files to the asset compilation tree, and therefore the standard ckeditor.rake task will properly copy them.

  #handle custom addons
  assets_root =  Rails.root.join('app','assets','javascripts')
  ckeditor_plugins_root = assets_root.join('ckeditor','plugins')
  %w(openlink sourcedialog).each do |ckeditor_plugin|
    Ckeditor.assets += Dir[ckeditor_plugins_root.join(ckeditor_plugin, '**', '*.js')].map {|x| x.sub(assets_root.to_path, '').sub(/^\/+/, '')}
@zolzaya

This comment has been minimized.

Copy link

zolzaya commented Aug 13, 2014

Thank you guys, I just solved it same way :D.

@opie-scripts

This comment has been minimized.

Copy link

opie-scripts commented Aug 25, 2014

what is your way, i have same problem

@jhenkens

This comment has been minimized.

Copy link
Contributor

jhenkens commented Aug 25, 2014

@infira Put your plugins in app/assets/javascripts/ckeditor/plugins and then add my code from above to your ckeditor.rb initializer. Change the array in the second to last line to point to the plugins you have. Then you just need to enable the plugin via standard ckeditor techniques of editing the config.rb

@zolzaya

This comment has been minimized.

Copy link

zolzaya commented Aug 26, 2014

@infira, follow the @jhenkens is instruction and here is the my way. Save below task to lib/tasks/ckeditor.rb. BTW this task is for youtube plugin.

require 'fileutils'

desc "Copy youtube plugin"
task "ckeditor:copy:plugins" => :environment do
  source = Rails.root.join('app', 'assets', 'javascripts', 'ckeditor', 'plugins')
  dest = Rails.root.join('public', 'assets', 'ckeditor', 'plugins')
  FileUtils.copy_entry source, dest
end

# auto run ckeditor:create_nondigest_assets after assets:precompile
Rake::Task['assets:precompile'].enhance do
  Rake::Task['ckeditor:copy:plugins'].invoke
end

Good luck 👍

@opie-scripts

This comment has been minimized.

Copy link

opie-scripts commented Aug 26, 2014

thanks (Y)

@alepore

This comment has been minimized.

Copy link

alepore commented Sep 29, 2014

thanks, @jhenkens code was very useful.
would be great to have this included on the gem, with something like a config.extra_plugins = ... on the initializer.

what do you think?

@jhenkens

This comment has been minimized.

Copy link
Contributor

jhenkens commented Oct 1, 2014

I personally feel that if it is added to an initializer option in the gem, that the gem should also provide some sort of scaffold for the config.js to include those plugins. It would be useful, indeed, to have a 'gem supported' way to add these assets to the rails asset pipeline through the initializer, but I'm not sure I want to go about doing that. CKEditor kinda scares me - I don't know why I still use it, and often have no idea why sometimes stuff I do works, and sometimes it doesn't.

@Anyoks

This comment has been minimized.

Copy link

Anyoks commented Jan 12, 2016

Added plugin, Thank you @jhenkens, @zolzaya and @iamryandrake for the solutions you posted. Helped me a great deal.

I have an issue though, the plugin worked on development mode and would not appear on production. The logs show nothing substantial. Anyone figure out how to get it to work? Been working all day in this!

Thank you!

Config.js

CKEDITOR.editorConfig = function( config )
{
  config.extraPlugins = 'dialog,dialogui,eqneditor';
};

ckeditor.rb

 config.assets_plugins = ['dialog','dialogui','eqneditor']
 #handle custom addons
 assets_root =  Rails.root.join('app','assets','javascripts')
 ckeditor_plugins_root = assets_root.join('ckeditor','plugins')
  %w(openlink sourcedialog).each do |ckeditor_plugin|
    Ckeditor.assets += Dir[ckeditor_plugins_root.join(ckeditor_plugin, '**', '*.js')].map {|x|              x.sub(assets_root.to_path, '').sub(/^\/+/, '')}
  end

Interesting thing is, When I have eqneditor alone on the list of plugins, it works perfectly in development, but not in production. When I add the other plugins, that are said to be required by all plugins, the eqneditor plugin makes the whole page freeze till I refresh and loose all the data.

@arpit016

This comment has been minimized.

Copy link

arpit016 commented Jul 1, 2017

@Anyoks Did you made it to work in production?, I am facing similar issue.

@krongk

This comment has been minimized.

Copy link

krongk commented Jul 17, 2017

Rails 5.5.1
gem ckeditor 4.2.2

the same issue in production env.

@Babbz75

This comment has been minimized.

Copy link

Babbz75 commented Aug 16, 2017

Anyone having trouble getting the iframe plugin to work?

https://ckeditor.com/addon/iframe

@williamair1

This comment has been minimized.

Copy link

williamair1 commented Oct 25, 2017

Is there a working solution for this? I cannot get it to work as well.

@bnymn

This comment has been minimized.

Copy link

bnymn commented Oct 25, 2017

@williamair1 Did you try the second message on this issue? Written by @renatosuero.

@williamair1

This comment has been minimized.

Copy link

williamair1 commented Oct 25, 2017

I tried the solutions suggested by both @renatosuero and @jhenkens. I was trying to install the lite plugin.
As for @renatosuero's solution, I tried with the eqneditor as well.

  1. Downloaded the zipped file from the link
  2. Created the /javascripts/ckeditor/plugins folder and unzipped the file at this location
  3. Created the config.js file and added the plugin
  4. Restarted server, but see no difference in the toolbox.
@Tashows

This comment has been minimized.

Copy link

Tashows commented May 29, 2018

Shouldn't:

%w(openlink sourcedialog).each do |ckeditor_plugin| Ckeditor.assets += Dir[ckeditor_plugins_root.join(ckeditor_plugin, '**', '*.js')].map {|x| x.sub(assets_root.to_path, '').sub(/^\/+/, '')} end

be replaced with this?

config.assets_plugins.each do |ckeditor_plugin| Ckeditor.assets += Dir[ckeditor_plugins_root.join(ckeditor_plugin, '**', '*.js')].map {|x| x.sub(assets_root.to_path, '').sub(/^\/+/, '')} end

I'm saying this cause I've seen that code being used in other questions and everyone has those two plugins (openlink and sourcedialog), when it seems that there should be a note that they need to be changed. Or did I understand something wrong?

@stale

This comment has been minimized.

Copy link

stale bot commented Dec 4, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 4, 2018

@stale stale bot closed this Dec 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment