Skip to content

Commit

Permalink
first shot at #27
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak committed Apr 24, 2012
1 parent 47ad9d0 commit d2240b6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/ember/handlebars/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ def self.default_mime_type
def prepare; end

def evaluate(scope, locals, &block)
template = mustache_to_handlebars(scope, data)

if configuration.precompile
func = Ember::Handlebars.compile(template)
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Ember.Handlebars.template(#{func});\n"
if scope.pathname.to_s =~ /\.raw\.(handlebars|hjs|hbs)/
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Handlebars.compile(#{indent(data).inspect});\n"
else
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Ember.Handlebars.compile(#{indent(template).inspect});\n"
template = mustache_to_handlebars(scope, data)

if configuration.precompile
func = Ember::Handlebars.compile(template)
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Ember.Handlebars.template(#{func});\n"
else
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Ember.Handlebars.compile(#{indent(template).inspect});\n"
end
end
end

private

def mustache_to_handlebars(scope, template)
if scope.pathname.to_s =~ /\.mustache\.(handlebars|hjs)/
if scope.pathname.to_s =~ /\.mustache\.(handlebars|hjs|hbs)/
template.gsub(/\{\{(\w[^\}\}]+)\}\}/){ |x| "{{unbound #{$1}}}" }
else
template
Expand Down

0 comments on commit d2240b6

Please sign in to comment.