Closed jrust closed 12 years ago
I'd suggest adding your plugin paths to config.assets.precompile
instead. This approach may work okay for applications but doesn't scale well to engines. Using precompilation also ensures you get the benefits of minification.
I'm not sure I follow, you're suggesting that it's fine behavior to have 404's come up for every page load in a production environment? How does adding a local plugin to the config.assets.precompile path help? TinyMCE will still try to load the plugin js file when you init it.
@ralfthewise, I looked into adding our custom tiny_mce plugins to the assets precompile path, but it added too much time to production deployment. In the end, I just hooked into the assets precompile task with my own assets.task to accomplish the same thing as my patch above:
# Ensure our custom plugins are copied to precompiled assets path
Rake::Task['assets:precompile:primary'].enhance do
target = File.join(Rails.public_path, Rails.application.config.assets.prefix)
mkdir_p target
%w(app lib vendor).each do |path|
assets = Rails.root.join(path, 'assets', 'javascripts', 'tinymce')
cp_r assets, target if File.directory? assets
end
end
@ralfthewise Adding the plugin path to config.assets.precompile
paths ensures that the relevant plugin javascript files are compiled when you run rake assets:precompile
(which you need to do in production mode with the asset pipeline). This ensures that they can be loaded by TinyMCE.
@jrust Whilst I'm glad your solution works for you, I'm curious as to how much time was added for precompilation, and what paths you added to the config.assets.precompile
paths. tinymce-rails uses the static copying method because TinyMCE itself is particularly large and it also comes pre-minified. Maybe your own plugins are particularly large, but I'm also wondering if maybe you added something similar to "tinymce/*"
to the precompile paths which would result in the entirety of TinyMCE being recompiled.
@spohlenz Good question. I didn't test how long our two tinymce plugins would take to compile. Looks like it would add 2 or 3 css files and 5 or 6 js files. So probably wouldn't cause too many issues, but we were needing the deploy process to be as speedy as possible and since the editor_plugin.js files are already minified we weren't gaining much from compiling them.
@jrust Yeah I looked at your pull request and implemented the same thing in a asset extension on our project, so thanks for that!
@spohlenz Sure, perhaps my confusion is due to not fully understanding the asset precompilation. My understanding is that by adding the plugin path to config.assets.precompile, it will get minified/gzipped and stuffed in with the "application.js" file, along with all other javascript associated with your project. That's great, we now have that plugin in that file and the code is loaded, but won't code in tinymce like:
tinymce.ScriptLoader.add(pluginUrl+"/"+script);
still result in 404 errors?
@ralfthewise The config.assets.precompile
paths are a list of files (or regexes to match against paths) which by default includes application.js
, application.css
and any other non-js or non-css files.
When rake assets:precompile
is run, every file within your asset paths is checked against this list (this includes your app/assets, vendor/assets, etc as well as asset paths within engines). If it matches, it processes any require
directives and minifies the file, saving it within public/assets
.
What this means, is that if you just want to include a file within application.js
, you don't need to add it to your precompile paths.
However if I have my own custom plugin located at app/assets/javascripts/tinymce/plugins/custom/editor_plugin.js
, then I should add tinymce/plugins/custom/editor_plugin.js
to the precompile paths, which will compile the file to public/assets/tinymce/plugins/custom/editor_plugin.js
, thereby allowing it to be loaded via TinyMCE.
Hope that makes sense.
This is an update to the tinymce precompile task to make sure that any custom tinymce plugins are also copied to the precompiled assets folder. Otherwise, when you try to use a custom plugin in production you get a 404 when tinymce goes to load the plugin.