mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
Merge pull request #2566 from minasmart/master
Enumerate deferred scripts with a sprockets helper
This commit is contained in:
commit
016927d5b9
2 changed files with 17 additions and 5 deletions
16
app/helpers/deferred_scripts_helper.rb
Normal file
16
app/helpers/deferred_scripts_helper.rb
Normal file
|
@ -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>
|
||||
window.assetPath = (function(){
|
||||
|
||||
// TODO: automate this to grab from the manifest, Rails voodoo should be able to get it
|
||||
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 %>
|
||||
};
|
||||
var map = <%= deferred_scripts %>;
|
||||
|
||||
return function(asset){ return map[asset]; };
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue