Copying javascript files to destination assets directory (almost) without assets pipeline

10 views
Skip to first unread message

Damjan Rems

unread,
Aug 26, 2014, 6:40:15 AM8/26/14
to rubyonra...@googlegroups.com
In my project I am using ckeditor as default HTML editor. One of the
strongest feature of ckeditor is that all its components are loaded from
server when started and can thus be easily extended. Which is also a
nightmare for rails developers because this problem cannot be solved by
assets pipeline especially if used as gem.

In ckeditor gem, which can be found on github
https://github.com/galetahub/ckeditor the problem was solved by adding
every single required file to app.config.assets.precompile which made
(in my case) assets compilation go from 1 minute to >5 minutes. What is
not acceptable.

Not until recently I found out assets:precompile rake task (why is this
so poor mentioned in documentation). Which can be added to every gem and
it is executed once when rake assets:precompile is invoked. So here is
my solution now:

(file lib/tasks/copy_assets.rb)
require 'fileutils'

desc "Copy all ckeditor files from gem's javascript folder to
public/assets/folder"
task "assets:precompile" do
p 'Copying ckeditor directory to public/assets folder *****'

input_dir = File.realpath( File.dirname( __FILE__ ) +
'/../../app/assets/javascripts/ckeditor')
output_dir = Rails.root.join('public/assets')
cp_r(input_dir, output_dir, verbose: true)
end

It works perfectly for me. Is there any problem to be expected except
the usual ones with browser caching?

by
TheR

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages