Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for emblem.js

  • Loading branch information...
commit ea87a9482dee7063a50034072c2a99d61d031064 1 parent 587a55a
@machty authored
View
2  Gemfile
@@ -1,2 +1,4 @@
source :rubygems
gemspec
+
+gem 'barber', git: 'https://github.com/machty/barber.git'
View
1  ember-rails.gemspec
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
s.add_dependency "railties", [">= 3.1"]
s.add_dependency "active_model_serializers"
s.add_dependency "barber"
+ s.add_dependency "barber-emblem"
s.add_development_dependency "bundler", [">= 1.2.2"]
s.add_development_dependency "appraisal"
View
52 lib/ember/emblem/template.rb
@@ -0,0 +1,52 @@
+require 'sprockets'
+require 'sprockets/engines'
+require 'ember/handlebars/template'
+require 'barber-emblem'
+
+module Ember
+ module Emblem
+ class Template < Handlebars::Template
+
+ def evaluate(scope, locals, &block)
+ target = template_target(scope)
+ raw = handlebars?(scope)
+
+ template = data
+
+ if configuration.precompile
+ if raw
+ template = precompile_emblem(template)
+ else
+ template = precompile_ember_emblem(template)
+ end
+ else
+ if raw
+ template = compile_emblem(data)
+ else
+ template = compile_ember_emblem(template)
+ end
+ end
+
+ "#{target} = #{template}\n"
+ end
+
+ private
+
+ def compile_emblem(string)
+ "Handlebars.compile(#{indent(string).inspect});"
+ end
+
+ def precompile_emblem(string)
+ Barber::Emblem::FilePrecompiler.call(string)
+ end
+
+ def compile_ember_emblem(string)
+ "Emblem.compile(Ember.Handlebars, #{indent(string).inspect});"
+ end
+
+ def precompile_ember_emblem(string)
+ Barber::Emblem::EmberFilePrecompiler.call(string)
+ end
+ end
+ end
+end
View
3  lib/ember/rails/engine.rb
@@ -1,4 +1,5 @@
require 'ember/handlebars/template'
+require 'ember/emblem/template'
require 'active_model_serializers'
module Ember
@@ -20,6 +21,8 @@ class Engine < ::Rails::Engine
sprockets.register_engine '.handlebars', Ember::Handlebars::Template
sprockets.register_engine '.hbs', Ember::Handlebars::Template
sprockets.register_engine '.hjs', Ember::Handlebars::Template
+
+ sprockets.register_engine '.emblem', Ember::Emblem::Template
end
end
end
View
1  test/dummy/app/assets/javascripts/templates/emblem_test.js.emblem
@@ -0,0 +1 @@
+p = test
View
18 test/emblem_test.rb
@@ -0,0 +1,18 @@
+
+require 'test_helper'
+
+class EmblemTemplateTest < ActionController::IntegrationTest
+
+ test "asset pipeline should serve ember emblem template" do
+ get "/assets/templates/emblem_test.js"
+ assert_response :success
+ assert_match /Ember\.TEMPLATES\["emblem_test"\] = Ember\.Handlebars\.template\(function .*"test"/m, @response.body
+ end
+
+ #test "asset pipeline should serve raw handlebars emblem template" do
+ #get "/assets/templates/emblem_test.js"
+ #assert_response :success
+ #assert_match /Ember\.TEMPLATES\["emblem_raw_test"\] = Handlebars\.template\(function .*"test"/m, @response.body
+ #end
+
+end
View
6 test/hjstemplate_test.rb
@@ -72,6 +72,12 @@ def with_template_root(root, sep=nil)
assert_match /Ember\.TEMPLATES\["test"\] = Ember\.Handlebars\.template\(function .*"test"/m, @response.body
end
+ #test "asset pipeline should serve raw handlebars templates" do
+ #get "/assets/templates/vanilla.js"
+ #assert_response :success
+ #assert_match /Ember\.TEMPLATES\["vanilla"\] = Handlebars\.template\(function .*"test"/m, @response.body
+ #end
+
test "should unbind mustache templates" do
get "/assets/templates/hairy.mustache"
assert_response :success
Please sign in to comment.
Something went wrong with that request. Please try again.