FIX: Customization templates were not working with Glimmer2

This commit is contained in:
Robin Ward 2016-12-27 12:17:30 -05:00
parent 3786d3679c
commit 889efe48be
1 changed files with 20 additions and 13 deletions

View File

@ -45,20 +45,27 @@ PLUGIN_API_JS
doc = Nokogiri::HTML.fragment(html) doc = Nokogiri::HTML.fragment(html)
doc.css('script[type="text/x-handlebars"]').each do |node| doc.css('script[type="text/x-handlebars"]').each do |node|
name = node["name"] || node["data-template-name"] || "broken" name = node["name"] || node["data-template-name"] || "broken"
precompiled = is_raw = name =~ /\.raw$/
if name =~ /\.raw$/ if is_raw
"require('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(node.inner_html)})" template = "require('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(node.inner_html)})"
else
"Ember.HTMLBars.template(#{Barber::Ember::Precompiler.compile(node.inner_html)})"
end
node.replace <<COMPILED node.replace <<COMPILED
<script> <script>
(function() { (function() {
Discourse.RAW_TEMPLATES[#{name.sub(/\.raw$/, '').inspect}] = #{precompiled}; Discourse.RAW_TEMPLATES[#{name.sub(/\.raw$/, '').inspect}] = #{template};
})(); })();
</script> </script>
COMPILED COMPILED
else
template = "Ember.HTMLBars.template(#{Barber::Ember::Precompiler.compile(node.inner_html)})"
node.replace <<COMPILED
<script>
(function() {
Ember.TEMPLATES[#{name.inspect}] = #{template};
})();
</script>
COMPILED
end
end end
doc.css('script[type="text/discourse-plugin"]').each do |node| doc.css('script[type="text/discourse-plugin"]').each do |node|