Create a gist now

Instantly share code, notes, and snippets.

Embed
Ember Handlebars Precompile
require 'execjs'
class HandlebarsFilter < Filter
class << self
def contents
@@contents ||= [File.read("headless-ember.js"), File.read("ember.js")].join("\n")
end
def context
@@context ||= ExecJS.compile(contents)
end
end
def generate_output(inputs, output)
inputs.each do |input|
name = File.basename(input.path, '.handlebars')
compiled = self.class.context.call("precompileEmberHandlebars", input.read)
output.write "\nEmber.TEMPLATES['#{name}'] = Ember.Handlebars.template(#{compiled});\n"
end
end
end
input "templates"
output "output"
match "*.handlebars" do
filter HandlebarsFilter
concat "templates.js"
end
// 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;
// Console
var console = window.console = {};
console.log = console.info = console.warn = console.error = function(){};
// jQuery
var jQuery = function() { return jQuery; };
jQuery.ready = function() { return jQuery; };
jQuery.inArray = function() { return jQuery; };
jQuery.jquery = "1.7.1";
var $ = jQuery;
// Ember
function precompileEmberHandlebars(string) {
return Ember.Handlebars.precompile(string).toString();
}
@wagenet

This comment has been minimized.

Show comment
Hide comment
@wagenet

wagenet Jan 13, 2012

By the way, this requires Ember master as of 1/13.

Owner

wagenet commented Jan 13, 2012

By the way, this requires Ember master as of 1/13.

@wagenet

This comment has been minimized.

Show comment
Hide comment
@wagenet

wagenet Jan 13, 2012

Oh, and a special thanks to @tchak for helping me figure this out!

Owner

wagenet commented Jan 13, 2012

Oh, and a special thanks to @tchak for helping me figure this out!

@garth

This comment has been minimized.

Show comment
Hide comment
@garth

garth Jan 13, 2012

I'm guessing that we should be able to replace Assetfile.rb with some equivalent js and run this through nodejs?

garth commented Jan 13, 2012

I'm guessing that we should be able to replace Assetfile.rb with some equivalent js and run this through nodejs?

@wagenet

This comment has been minimized.

Show comment
Hide comment
@wagenet

wagenet Jan 14, 2012

@garth, in theory yes. The main thing is that you have to have a full Ember running to get proper compilation. Unforunately, right now that requires stubbing some things out like in my headless-ember.js.

Owner

wagenet commented Jan 14, 2012

@garth, in theory yes. The main thing is that you have to have a full Ember running to get proper compilation. Unforunately, right now that requires stubbing some things out like in my headless-ember.js.

@manoharank

This comment has been minimized.

Show comment
Hide comment
@manoharank

manoharank Feb 9, 2013

@wagenet I am getting error when compiling ember 1.0.0-pre.4 in this line https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/system/utils.js#L24. Any workaround?

@wagenet I am getting error when compiling ember 1.0.0-pre.4 in this line https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/system/utils.js#L24. Any workaround?

@ppcano

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment