mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:09:00 +08:00
FIX: Use addRawTemplates
even when compiling .hbr
files (#12228)
Without this patch, we'd be using the `__RAW_TEMPLATES` global which is incompatible with Ember CLI.
This commit is contained in:
parent
a9b6f4d829
commit
79502b5b10
|
@ -41,11 +41,11 @@ module Discourse
|
||||||
module Ember
|
module Ember
|
||||||
module Handlebars
|
module Handlebars
|
||||||
module Helper
|
module Helper
|
||||||
def precompile_handlebars(string)
|
def precompile_handlebars(string, input = nil)
|
||||||
"requirejs('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(string)});"
|
"requirejs('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(string)});"
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile_handlebars(string)
|
def compile_handlebars(string, input = nil)
|
||||||
"requirejs('discourse-common/lib/raw-handlebars').compile(#{indent(string).inspect});"
|
"requirejs('discourse-common/lib/raw-handlebars').compile(#{indent(string).inspect});"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -54,22 +54,74 @@ module Discourse
|
||||||
end
|
end
|
||||||
|
|
||||||
class Ember::Handlebars::Template
|
class Ember::Handlebars::Template
|
||||||
include Discourse::Ember::Handlebars::Helper
|
prepend Discourse::Ember::Handlebars::Helper
|
||||||
|
|
||||||
def precompile_handlebars(string, input = nil)
|
def path_for(module_name, config)
|
||||||
"requirejs('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(string)});"
|
# We need this for backward-compatibility reasons.
|
||||||
end
|
# Plugins may not have an app subdirectory.
|
||||||
|
template_path(module_name, config).inspect.gsub('discourse/templates/', '')
|
||||||
def compile_handlebars(string, input = nil)
|
|
||||||
"requirejs('discourse-common/lib/raw-handlebars').compile(#{indent(string).inspect});"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def global_template_target(namespace, module_name, config)
|
def global_template_target(namespace, module_name, config)
|
||||||
# We need this for backward-compatibility reasons.
|
"#{namespace}[#{path_for(module_name, config)}]"
|
||||||
# Plugins may not have an app subdirectory.
|
end
|
||||||
path = template_path(module_name, config).inspect.gsub('discourse/templates/', '')
|
|
||||||
|
|
||||||
"#{namespace}[#{path}]"
|
def call(input)
|
||||||
|
data = input[:data]
|
||||||
|
filename = input[:filename]
|
||||||
|
|
||||||
|
raw = handlebars?(filename)
|
||||||
|
|
||||||
|
if raw
|
||||||
|
template = data
|
||||||
|
else
|
||||||
|
template = mustache_to_handlebars(filename, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
template_name = input[:name]
|
||||||
|
|
||||||
|
module_name =
|
||||||
|
case config.output_type
|
||||||
|
when :amd
|
||||||
|
amd_template_target(config.amd_namespace, template_name)
|
||||||
|
when :global
|
||||||
|
template_path(template_name, config)
|
||||||
|
else
|
||||||
|
raise "Unsupported `output_type`: #{config.output_type}"
|
||||||
|
end
|
||||||
|
|
||||||
|
meta = meta_supported? ? { moduleName: module_name } : false
|
||||||
|
|
||||||
|
if config.precompile
|
||||||
|
if raw
|
||||||
|
template = precompile_handlebars(template, input)
|
||||||
|
else
|
||||||
|
template = precompile_ember_handlebars(template, config.ember_template, input, meta)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if raw
|
||||||
|
template = compile_handlebars(data)
|
||||||
|
else
|
||||||
|
template = compile_ember_handlebars(template, config.ember_template, meta)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
case config.output_type
|
||||||
|
when :amd
|
||||||
|
"define('#{module_name}', ['exports'], function(__exports__){ __exports__['default'] = #{template} });"
|
||||||
|
when :global
|
||||||
|
if raw
|
||||||
|
return <<~RAW_TEMPLATE
|
||||||
|
var __t = #{template};
|
||||||
|
requirejs('discourse-common/lib/raw-templates').addRawTemplate(#{path_for(template_name, config)}, __t);
|
||||||
|
RAW_TEMPLATE
|
||||||
|
end
|
||||||
|
|
||||||
|
target = global_template_target('Ember.TEMPLATES', template_name, config)
|
||||||
|
"#{target} = #{template}\n"
|
||||||
|
else
|
||||||
|
raise "Unsupported `output_type`: #{config.output_type}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
||||||
|
|
Loading…
Reference in New Issue
Block a user