2014-10-29 12:24:51 +08:00
|
|
|
# barber patches to re-route raw compilation via ember compat handlebars
|
|
|
|
|
2016-04-18 10:47:52 +08:00
|
|
|
class Barber::Precompiler
|
|
|
|
def sources
|
|
|
|
[File.open("#{Rails.root}/vendor/assets/javascripts/handlebars.js"), precompiler]
|
|
|
|
end
|
2014-10-29 12:24:51 +08:00
|
|
|
|
2016-04-18 10:47:52 +08:00
|
|
|
def precompiler
|
|
|
|
@precompiler ||= StringIO.new <<END
|
|
|
|
var Discourse = {};
|
|
|
|
#{File.read(Rails.root + "app/assets/javascripts/discourse/lib/ember_compat_handlebars.js")}
|
|
|
|
var Barber = {
|
|
|
|
precompile: function(string) {
|
|
|
|
return Discourse.EmberCompatHandlebars.precompile(string,false).toString();
|
|
|
|
}
|
|
|
|
};
|
2014-10-29 12:24:51 +08:00
|
|
|
END
|
2016-04-18 10:47:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Discourse
|
|
|
|
module Ember
|
|
|
|
module Handlebars
|
|
|
|
module Helper
|
|
|
|
def precompile_handlebars(string)
|
|
|
|
"Discourse.EmberCompatHandlebars.template(#{Barber::Precompiler.compile(string)});"
|
|
|
|
end
|
|
|
|
|
|
|
|
def compile_handlebars(string)
|
|
|
|
"Discourse.EmberCompatHandlebars.compile(#{indent(string).inspect});"
|
|
|
|
end
|
|
|
|
end
|
2014-10-29 12:24:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Ember::Handlebars::Template
|
2016-04-18 10:47:52 +08:00
|
|
|
include Discourse::Ember::Handlebars::Helper
|
|
|
|
|
|
|
|
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
|
|
|
# returned paths with the `.raw` extension and our code is depending on the `.raw`
|
|
|
|
# to find the right template to use.
|
|
|
|
def actual_name(input)
|
|
|
|
actual_name = input[:name]
|
|
|
|
input[:filename].include?('.raw') ? "#{actual_name}.raw" : actual_name
|
2014-10-29 12:24:51 +08:00
|
|
|
end
|
|
|
|
end
|