Fix up the compilation process
This commit is contained in:
+37
-29
@@ -1,12 +1,20 @@
|
||||
if(exports) {
|
||||
var inspect = function(obj) {
|
||||
require("sys").print(require("sys").inspect(obj) + "\n");
|
||||
};
|
||||
var Handlebars = {};
|
||||
Handlebars.AST = require("handlebars/ast");
|
||||
Handlebars.Visitor = require("handlebars/jison_ext").Visitor;
|
||||
}
|
||||
var inspect = function(obj) {
|
||||
require("sys").print(require("sys").inspect(obj) + "\n");
|
||||
};
|
||||
|
||||
var Handlebars = {};
|
||||
|
||||
Handlebars.AST = require("handlebars/ast").AST;
|
||||
Handlebars.HandlebarsLexer = require("handlebars/handlebars_lexer").Lexer;
|
||||
Handlebars.Visitor = require("handlebars/jison_ext").Visitor;
|
||||
Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor;
|
||||
Handlebars.Parser = require("handlebars/parser").parser;
|
||||
Handlebars.Runtime = require("handlebars/runtime").Runtime;
|
||||
Handlebars.Utils = require("handlebars/utils").Utils;
|
||||
Handlebars.SafeString = require("handlebars/utils").SafeString;
|
||||
Handlebars.Exception = require("handlebars/utils").Exception;
|
||||
|
||||
// BEGIN(BROWSER)
|
||||
// A Context wraps data, and makes it possible to extract a
|
||||
// new Context given a path. For instance, if the data
|
||||
// is { person: { name: "Alan" } }, a Context wrapping
|
||||
@@ -21,10 +29,7 @@ Handlebars.Context.prototype = {
|
||||
|
||||
// Make a shallow copy of the Context
|
||||
clone: function() {
|
||||
var context = new Handlebars.Context();
|
||||
context.data = this.data;
|
||||
context.fallback = this.fallback;
|
||||
return context;
|
||||
return new Handlebars.Context(this.data, this.fallback);
|
||||
},
|
||||
|
||||
// Search for an object inside the Context's data. The
|
||||
@@ -94,19 +99,21 @@ Handlebars.Runtime.prototype = {
|
||||
var statements = program.statements;
|
||||
|
||||
for(var i=0, l=statements.length; i<l; i++) {
|
||||
this.accept(statements[i]);
|
||||
var statement = statements[i];
|
||||
this[statement.type](statement);
|
||||
}
|
||||
|
||||
return this.buffer;
|
||||
},
|
||||
|
||||
mustache: function(mustache) {
|
||||
var idObj = this.accept(mustache.id);
|
||||
var idObj = this.ID(mustache.id);
|
||||
var params = mustache.params;
|
||||
var buf;
|
||||
|
||||
for(var i=0, l=params.length; i<l; i++) {
|
||||
params[i] = this.accept(params[i]).data;
|
||||
var param = params[i];
|
||||
params[i] = this[param.type](param).data;
|
||||
}
|
||||
|
||||
if(toString.call(idObj.data) === "[object Function]") {
|
||||
@@ -125,12 +132,12 @@ Handlebars.Runtime.prototype = {
|
||||
var mustache = block.mustache,
|
||||
id = mustache.id;
|
||||
|
||||
var idObj = this.accept(mustache.id),
|
||||
var idObj = this.ID(mustache.id),
|
||||
data = idObj.data;
|
||||
|
||||
if(toString.call(data) !== "[object Function]") {
|
||||
params = [data];
|
||||
data = this.context.evaluate({depth: 0, parts: ["helperMissing"]}, this.stack).data;
|
||||
data = this.context.fallback.helperMissing;
|
||||
} else {
|
||||
params = this.evaluateParams(mustache.params);
|
||||
}
|
||||
@@ -148,7 +155,7 @@ Handlebars.Runtime.prototype = {
|
||||
},
|
||||
|
||||
partial: function(partial) {
|
||||
var partials = this.context.evaluate({depth: 0, parts: ["partials"]}, this.stack).data || {};
|
||||
var partials = this.context.fallback.partials || {};
|
||||
var id = partial.id.original;
|
||||
|
||||
var partialBody = partials[partial.id.original];
|
||||
@@ -165,12 +172,12 @@ Handlebars.Runtime.prototype = {
|
||||
}
|
||||
|
||||
if(partial.context) {
|
||||
var context = this.accept(partial.context);
|
||||
var context = this.ID(partial.context);
|
||||
} else {
|
||||
var context = this.context;
|
||||
}
|
||||
var runtime = new Handlebars.Runtime(context, this.context.fallback, this.stack.slice(0));
|
||||
this.buffer = this.buffer + runtime.accept(program);
|
||||
this.buffer = this.buffer + runtime.program(program);
|
||||
},
|
||||
|
||||
not: function(context, fn) {
|
||||
@@ -183,7 +190,7 @@ Handlebars.Runtime.prototype = {
|
||||
id = mustache.id,
|
||||
not;
|
||||
|
||||
var idObj = this.accept(id),
|
||||
var idObj = this.ID(id),
|
||||
data = idObj.data,
|
||||
isInverse = Handlebars.Utils.isEmpty(data);
|
||||
|
||||
@@ -213,12 +220,15 @@ Handlebars.Runtime.prototype = {
|
||||
comment: function() {},
|
||||
|
||||
evaluateParams: function(params) {
|
||||
var ret = [];
|
||||
|
||||
for(var i=0, l=params.length; i<l; i++) {
|
||||
params[i] = this.accept(params[i]).data;
|
||||
var param = params[i];
|
||||
ret[i] = this[param.type](param).data;
|
||||
}
|
||||
|
||||
if(params.length === 0) { params = [this.wrapContext()]; }
|
||||
return params;
|
||||
if(ret.length === 0) { ret = [this.wrapContext()]; }
|
||||
return ret;
|
||||
},
|
||||
|
||||
wrapContext: function() {
|
||||
@@ -246,14 +256,12 @@ Handlebars.Runtime.prototype = {
|
||||
return function(context) {
|
||||
if(context && context.isWrappedContext) { context = context.__data__; }
|
||||
var runtime = new Handlebars.Runtime(context, fallback, stack);
|
||||
runtime.accept(program);
|
||||
runtime.program(program);
|
||||
return runtime.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// END(BROWSER)
|
||||
|
||||
if(exports) {
|
||||
exports.Runtime = Handlebars.Runtime;
|
||||
}
|
||||
|
||||
exports.Runtime = Handlebars.Runtime;
|
||||
|
||||
Reference in New Issue
Block a user