Merge pull request #2566 from minasmart/master
Enumerate deferred scripts with a sprockets helper
This commit is contained in:
commit
016927d5b9
|
@ -0,0 +1,16 @@
|
||||||
|
module DeferredScriptsHelper
|
||||||
|
|
||||||
|
# Provides a javascript map of the files in the 'defer' directory
|
||||||
|
def deferred_scripts
|
||||||
|
files = {}
|
||||||
|
|
||||||
|
Dir.glob("#{Rails.root}/app/assets/javascripts/defer/*.js").each do |file|
|
||||||
|
module_name = "defer/#{File.basename(file, '.js')}"
|
||||||
|
file_name = asset_path("defer/#{File.basename(file)}")
|
||||||
|
files[module_name] = file_name
|
||||||
|
end
|
||||||
|
|
||||||
|
return files.to_json.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,11 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
window.assetPath = (function(){
|
window.assetPath = (function(){
|
||||||
|
|
||||||
// TODO: automate this to grab from the manifest, Rails voodoo should be able to get it
|
var map = <%= deferred_scripts %>;
|
||||||
var map = {
|
|
||||||
'defer/html-sanitizer-bundle': <%= asset_path('defer/html-sanitizer-bundle.js').inspect.html_safe %>,
|
|
||||||
'defer/google_diff_match_patch': <%= asset_path('defer/google_diff_match_patch.js').inspect.html_safe %>
|
|
||||||
};
|
|
||||||
|
|
||||||
return function(asset){ return map[asset]; };
|
return function(asset){ return map[asset]; };
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue