Factory update with tabs to spaces.. sorry :(
This commit is contained in:
+9
-9
@@ -2,18 +2,18 @@ var handlebars = require("./handlebars/base"),
|
|||||||
|
|
||||||
// Each of these augment the Handlebars object. No need to setup here.
|
// Each of these augment the Handlebars object. No need to setup here.
|
||||||
// (This is done to easily share code between commonjs and browse envs)
|
// (This is done to easily share code between commonjs and browse envs)
|
||||||
utils = require("./handlebars/utils"),
|
utils = require("./handlebars/utils"),
|
||||||
compiler = require("./handlebars/compiler"),
|
compiler = require("./handlebars/compiler"),
|
||||||
runtime = require("./handlebars/runtime");
|
runtime = require("./handlebars/runtime");
|
||||||
|
|
||||||
var create = function() {
|
var create = function() {
|
||||||
var hb = handlebars.create();
|
var hb = handlebars.create();
|
||||||
|
|
||||||
utils.attach(hb);
|
utils.attach(hb);
|
||||||
compiler.attach(hb);
|
compiler.attach(hb);
|
||||||
runtime.attach(hb);
|
runtime.attach(hb);
|
||||||
|
|
||||||
return hb;
|
return hb;
|
||||||
};
|
};
|
||||||
|
|
||||||
var Handlebars = create();
|
var Handlebars = create();
|
||||||
@@ -29,4 +29,4 @@ module.exports = Handlebars; // instantiate an instance
|
|||||||
// var handlebars = require('handlebars');
|
// var handlebars = require('handlebars');
|
||||||
|
|
||||||
// var singleton = handlebars.Handlebars,
|
// var singleton = handlebars.Handlebars,
|
||||||
// local = handlebars.create();
|
// local = handlebars.create();
|
||||||
|
|||||||
+85
-85
@@ -1,116 +1,116 @@
|
|||||||
module.exports.create = function() {
|
module.exports.create = function() {
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
var Handlebars = {};
|
var Handlebars = {};
|
||||||
|
|
||||||
Handlebars.VERSION = "1.0.rc.1";
|
Handlebars.VERSION = "1.0.rc.1";
|
||||||
|
|
||||||
Handlebars.helpers = {};
|
Handlebars.helpers = {};
|
||||||
Handlebars.partials = {};
|
Handlebars.partials = {};
|
||||||
|
|
||||||
Handlebars.registerHelper = function(name, fn, inverse) {
|
Handlebars.registerHelper = function(name, fn, inverse) {
|
||||||
if(inverse) { fn.not = inverse; }
|
if(inverse) { fn.not = inverse; }
|
||||||
this.helpers[name] = fn;
|
this.helpers[name] = fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.registerPartial = function(name, str) {
|
Handlebars.registerPartial = function(name, str) {
|
||||||
this.partials[name] = str;
|
this.partials[name] = str;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.registerHelper('helperMissing', function(arg) {
|
Handlebars.registerHelper('helperMissing', function(arg) {
|
||||||
if(arguments.length === 2) {
|
if(arguments.length === 2) {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Could not find property '" + arg + "'");
|
throw new Error("Could not find property '" + arg + "'");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var toString = Object.prototype.toString, functionType = "[object Function]";
|
var toString = Object.prototype.toString, functionType = "[object Function]";
|
||||||
|
|
||||||
Handlebars.registerHelper('blockHelperMissing', function(context, options) {
|
Handlebars.registerHelper('blockHelperMissing', function(context, options) {
|
||||||
var inverse = options.inverse || function() {}, fn = options.fn;
|
var inverse = options.inverse || function() {}, fn = options.fn;
|
||||||
|
|
||||||
|
|
||||||
var ret = "";
|
var ret = "";
|
||||||
var type = toString.call(context);
|
var type = toString.call(context);
|
||||||
|
|
||||||
if(type === functionType) { context = context.call(this); }
|
if(type === functionType) { context = context.call(this); }
|
||||||
|
|
||||||
if(context === true) {
|
if(context === true) {
|
||||||
return fn(this);
|
return fn(this);
|
||||||
} else if(context === false || context == null) {
|
} else if(context === false || context == null) {
|
||||||
return inverse(this);
|
return inverse(this);
|
||||||
} else if(type === "[object Array]") {
|
} else if(type === "[object Array]") {
|
||||||
if(context.length > 0) {
|
if(context.length > 0) {
|
||||||
for(var i=0, j=context.length; i<j; i++) {
|
|
||||||
ret = ret + fn(context[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = inverse(this);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
} else {
|
|
||||||
return fn(context);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Handlebars.K = function() {};
|
|
||||||
|
|
||||||
Handlebars.createFrame = Object.create || function(object) {
|
|
||||||
Handlebars.K.prototype = object;
|
|
||||||
var obj = new Handlebars.K();
|
|
||||||
Handlebars.K.prototype = null;
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.registerHelper('each', function(context, options) {
|
|
||||||
var fn = options.fn, inverse = options.inverse;
|
|
||||||
var ret = "", data;
|
|
||||||
|
|
||||||
if (options.data) {
|
|
||||||
data = Handlebars.createFrame(options.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(context && context.length > 0) {
|
|
||||||
for(var i=0, j=context.length; i<j; i++) {
|
for(var i=0, j=context.length; i<j; i++) {
|
||||||
if (data) { data.index = i; }
|
ret = ret + fn(context[i]);
|
||||||
ret = ret + fn(context[i], { data: data });
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = inverse(this);
|
ret = inverse(this);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
} else {
|
||||||
|
return fn(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('if', function(context, options) {
|
Handlebars.K = function() {};
|
||||||
var type = toString.call(context);
|
|
||||||
if(type === functionType) { context = context.call(this); }
|
|
||||||
|
|
||||||
if(!context || Handlebars.Utils.isEmpty(context)) {
|
Handlebars.createFrame = Object.create || function(object) {
|
||||||
return options.inverse(this);
|
Handlebars.K.prototype = object;
|
||||||
} else {
|
var obj = new Handlebars.K();
|
||||||
return options.fn(this);
|
Handlebars.K.prototype = null;
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
Handlebars.registerHelper('each', function(context, options) {
|
||||||
|
var fn = options.fn, inverse = options.inverse;
|
||||||
|
var ret = "", data;
|
||||||
|
|
||||||
|
if (options.data) {
|
||||||
|
data = Handlebars.createFrame(options.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(context && context.length > 0) {
|
||||||
|
for(var i=0, j=context.length; i<j; i++) {
|
||||||
|
if (data) { data.index = i; }
|
||||||
|
ret = ret + fn(context[i], { data: data });
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
ret = inverse(this);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('unless', function(context, options) {
|
Handlebars.registerHelper('if', function(context, options) {
|
||||||
var fn = options.fn, inverse = options.inverse;
|
var type = toString.call(context);
|
||||||
options.fn = inverse;
|
if(type === functionType) { context = context.call(this); }
|
||||||
options.inverse = fn;
|
|
||||||
|
|
||||||
return Handlebars.helpers['if'].call(this, context, options);
|
if(!context || Handlebars.Utils.isEmpty(context)) {
|
||||||
});
|
return options.inverse(this);
|
||||||
|
} else {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('with', function(context, options) {
|
Handlebars.registerHelper('unless', function(context, options) {
|
||||||
return options.fn(context);
|
var fn = options.fn, inverse = options.inverse;
|
||||||
});
|
options.fn = inverse;
|
||||||
|
options.inverse = fn;
|
||||||
|
|
||||||
Handlebars.registerHelper('log', function(context) {
|
return Handlebars.helpers['if'].call(this, context, options);
|
||||||
Handlebars.log(context);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// END(BROWSER)
|
Handlebars.registerHelper('with', function(context, options) {
|
||||||
|
return options.fn(context);
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper('log', function(context) {
|
||||||
|
Handlebars.log(context);
|
||||||
|
});
|
||||||
|
|
||||||
|
// END(BROWSER)
|
||||||
|
|
||||||
return Handlebars;
|
return Handlebars;
|
||||||
|
|
||||||
|
|||||||
@@ -1,124 +1,126 @@
|
|||||||
|
|
||||||
// BEGIN(BROWSER)
|
|
||||||
exports.attach = function(Handlebars) {
|
exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
Handlebars.AST = {};
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
Handlebars.AST.ProgramNode = function(statements, inverse) {
|
Handlebars.AST = {};
|
||||||
this.type = "program";
|
|
||||||
this.statements = statements;
|
|
||||||
if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
|
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
|
Handlebars.AST.ProgramNode = function(statements, inverse) {
|
||||||
this.type = "mustache";
|
this.type = "program";
|
||||||
this.escaped = !unescaped;
|
this.statements = statements;
|
||||||
this.hash = hash;
|
if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
|
||||||
|
};
|
||||||
|
|
||||||
var id = this.id = rawParams[0];
|
Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
|
||||||
var params = this.params = rawParams.slice(1);
|
this.type = "mustache";
|
||||||
|
this.escaped = !unescaped;
|
||||||
|
this.hash = hash;
|
||||||
|
|
||||||
// a mustache is an eligible helper if:
|
var id = this.id = rawParams[0];
|
||||||
// * its id is simple (a single part, not `this` or `..`)
|
var params = this.params = rawParams.slice(1);
|
||||||
var eligibleHelper = this.eligibleHelper = id.isSimple;
|
|
||||||
|
|
||||||
// a mustache is definitely a helper if:
|
// a mustache is an eligible helper if:
|
||||||
// * it is an eligible helper, and
|
// * its id is simple (a single part, not `this` or `..`)
|
||||||
// * it has at least one parameter or hash segment
|
var eligibleHelper = this.eligibleHelper = id.isSimple;
|
||||||
this.isHelper = eligibleHelper && (params.length || hash);
|
|
||||||
|
|
||||||
// if a mustache is an eligible helper but not a definite
|
// a mustache is definitely a helper if:
|
||||||
// helper, it is ambiguous, and will be resolved in a later
|
// * it is an eligible helper, and
|
||||||
// pass or at runtime.
|
// * it has at least one parameter or hash segment
|
||||||
};
|
this.isHelper = eligibleHelper && (params.length || hash);
|
||||||
|
|
||||||
Handlebars.AST.PartialNode = function(id, context) {
|
// if a mustache is an eligible helper but not a definite
|
||||||
this.type = "partial";
|
// helper, it is ambiguous, and will be resolved in a later
|
||||||
|
// pass or at runtime.
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: disallow complex IDs
|
Handlebars.AST.PartialNode = function(id, context) {
|
||||||
|
this.type = "partial";
|
||||||
|
|
||||||
this.id = id;
|
// TODO: disallow complex IDs
|
||||||
this.context = context;
|
|
||||||
};
|
|
||||||
|
|
||||||
var verifyMatch = function(open, close) {
|
this.id = id;
|
||||||
if(open.original !== close.original) {
|
this.context = context;
|
||||||
throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
|
var verifyMatch = function(open, close) {
|
||||||
verifyMatch(mustache.id, close);
|
if(open.original !== close.original) {
|
||||||
this.type = "block";
|
throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
|
||||||
this.mustache = mustache;
|
}
|
||||||
this.program = program;
|
};
|
||||||
this.inverse = inverse;
|
|
||||||
|
|
||||||
if (this.inverse && !this.program) {
|
Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
|
||||||
this.isInverse = true;
|
verifyMatch(mustache.id, close);
|
||||||
}
|
this.type = "block";
|
||||||
};
|
this.mustache = mustache;
|
||||||
|
this.program = program;
|
||||||
|
this.inverse = inverse;
|
||||||
|
|
||||||
Handlebars.AST.ContentNode = function(string) {
|
if (this.inverse && !this.program) {
|
||||||
this.type = "content";
|
this.isInverse = true;
|
||||||
this.string = string;
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.HashNode = function(pairs) {
|
Handlebars.AST.ContentNode = function(string) {
|
||||||
this.type = "hash";
|
this.type = "content";
|
||||||
this.pairs = pairs;
|
this.string = string;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.IdNode = function(parts) {
|
Handlebars.AST.HashNode = function(pairs) {
|
||||||
this.type = "ID";
|
this.type = "hash";
|
||||||
this.original = parts.join(".");
|
this.pairs = pairs;
|
||||||
|
};
|
||||||
|
|
||||||
var dig = [], depth = 0;
|
Handlebars.AST.IdNode = function(parts) {
|
||||||
|
this.type = "ID";
|
||||||
|
this.original = parts.join(".");
|
||||||
|
|
||||||
for(var i=0,l=parts.length; i<l; i++) {
|
var dig = [], depth = 0;
|
||||||
var part = parts[i];
|
|
||||||
|
|
||||||
if(part === "..") { depth++; }
|
for(var i=0,l=parts.length; i<l; i++) {
|
||||||
else if(part === "." || part === "this") { this.isScoped = true; }
|
var part = parts[i];
|
||||||
else { dig.push(part); }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.parts = dig;
|
if(part === "..") { depth++; }
|
||||||
this.string = dig.join('.');
|
else if(part === "." || part === "this") { this.isScoped = true; }
|
||||||
this.depth = depth;
|
else { dig.push(part); }
|
||||||
|
}
|
||||||
|
|
||||||
// an ID is simple if it only has one part, and that part is not
|
this.parts = dig;
|
||||||
// `..` or `this`.
|
this.string = dig.join('.');
|
||||||
this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
|
this.depth = depth;
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.AST.DataNode = function(id) {
|
// an ID is simple if it only has one part, and that part is not
|
||||||
this.type = "DATA";
|
// `..` or `this`.
|
||||||
this.id = id;
|
this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.StringNode = function(string) {
|
Handlebars.AST.DataNode = function(id) {
|
||||||
this.type = "STRING";
|
this.type = "DATA";
|
||||||
this.string = string;
|
this.id = id;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.IntegerNode = function(integer) {
|
Handlebars.AST.StringNode = function(string) {
|
||||||
this.type = "INTEGER";
|
this.type = "STRING";
|
||||||
this.integer = integer;
|
this.string = string;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.BooleanNode = function(bool) {
|
Handlebars.AST.IntegerNode = function(integer) {
|
||||||
this.type = "BOOLEAN";
|
this.type = "INTEGER";
|
||||||
this.bool = bool;
|
this.integer = integer;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.AST.CommentNode = function(comment) {
|
Handlebars.AST.BooleanNode = function(bool) {
|
||||||
this.type = "comment";
|
this.type = "BOOLEAN";
|
||||||
this.comment = comment;
|
this.bool = bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
return Handlebars;
|
Handlebars.AST.CommentNode = function(comment) {
|
||||||
|
this.type = "comment";
|
||||||
|
this.comment = comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
// END(BROWSER)
|
// END(BROWSER)
|
||||||
|
|
||||||
|
return Handlebars;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
var handlebars = require("./parser").parser;
|
var handlebars = require("./parser").parser;
|
||||||
|
|
||||||
exports.attach = function(Handlebars) {
|
exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
|
||||||
|
|
||||||
Handlebars.Parser = handlebars;
|
|
||||||
|
|
||||||
Handlebars.parse = function(string) {
|
// BEGIN(BROWSER)
|
||||||
Handlebars.Parser.yy = Handlebars.AST;
|
|
||||||
return Handlebars.Parser.parse(string);
|
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.print = function(ast) {
|
Handlebars.Parser = handlebars;
|
||||||
return new Handlebars.PrintVisitor().accept(ast);
|
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.logger = {
|
Handlebars.parse = function(string) {
|
||||||
DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
|
Handlebars.Parser.yy = Handlebars.AST;
|
||||||
|
return Handlebars.Parser.parse(string);
|
||||||
// override in the host environment
|
};
|
||||||
log: function(level, str) {}
|
|
||||||
};
|
Handlebars.print = function(ast) {
|
||||||
|
return new Handlebars.PrintVisitor().accept(ast);
|
||||||
Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
|
};
|
||||||
|
|
||||||
return Handlebars;
|
Handlebars.logger = {
|
||||||
|
DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
|
||||||
// END(BROWSER)
|
|
||||||
|
// override in the host environment
|
||||||
|
log: function(level, str) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
|
||||||
|
|
||||||
|
return Handlebars;
|
||||||
|
|
||||||
|
// END(BROWSER)
|
||||||
};
|
};
|
||||||
|
|||||||
+1001
-1001
File diff suppressed because it is too large
Load Diff
@@ -2,9 +2,9 @@
|
|||||||
module.exports.attach = function(Handlebars) {
|
module.exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
var visitor = require("./visitor"),
|
var visitor = require("./visitor"),
|
||||||
printer = require("./printer"),
|
printer = require("./printer"),
|
||||||
ast = require("./ast"),
|
ast = require("./ast"),
|
||||||
compiler = require("./compiler");
|
compiler = require("./compiler");
|
||||||
|
|
||||||
visitor.attach(Handlebars);
|
visitor.attach(Handlebars);
|
||||||
printer.attach(Handlebars);
|
printer.attach(Handlebars);
|
||||||
|
|||||||
+121
-121
@@ -1,130 +1,130 @@
|
|||||||
exports.attach = function(Handlebars) {
|
exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
Handlebars.PrintVisitor = function() { this.padding = 0; };
|
|
||||||
Handlebars.PrintVisitor.prototype = new Handlebars.Visitor();
|
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
|
Handlebars.PrintVisitor = function() { this.padding = 0; };
|
||||||
var out = "";
|
Handlebars.PrintVisitor.prototype = new Handlebars.Visitor();
|
||||||
|
|
||||||
for(var i=0,l=this.padding; i<l; i++) {
|
Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
|
||||||
out = out + " ";
|
var out = "";
|
||||||
}
|
|
||||||
|
|
||||||
out = out + string;
|
for(var i=0,l=this.padding; i<l; i++) {
|
||||||
|
out = out + " ";
|
||||||
|
}
|
||||||
|
|
||||||
if(newline !== false) { out = out + "\n"; }
|
out = out + string;
|
||||||
return out;
|
|
||||||
};
|
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.program = function(program) {
|
if(newline !== false) { out = out + "\n"; }
|
||||||
var out = "",
|
return out;
|
||||||
statements = program.statements,
|
};
|
||||||
inverse = program.inverse,
|
|
||||||
i, l;
|
Handlebars.PrintVisitor.prototype.program = function(program) {
|
||||||
|
var out = "",
|
||||||
for(i=0, l=statements.length; i<l; i++) {
|
statements = program.statements,
|
||||||
out = out + this.accept(statements[i]);
|
inverse = program.inverse,
|
||||||
}
|
i, l;
|
||||||
|
|
||||||
this.padding--;
|
for(i=0, l=statements.length; i<l; i++) {
|
||||||
|
out = out + this.accept(statements[i]);
|
||||||
return out;
|
}
|
||||||
};
|
|
||||||
|
this.padding--;
|
||||||
Handlebars.PrintVisitor.prototype.block = function(block) {
|
|
||||||
var out = "";
|
return out;
|
||||||
|
};
|
||||||
out = out + this.pad("BLOCK:");
|
|
||||||
this.padding++;
|
Handlebars.PrintVisitor.prototype.block = function(block) {
|
||||||
out = out + this.accept(block.mustache);
|
var out = "";
|
||||||
if (block.program) {
|
|
||||||
out = out + this.pad("PROGRAM:");
|
out = out + this.pad("BLOCK:");
|
||||||
this.padding++;
|
this.padding++;
|
||||||
out = out + this.accept(block.program);
|
out = out + this.accept(block.mustache);
|
||||||
this.padding--;
|
if (block.program) {
|
||||||
}
|
out = out + this.pad("PROGRAM:");
|
||||||
if (block.inverse) {
|
this.padding++;
|
||||||
if (block.program) { this.padding++; }
|
out = out + this.accept(block.program);
|
||||||
out = out + this.pad("{{^}}");
|
this.padding--;
|
||||||
this.padding++;
|
}
|
||||||
out = out + this.accept(block.inverse);
|
if (block.inverse) {
|
||||||
this.padding--;
|
if (block.program) { this.padding++; }
|
||||||
if (block.program) { this.padding--; }
|
out = out + this.pad("{{^}}");
|
||||||
}
|
this.padding++;
|
||||||
this.padding--;
|
out = out + this.accept(block.inverse);
|
||||||
|
this.padding--;
|
||||||
return out;
|
if (block.program) { this.padding--; }
|
||||||
};
|
}
|
||||||
|
this.padding--;
|
||||||
Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
|
|
||||||
var params = mustache.params, paramStrings = [], hash;
|
return out;
|
||||||
|
};
|
||||||
for(var i=0, l=params.length; i<l; i++) {
|
|
||||||
paramStrings.push(this.accept(params[i]));
|
Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
|
||||||
}
|
var params = mustache.params, paramStrings = [], hash;
|
||||||
|
|
||||||
params = "[" + paramStrings.join(", ") + "]";
|
for(var i=0, l=params.length; i<l; i++) {
|
||||||
|
paramStrings.push(this.accept(params[i]));
|
||||||
hash = mustache.hash ? " " + this.accept(mustache.hash) : "";
|
}
|
||||||
|
|
||||||
return this.pad("{{ " + this.accept(mustache.id) + " " + params + hash + " }}");
|
params = "[" + paramStrings.join(", ") + "]";
|
||||||
};
|
|
||||||
|
hash = mustache.hash ? " " + this.accept(mustache.hash) : "";
|
||||||
Handlebars.PrintVisitor.prototype.partial = function(partial) {
|
|
||||||
var content = this.accept(partial.id);
|
return this.pad("{{ " + this.accept(mustache.id) + " " + params + hash + " }}");
|
||||||
if(partial.context) { content = content + " " + this.accept(partial.context); }
|
};
|
||||||
return this.pad("{{> " + content + " }}");
|
|
||||||
};
|
Handlebars.PrintVisitor.prototype.partial = function(partial) {
|
||||||
|
var content = this.accept(partial.id);
|
||||||
Handlebars.PrintVisitor.prototype.hash = function(hash) {
|
if(partial.context) { content = content + " " + this.accept(partial.context); }
|
||||||
var pairs = hash.pairs;
|
return this.pad("{{> " + content + " }}");
|
||||||
var joinedPairs = [], left, right;
|
};
|
||||||
|
|
||||||
for(var i=0, l=pairs.length; i<l; i++) {
|
Handlebars.PrintVisitor.prototype.hash = function(hash) {
|
||||||
left = pairs[i][0];
|
var pairs = hash.pairs;
|
||||||
right = this.accept(pairs[i][1]);
|
var joinedPairs = [], left, right;
|
||||||
joinedPairs.push( left + "=" + right );
|
|
||||||
}
|
for(var i=0, l=pairs.length; i<l; i++) {
|
||||||
|
left = pairs[i][0];
|
||||||
return "HASH{" + joinedPairs.join(", ") + "}";
|
right = this.accept(pairs[i][1]);
|
||||||
};
|
joinedPairs.push( left + "=" + right );
|
||||||
|
}
|
||||||
Handlebars.PrintVisitor.prototype.STRING = function(string) {
|
|
||||||
return '"' + string.string + '"';
|
return "HASH{" + joinedPairs.join(", ") + "}";
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.INTEGER = function(integer) {
|
Handlebars.PrintVisitor.prototype.STRING = function(string) {
|
||||||
return "INTEGER{" + integer.integer + "}";
|
return '"' + string.string + '"';
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.BOOLEAN = function(bool) {
|
Handlebars.PrintVisitor.prototype.INTEGER = function(integer) {
|
||||||
return "BOOLEAN{" + bool.bool + "}";
|
return "INTEGER{" + integer.integer + "}";
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.ID = function(id) {
|
Handlebars.PrintVisitor.prototype.BOOLEAN = function(bool) {
|
||||||
var path = id.parts.join("/");
|
return "BOOLEAN{" + bool.bool + "}";
|
||||||
if(id.parts.length > 1) {
|
};
|
||||||
return "PATH:" + path;
|
|
||||||
} else {
|
Handlebars.PrintVisitor.prototype.ID = function(id) {
|
||||||
return "ID:" + path;
|
var path = id.parts.join("/");
|
||||||
}
|
if(id.parts.length > 1) {
|
||||||
};
|
return "PATH:" + path;
|
||||||
|
} else {
|
||||||
Handlebars.PrintVisitor.prototype.DATA = function(data) {
|
return "ID:" + path;
|
||||||
return "@" + data.id;
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.content = function(content) {
|
Handlebars.PrintVisitor.prototype.DATA = function(data) {
|
||||||
return this.pad("CONTENT[ '" + content.string + "' ]");
|
return "@" + data.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.PrintVisitor.prototype.comment = function(comment) {
|
Handlebars.PrintVisitor.prototype.content = function(content) {
|
||||||
return this.pad("{{! '" + comment.comment + "' }}");
|
return this.pad("CONTENT[ '" + content.string + "' ]");
|
||||||
};
|
};
|
||||||
// END(BROWSER)
|
|
||||||
|
Handlebars.PrintVisitor.prototype.comment = function(comment) {
|
||||||
return Handlebars;
|
return this.pad("{{! '" + comment.comment + "' }}");
|
||||||
|
};
|
||||||
|
// END(BROWSER)
|
||||||
|
|
||||||
|
return Handlebars;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
|
|
||||||
exports.attach = function(Handlebars) {
|
exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
Handlebars.Visitor = function() {};
|
Handlebars.Visitor = function() {};
|
||||||
|
|
||||||
Handlebars.Visitor.prototype = {
|
Handlebars.Visitor.prototype = {
|
||||||
accept: function(object) {
|
accept: function(object) {
|
||||||
return this[object.type](object);
|
return this[object.type](object);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// END(BROWSER)
|
// END(BROWSER)
|
||||||
|
|
||||||
return Handlebars;
|
|
||||||
|
|
||||||
|
return Handlebars;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+58
-58
@@ -1,72 +1,72 @@
|
|||||||
exports.attach = function(Handlebars) {
|
exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
Handlebars.VM = {
|
|
||||||
template: function(templateSpec) {
|
|
||||||
// Just add water
|
|
||||||
var container = {
|
|
||||||
escapeExpression: Handlebars.Utils.escapeExpression,
|
|
||||||
invokePartial: Handlebars.VM.invokePartial,
|
|
||||||
programs: [],
|
|
||||||
program: function(i, fn, data) {
|
|
||||||
var programWrapper = this.programs[i];
|
|
||||||
if(data) {
|
|
||||||
return Handlebars.VM.program(fn, data);
|
|
||||||
} else if(programWrapper) {
|
|
||||||
return programWrapper;
|
|
||||||
} else {
|
|
||||||
programWrapper = this.programs[i] = Handlebars.VM.program(fn);
|
|
||||||
return programWrapper;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
programWithDepth: Handlebars.VM.programWithDepth,
|
|
||||||
noop: Handlebars.VM.noop
|
|
||||||
};
|
|
||||||
|
|
||||||
return function(context, options) {
|
Handlebars.VM = {
|
||||||
options = options || {};
|
template: function(templateSpec) {
|
||||||
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
|
// Just add water
|
||||||
};
|
var container = {
|
||||||
},
|
escapeExpression: Handlebars.Utils.escapeExpression,
|
||||||
|
invokePartial: Handlebars.VM.invokePartial,
|
||||||
|
programs: [],
|
||||||
|
program: function(i, fn, data) {
|
||||||
|
var programWrapper = this.programs[i];
|
||||||
|
if(data) {
|
||||||
|
return Handlebars.VM.program(fn, data);
|
||||||
|
} else if(programWrapper) {
|
||||||
|
return programWrapper;
|
||||||
|
} else {
|
||||||
|
programWrapper = this.programs[i] = Handlebars.VM.program(fn);
|
||||||
|
return programWrapper;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
programWithDepth: Handlebars.VM.programWithDepth,
|
||||||
|
noop: Handlebars.VM.noop
|
||||||
|
};
|
||||||
|
|
||||||
programWithDepth: function(fn, data, $depth) {
|
return function(context, options) {
|
||||||
var args = Array.prototype.slice.call(arguments, 2);
|
options = options || {};
|
||||||
|
return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
return function(context, options) {
|
programWithDepth: function(fn, data, $depth) {
|
||||||
options = options || {};
|
var args = Array.prototype.slice.call(arguments, 2);
|
||||||
|
|
||||||
return fn.apply(this, [context, options.data || data].concat(args));
|
return function(context, options) {
|
||||||
};
|
options = options || {};
|
||||||
},
|
|
||||||
program: function(fn, data) {
|
|
||||||
return function(context, options) {
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
return fn(context, options.data || data);
|
return fn.apply(this, [context, options.data || data].concat(args));
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
noop: function() { return ""; },
|
program: function(fn, data) {
|
||||||
invokePartial: function(partial, name, context, helpers, partials, data) {
|
return function(context, options) {
|
||||||
var options = { helpers: helpers, partials: partials, data: data };
|
options = options || {};
|
||||||
|
|
||||||
if(partial === undefined) {
|
return fn(context, options.data || data);
|
||||||
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
};
|
||||||
} else if(partial instanceof Function) {
|
},
|
||||||
return partial(context, options);
|
noop: function() { return ""; },
|
||||||
} else if (!Handlebars.compile) {
|
invokePartial: function(partial, name, context, helpers, partials, data) {
|
||||||
throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
|
var options = { helpers: helpers, partials: partials, data: data };
|
||||||
} else {
|
|
||||||
partials[name] = Handlebars.compile(partial);
|
if(partial === undefined) {
|
||||||
return partials[name](context, options);
|
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
||||||
}
|
} else if(partial instanceof Function) {
|
||||||
|
return partial(context, options);
|
||||||
|
} else if (!Handlebars.compile) {
|
||||||
|
throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
|
||||||
|
} else {
|
||||||
|
partials[name] = Handlebars.compile(partial);
|
||||||
|
return partials[name](context, options);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Handlebars.template = Handlebars.VM.template;
|
Handlebars.template = Handlebars.VM.template;
|
||||||
|
|
||||||
// END(BROWSER)
|
// END(BROWSER)
|
||||||
|
|
||||||
return Handlebars;
|
return Handlebars;
|
||||||
|
|
||||||
};
|
};
|
||||||
+66
-66
@@ -1,72 +1,72 @@
|
|||||||
exports.attach = function(Handlebars) {
|
exports.attach = function(Handlebars) {
|
||||||
|
|
||||||
// BEGIN(BROWSER)
|
// BEGIN(BROWSER)
|
||||||
|
|
||||||
Handlebars.Exception = function(message) {
|
Handlebars.Exception = function(message) {
|
||||||
var tmp = Error.prototype.constructor.apply(this, arguments);
|
var tmp = Error.prototype.constructor.apply(this, arguments);
|
||||||
|
|
||||||
for (var p in tmp) {
|
for (var p in tmp) {
|
||||||
if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
|
if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.message = tmp.message;
|
this.message = tmp.message;
|
||||||
};
|
};
|
||||||
Handlebars.Exception.prototype = new Error();
|
Handlebars.Exception.prototype = new Error();
|
||||||
|
|
||||||
// Build out our basic SafeString type
|
// Build out our basic SafeString type
|
||||||
Handlebars.SafeString = function(string) {
|
Handlebars.SafeString = function(string) {
|
||||||
this.string = string;
|
this.string = string;
|
||||||
};
|
};
|
||||||
Handlebars.SafeString.prototype.toString = function() {
|
Handlebars.SafeString.prototype.toString = function() {
|
||||||
return this.string.toString();
|
return this.string.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var escape = {
|
var escape = {
|
||||||
"<": "<",
|
"<": "<",
|
||||||
">": ">",
|
">": ">",
|
||||||
'"': """,
|
'"': """,
|
||||||
"'": "'",
|
"'": "'",
|
||||||
"`": "`"
|
"`": "`"
|
||||||
};
|
};
|
||||||
|
|
||||||
var badChars = /&(?!\w+;)|[<>"'`]/g;
|
var badChars = /&(?!\w+;)|[<>"'`]/g;
|
||||||
var possible = /[&<>"'`]/;
|
var possible = /[&<>"'`]/;
|
||||||
|
|
||||||
var escapeChar = function(chr) {
|
var escapeChar = function(chr) {
|
||||||
return escape[chr] || "&";
|
return escape[chr] || "&";
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.Utils = {
|
Handlebars.Utils = {
|
||||||
escapeExpression: function(string) {
|
escapeExpression: function(string) {
|
||||||
// don't escape SafeStrings, since they're already safe
|
// don't escape SafeStrings, since they're already safe
|
||||||
if (string instanceof Handlebars.SafeString) {
|
if (string instanceof Handlebars.SafeString) {
|
||||||
return string.toString();
|
return string.toString();
|
||||||
} else if (string == null || string === false) {
|
} else if (string == null || string === false) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!possible.test(string)) { return string; }
|
if(!possible.test(string)) { return string; }
|
||||||
return string.replace(badChars, escapeChar);
|
return string.replace(badChars, escapeChar);
|
||||||
},
|
},
|
||||||
|
|
||||||
isEmpty: function(value) {
|
isEmpty: function(value) {
|
||||||
if (typeof value === "undefined") {
|
if (typeof value === "undefined") {
|
||||||
return true;
|
return true;
|
||||||
} else if (value === null) {
|
} else if (value === null) {
|
||||||
return true;
|
return true;
|
||||||
} else if (value === false) {
|
} else if (value === false) {
|
||||||
return true;
|
return true;
|
||||||
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
|
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// END(BROWSER)
|
// END(BROWSER)
|
||||||
|
|
||||||
return Handlebars;
|
return Handlebars;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user