2017-01-26 14:35:46 -05:00
|
|
|
<%
|
|
|
|
ace_gem_path = Bundler.rubygems.find_name('ace-rails-ap').first.full_gem_path
|
|
|
|
ace_workers = Dir[ace_gem_path + '/vendor/assets/javascripts/ace/worker-*.js'].sort.map do |file|
|
|
|
|
File.basename(file, '.js').sub(/^worker-/, '')
|
|
|
|
end
|
|
|
|
ace_modes = Dir[ace_gem_path + '/vendor/assets/javascripts/ace/mode-*.js'].sort.map do |file|
|
|
|
|
File.basename(file, '.js').sub(/^mode-/, '')
|
|
|
|
end
|
|
|
|
%>
|
2017-01-29 17:54:08 -05:00
|
|
|
// Lazy-load configuration when ace.edit is called
|
2017-01-26 14:35:46 -05:00
|
|
|
(function() {
|
2017-01-29 17:54:08 -05:00
|
|
|
var basePath;
|
|
|
|
var ace = window.ace;
|
|
|
|
var edit = ace.edit;
|
|
|
|
ace.edit = function() {
|
|
|
|
window.gon = window.gon || {};
|
|
|
|
basePath = (window.gon.relative_url_root || '').replace(/\/$/, '') + '/assets/ace';
|
|
|
|
ace.config.set('basePath', basePath);
|
2017-01-26 14:35:46 -05:00
|
|
|
|
2017-01-29 17:54:08 -05:00
|
|
|
// configure paths for all worker modules
|
2017-01-26 14:35:46 -05:00
|
|
|
<% ace_workers.each do |worker| %>
|
2017-01-29 17:54:08 -05:00
|
|
|
ace.config.setModuleUrl('ace/mode/<%= worker %>_worker', basePath + '/<%= File.basename(asset_path("ace/worker-#{worker}.js")) %>');
|
2017-01-26 14:35:46 -05:00
|
|
|
<% end %>
|
|
|
|
|
2017-01-29 17:54:08 -05:00
|
|
|
// configure paths for all mode modules
|
2017-01-26 14:35:46 -05:00
|
|
|
<% ace_modes.each do |mode| %>
|
2017-01-29 17:54:08 -05:00
|
|
|
ace.config.setModuleUrl('ace/mode/<%= mode %>', basePath + '/<%= File.basename(asset_path("ace/mode-#{mode}.js")) %>');
|
2017-01-26 14:35:46 -05:00
|
|
|
<% end %>
|
2017-01-29 17:54:08 -05:00
|
|
|
|
|
|
|
// restore original method
|
|
|
|
ace.edit = edit;
|
|
|
|
return ace.edit.apply(ace, arguments);
|
|
|
|
};
|
2017-01-26 14:35:46 -05:00
|
|
|
})();
|