Skip to content

Commit

Permalink
Merge branch 'refs/heads/barber'
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak committed Nov 1, 2012
2 parents c2a7d69 + f2d2cb5 commit bc359f9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 94 deletions.
1 change: 1 addition & 0 deletions ember-rails.gemspec
Expand Up @@ -14,6 +14,7 @@ Gem::Specification.new do |s|
s.add_dependency "execjs", [">= 1.2"]
s.add_dependency "railties", ["~> 3.1"]
s.add_dependency "active_model_serializers"
s.add_dependency "barber"

s.add_development_dependency "rails", ["~> 3.1"]

Expand Down
28 changes: 0 additions & 28 deletions lib/ember/handlebars/assets/ember-precompiler.js

This file was deleted.

54 changes: 0 additions & 54 deletions lib/ember/handlebars/source.rb

This file was deleted.

50 changes: 43 additions & 7 deletions lib/ember/handlebars/template.rb
@@ -1,6 +1,6 @@
require 'sprockets'
require 'sprockets/engines'
require 'ember/handlebars/source'
require 'barber'

module Ember
module Handlebars
Expand All @@ -12,22 +12,58 @@ def self.default_mime_type
def prepare; end

def evaluate(scope, locals, &block)
if scope.pathname.to_s =~ /\.raw\.(handlebars|hjs|hbs)/
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Handlebars.compile(#{indent(data).inspect});\n"
target = template_target(scope)
raw = handlebars?(scope)

if raw
template = data
else
template = mustache_to_handlebars(scope, data)
end

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

"#{target} = #{template}\n"
end

private

def handlebars?(scope)
scope.pathname.to_s =~ /\.raw\.(handlebars|hjs|hbs)/
end

def template_target(scope)
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}]"
end

def compile_handlebars(string)
"Handlebars.compile(#{indent(string).inspect});"
end

def precompile_handlebars(string)
Barber::FilePrecompiler.call(string)
end

def compile_ember_handlebars(string)
"Ember.Handlebars.compile(#{indent(string).inspect});"
end

def precompile_ember_handlebars(string)
Barber::Ember::FilePrecompiler.call(string)
end

def mustache_to_handlebars(scope, template)
if scope.pathname.to_s =~ /\.mustache\.(handlebars|hjs|hbs)/
template.gsub(/\{\{(\w[^\}\}]+)\}\}/){ |x| "{{unbound #{$1}}}" }
Expand Down
2 changes: 0 additions & 2 deletions lib/ember/handlebars/version.rb
@@ -1,5 +1,3 @@
require 'ember/handlebars/source'

module Ember
module Handlebars
VERSION = "1.0.rc.1"
Expand Down
2 changes: 0 additions & 2 deletions lib/ember/version.rb
@@ -1,5 +1,3 @@
require 'ember/handlebars/source'

module Ember
VERSION = "1.0-pre.2"
end
2 changes: 1 addition & 1 deletion test/hjstemplate_test.rb
Expand Up @@ -69,7 +69,7 @@ def with_template_root(root, sep=nil)
test "ensure new lines inside the anon function are persisted" do
get "/assets/templates/new_lines.js"
assert_response :success
assert @response.body.include?("helpers;\n"), @response.body.inspect
assert @response.body.include?("helpers; data = data || {};\n"), @response.body.inspect
end

end

0 comments on commit bc359f9

Please sign in to comment.