summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/ace/ace_config_paths.js.erb
blob: 5cb1037bc86973521c4bd1b15bc3c3b47d08a30c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<%
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
%>

(function() {
  window.gon = window.gon || {};
  var basePath = (window.gon.relative_url_root || '').replace(/\/$/, '') + '/assets/ace';
  ace.config.set('basePath', basePath);

  // configure paths for all worker modules
<% ace_workers.each do |worker| %>
  <% filename = File.basename(asset_path("ace/worker-#{worker}.js")) %>
  ace.config.setModuleUrl('ace/mode/<%= worker %>_worker', basePath + '/<%= filename %>');
<% end %>

  // configure paths for all mode modules
<% ace_modes.each do |mode| %>
  <% filename = File.basename(asset_path("ace/mode-#{mode}.js")) %>
  ace.config.setModuleUrl('ace/mode/<%= mode %>', basePath + '/<%= filename %>');
<% end %>
})();