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.css('script[type="text/x-handlebars"]').each do |node|
name = node["name"] || node["data-template-name"] || "broken"
precompiled =
if name =~ /\.raw$/
"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
<script>
(function() {
Discourse.RAW_TEMPLATES[#{name.sub(/\.raw$/, '').inspect}] = #{precompiled};
})();
</script>
is_raw = name =~ /\.raw$/
if is_raw
template = "require('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(node.inner_html)})"
node.replace <<COMPILED
<script>
(function() {
Discourse.RAW_TEMPLATES[#{name.sub(/\.raw$/, '').inspect}] = #{template};
})();
</script>
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
doc.css('script[type="text/discourse-plugin"]').each do |node|