Skip to content
Browse files

use barber

  • Loading branch information...
1 parent c2a7d69 commit a634dac8da70ee9a6c6b805c39811b19946db123 @tchak tchak committed Nov 1, 2012
View
1 ember-rails.gemspec
@@ -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"]
View
28 lib/ember/handlebars/assets/ember-precompiler.js
@@ -1,28 +0,0 @@
-// DOM
-var Element = {};
-Element.firstChild = function () { return Element; };
-Element.innerHTML = function () { return Element; };
-
-var document = { createRange: false, createElement: function() { return Element; } };
-var window = this;
-this.document = document;
-
-// null out console.log and console.warn to avoid unexpected output
-if (window.console) {
- window.console.warn = function() {};
- window.console.log = function() {};
-}
-
-//// jQuery
-var jQuery = window.jQuery = function() { return jQuery; };
-jQuery.ready = function() { return jQuery; };
-jQuery.inArray = function() { return jQuery; };
-jQuery.jquery = "1.7.2";
-jQuery.event = {fixHooks: {}};
-
-// Precompiler
-var EmberRails = {
- precompile: function(string) {
- return Ember.Handlebars.precompile(string).toString();
- }
-};
View
54 lib/ember/handlebars/source.rb
@@ -1,54 +0,0 @@
-require 'execjs'
-
-module Ember
- module Handlebars
- class Source
- class << self
- def precompiler_path
- File.expand_path(File.join(__FILE__, '../assets/ember-precompiler.js'))
- end
-
- def vendor_path
- path = ::Rails.root.nil? ? '' : ::Rails.root.join('vendor/assets/javascripts/ember.js')
-
- if !File.exists?(path)
- path = File.expand_path(File.join(__FILE__, '../../../../vendor/ember/production/ember.js'))
- end
- end
-
- def path
- @path ||= ENV['EMBER_SOURCE_PATH'] || vendor_path
- end
-
- def contents
- @contents ||= begin
- config = ::Rails.application.config.ember
- handlebars = File.read(config.handlebars_location)
- ember = File.read(config.ember_location)
- precompiler = File.read(precompiler_path)
-
- [precompiler, handlebars, ember].join("\n")
- end
- end
-
- def handlebars_version
- @handlebars_version ||= contents[/^Handlebars.VERSION = "([^"]*)"/, 1]
- end
-
- def ember_version
- @ember_version ||= contents[/^Ember.VERSION = '([^']*)'/, 1]
- end
-
- def context
- @context ||= ExecJS.compile(contents)
- end
- end
- end
-
- class << self
- def compile(template)
- Source.context.call('EmberRails.precompile', template)
- end
- end
- end
-end
View
6 lib/ember/handlebars/template.rb
@@ -1,6 +1,6 @@
require 'sprockets'
require 'sprockets/engines'
-require 'ember/handlebars/source'
+require 'barber'
module Ember
module Handlebars
@@ -18,8 +18,8 @@ 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"
+ template = Barber::Ember::FilePrecompiler.call(template)
+ "Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = #{template}\n"
else
"Ember.TEMPLATES[#{template_path(scope.logical_path).inspect}] = Ember.Handlebars.compile(#{indent(template).inspect});\n"
end

0 comments on commit a634dac

Please sign in to comment.
Something went wrong with that request. Please try again.