mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 20:24:05 -06:00
Enumerate deferred scripts with a sprockets helper
This commit is contained in:
parent
aad5d439d0
commit
ec280913b2
@ -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_javascripts %>;
|
||||
|
||||
return function(asset){ return map[asset]; };
|
||||
})();
|
||||
|
20
config/initializers/deferred_javascripts_helper.rb
Normal file
20
config/initializers/deferred_javascripts_helper.rb
Normal file
@ -0,0 +1,20 @@
|
||||
module DeferredJavascriptsHelper
|
||||
|
||||
# Provides a javascript map of the files in the 'defer' directory
|
||||
def deferred_javascripts
|
||||
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
|
||||
|
||||
module Sprockets::Rails::Helper
|
||||
include DeferredJavascriptsHelper
|
||||
end
|
Loading…
Reference in New Issue
Block a user