Fix up the compilation process

This commit is contained in:
wycats
2010-12-04 17:35:36 -05:00
parent f205cec745
commit 4db1abcd74
10 changed files with 190 additions and 118 deletions
+44 -18
View File
@@ -1,14 +1,37 @@
require.paths.push(__dirname + "/lib");
if(exports) {
require.paths.push("lib");
var Handlebars = require("handlebars").Handlebars;
var Handlebars = require("handlebars").Handlebars;
if(require("sys")) {
var print = function(val) {
require("sys").print(val + "\n")
}
}
}
var string = "foo {{ bar ../baz/bat/bam \"baz\" }}baz{{! foo bar baz }}{{#foo}} bar {{^}} baz {{/foo}}{{> partial }}{{# bar }}part1 {{^}} part2{{> foo }}{{/bar}}zomg"
var string = "foo {{#list people}}{{name}}{{/list}}{{#bool}}true: {{name}}{{/bool}}{{#nobool}}false: {{name}}{{/bool}}";
var string = "foo {{#list people}}{{name}}{{/list}}{{#bool}}true: {{name}}{{/bool}}{{#nobool}}false: {{name}}{{/nobool}}";
var ast = Handlebars.parse(string);
//require("sys").print(Handlebars.print(ast));
//
var runtime = new Handlebars.Runtime({people: [{name: "Yehuda"}, {name: "Leah"}], bool: true, nobool: false, name: "Yehuda Katz"},
var helperMissing = function(context, fn) {
var ret = "";
if(context === true) {
return fn(this);
} else if(context === false) {
return "";
} else if(Object.prototype.toString.call(context) === "[object Array]") {
for(var i=0, j=context.length; i<j; i++) {
ret = ret + fn(context[i]);
}
return ret;
} else {
return fn(context);
}
};
var context = {people: [{name: "Yehuda"}, {name: "Leah"}], bool: true, nobool: false, name: "Yehuda Katz"};
var fallback =
{
list: function(ctx, fn) {
var out = "<ul>";
@@ -17,14 +40,17 @@ var runtime = new Handlebars.Runtime({people: [{name: "Yehuda"}, {name: "Leah"}]
}
return out + "</ul>";
},
helperMissing: function(context, fn) {
if(context === true) {
return fn(this);
} else if(context === false) {
return "";
}
}
}
)
runtime.accept(ast)
require("sys").print(runtime.buffer)
helperMissing: helperMissing
};
var compiled = Handlebars.compile(string);
var result;
var time = new Date;
for(var i=0; i<10000; i++) {
result = compiled(context, fallback);
}
print(new Date - time)
print(result)