-
-
Save ppcano/2045348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment