From 2e861f6b69c804e6b5fa77ea2cf5366aa38bfc31 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 29 Jan 2019 11:30:35 +1100 Subject: [PATCH] add wizard raw template pre-compilation --- assets/javascripts/wizard-custom.js | 1 + assets/javascripts/wizard-plugin.js.erb | 2 ++ .../javascripts/wizard-raw-templates.js.erb | 22 +++++++++++++++++++ views/layouts/wizard.html.erb | 1 + 4 files changed, 26 insertions(+) create mode 100644 assets/javascripts/wizard-raw-templates.js.erb diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index 6c8cd3fc..c0b0ae2b 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -21,4 +21,5 @@ window.Discourse = {} window.Wizard = {}; Wizard.SiteSettings = {}; +Wizard.RAW_TEMPLATES = {}; Discourse.__widget_helpers = {}; diff --git a/assets/javascripts/wizard-plugin.js.erb b/assets/javascripts/wizard-plugin.js.erb index d16858f8..16175206 100644 --- a/assets/javascripts/wizard-plugin.js.erb +++ b/assets/javascripts/wizard-plugin.js.erb @@ -4,6 +4,8 @@ Discourse.unofficial_plugins.each do |plugin| plugin_name = plugin.metadata.name if require_plugin_assets = CustomWizard::Field.require_assets[plugin_name] plugin.each_globbed_asset do |f, is_dir| + next if f.include? "raw.hbs" + if require_plugin_assets.any? { |dir| f.include?(dir) } if is_dir depend_on(f) diff --git a/assets/javascripts/wizard-raw-templates.js.erb b/assets/javascripts/wizard-raw-templates.js.erb new file mode 100644 index 00000000..8c6c37c6 --- /dev/null +++ b/assets/javascripts/wizard-raw-templates.js.erb @@ -0,0 +1,22 @@ +<%= +result = '' +Discourse.unofficial_plugins.each do |plugin| + plugin_name = plugin.metadata.name + if require_plugin_assets = CustomWizard::Field.require_assets[plugin_name] + plugin.each_globbed_asset do |f, is_dir| + if f.include? "raw.hbs" + name = File.basename(f, ".raw.hbs") + compiled = Barber::Precompiler.new().compile(File.read(f)) + result << " + (function() { + if ('Wizard' in window) { + Wizard.RAW_TEMPLATES['javascripts/#{name}'] = requirejs('discourse-common/lib/raw-handlebars').template(#{compiled}); + } + })(); + " + end + end + end +end +result +%> diff --git a/views/layouts/wizard.html.erb b/views/layouts/wizard.html.erb index 5b1d1843..613193e7 100644 --- a/views/layouts/wizard.html.erb +++ b/views/layouts/wizard.html.erb @@ -40,5 +40,6 @@ <%- end %> <%= preload_script 'wizard-custom-start' %> + <%= preload_script 'wizard-raw-templates' %>