|
|
|
@ -1,65 +1,77 @@
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2011 by Yehuda Katz
|
|
|
|
|
Copyright (C) 2011 by Yehuda Katz
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// lib/handlebars/browser-prefix.js
|
|
|
|
|
var Handlebars = {};
|
|
|
|
|
|
|
|
|
|
(function(Handlebars, undefined) {
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/base.js
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/base.js
|
|
|
|
|
|
|
|
|
|
Handlebars.VERSION = "1.0.0-rc.3";
|
|
|
|
|
Handlebars.COMPILER_REVISION = 2;
|
|
|
|
|
Handlebars.VERSION = "1.0.0-rc.4";
|
|
|
|
|
Handlebars.COMPILER_REVISION = 3;
|
|
|
|
|
|
|
|
|
|
Handlebars.REVISION_CHANGES = {
|
|
|
|
|
Handlebars.REVISION_CHANGES = {
|
|
|
|
|
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
|
|
|
|
|
2: '>= 1.0.0-rc.3'
|
|
|
|
|
};
|
|
|
|
|
2: '== 1.0.0-rc.3',
|
|
|
|
|
3: '>= 1.0.0-rc.4'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.helpers = {};
|
|
|
|
|
Handlebars.partials = {};
|
|
|
|
|
|
|
|
|
|
Handlebars.helpers = {};
|
|
|
|
|
Handlebars.partials = {};
|
|
|
|
|
var toString = Object.prototype.toString,
|
|
|
|
|
functionType = '[object Function]',
|
|
|
|
|
objectType = '[object Object]';
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper = function(name, fn, inverse) {
|
|
|
|
|
if(inverse) { fn.not = inverse; }
|
|
|
|
|
Handlebars.registerHelper = function(name, fn, inverse) {
|
|
|
|
|
if (toString.call(name) === objectType) {
|
|
|
|
|
if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); }
|
|
|
|
|
Handlebars.Utils.extend(this.helpers, name);
|
|
|
|
|
} else {
|
|
|
|
|
if (inverse) { fn.not = inverse; }
|
|
|
|
|
this.helpers[name] = fn;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.registerPartial = function(name, str) {
|
|
|
|
|
Handlebars.registerPartial = function(name, str) {
|
|
|
|
|
if (toString.call(name) === objectType) {
|
|
|
|
|
Handlebars.Utils.extend(this.partials, name);
|
|
|
|
|
} else {
|
|
|
|
|
this.partials[name] = str;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('helperMissing', function(arg) {
|
|
|
|
|
Handlebars.registerHelper('helperMissing', function(arg) {
|
|
|
|
|
if(arguments.length === 2) {
|
|
|
|
|
return undefined;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error("Could not find property '" + arg + "'");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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 type = toString.call(context);
|
|
|
|
@ -79,18 +91,18 @@ var Handlebars = {};
|
|
|
|
|
} else {
|
|
|
|
|
return fn(context);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Handlebars.K = function() {};
|
|
|
|
|
Handlebars.K = function() {};
|
|
|
|
|
|
|
|
|
|
Handlebars.createFrame = Object.create || function(object) {
|
|
|
|
|
Handlebars.createFrame = Object.create || function(object) {
|
|
|
|
|
Handlebars.K.prototype = object;
|
|
|
|
|
var obj = new Handlebars.K();
|
|
|
|
|
Handlebars.K.prototype = null;
|
|
|
|
|
return obj;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.logger = {
|
|
|
|
|
Handlebars.logger = {
|
|
|
|
|
DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
|
|
|
|
|
|
|
|
|
|
methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
|
|
|
|
@ -104,11 +116,11 @@ var Handlebars = {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
|
|
|
|
|
Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('each', function(context, options) {
|
|
|
|
|
Handlebars.registerHelper('each', function(context, options) {
|
|
|
|
|
var fn = options.fn, inverse = options.inverse;
|
|
|
|
|
var i = 0, ret = "", data;
|
|
|
|
|
|
|
|
|
@ -138,9 +150,9 @@ var Handlebars = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('if', function(context, options) {
|
|
|
|
|
Handlebars.registerHelper('if', function(context, options) {
|
|
|
|
|
var type = toString.call(context);
|
|
|
|
|
if(type === functionType) { context = context.call(this); }
|
|
|
|
|
|
|
|
|
@ -149,60 +161,68 @@ var Handlebars = {};
|
|
|
|
|
} else {
|
|
|
|
|
return options.fn(this);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('unless', function(context, options) {
|
|
|
|
|
Handlebars.registerHelper('unless', function(context, options) {
|
|
|
|
|
return Handlebars.helpers['if'].call(this, context, {fn: options.inverse, inverse: options.fn});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('with', function(context, options) {
|
|
|
|
|
Handlebars.registerHelper('with', function(context, options) {
|
|
|
|
|
if (!Handlebars.Utils.isEmpty(context)) return options.fn(context);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('log', function(context, options) {
|
|
|
|
|
Handlebars.registerHelper('log', function(context, options) {
|
|
|
|
|
var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
|
|
|
|
|
Handlebars.log(level, context);
|
|
|
|
|
});
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/utils.js
|
|
|
|
|
});
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/utils.js
|
|
|
|
|
|
|
|
|
|
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
|
|
|
|
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
|
|
|
|
|
|
|
|
|
Handlebars.Exception = function(message) {
|
|
|
|
|
Handlebars.Exception = function(message) {
|
|
|
|
|
var tmp = Error.prototype.constructor.apply(this, arguments);
|
|
|
|
|
|
|
|
|
|
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
|
|
|
|
for (var idx = 0; idx < errorProps.length; idx++) {
|
|
|
|
|
this[errorProps[idx]] = tmp[errorProps[idx]];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Handlebars.Exception.prototype = new Error();
|
|
|
|
|
};
|
|
|
|
|
Handlebars.Exception.prototype = new Error();
|
|
|
|
|
|
|
|
|
|
// Build out our basic SafeString type
|
|
|
|
|
Handlebars.SafeString = function(string) {
|
|
|
|
|
// Build out our basic SafeString type
|
|
|
|
|
Handlebars.SafeString = function(string) {
|
|
|
|
|
this.string = string;
|
|
|
|
|
};
|
|
|
|
|
Handlebars.SafeString.prototype.toString = function() {
|
|
|
|
|
};
|
|
|
|
|
Handlebars.SafeString.prototype.toString = function() {
|
|
|
|
|
return this.string.toString();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var escape = {
|
|
|
|
|
var escape = {
|
|
|
|
|
"&": "&",
|
|
|
|
|
"<": "<",
|
|
|
|
|
">": ">",
|
|
|
|
|
'"': """,
|
|
|
|
|
"'": "'",
|
|
|
|
|
"`": "`"
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var badChars = /[&<>"'`]/g;
|
|
|
|
|
var possible = /[&<>"'`]/;
|
|
|
|
|
var badChars = /[&<>"'`]/g;
|
|
|
|
|
var possible = /[&<>"'`]/;
|
|
|
|
|
|
|
|
|
|
var escapeChar = function(chr) {
|
|
|
|
|
var escapeChar = function(chr) {
|
|
|
|
|
return escape[chr] || "&";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.Utils = {
|
|
|
|
|
extend: function(obj, value) {
|
|
|
|
|
for(var key in value) {
|
|
|
|
|
if(value.hasOwnProperty(key)) {
|
|
|
|
|
obj[key] = value[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Handlebars.Utils = {
|
|
|
|
|
escapeExpression: function(string) {
|
|
|
|
|
// don't escape SafeStrings, since they're already safe
|
|
|
|
|
if (string instanceof Handlebars.SafeString) {
|
|
|
|
@ -211,6 +231,11 @@ var Handlebars = {};
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Force a string conversion as this will be done by the append regardless and
|
|
|
|
|
// the regex test will do this transparently behind the scenes, causing issues if
|
|
|
|
|
// an object's to string has escaped characters in it.
|
|
|
|
|
string = string.toString();
|
|
|
|
|
|
|
|
|
|
if(!possible.test(string)) { return string; }
|
|
|
|
|
return string.replace(badChars, escapeChar);
|
|
|
|
|
},
|
|
|
|
@ -224,11 +249,11 @@ var Handlebars = {};
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/runtime.js
|
|
|
|
|
};
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/runtime.js
|
|
|
|
|
|
|
|
|
|
Handlebars.VM = {
|
|
|
|
|
Handlebars.VM = {
|
|
|
|
|
template: function(templateSpec) {
|
|
|
|
|
// Just add water
|
|
|
|
|
var container = {
|
|
|
|
@ -238,13 +263,11 @@ var Handlebars = {};
|
|
|
|
|
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;
|
|
|
|
|
programWrapper = Handlebars.VM.program(i, fn, data);
|
|
|
|
|
} else if (!programWrapper) {
|
|
|
|
|
programWrapper = this.programs[i] = Handlebars.VM.program(i, fn);
|
|
|
|
|
}
|
|
|
|
|
return programWrapper;
|
|
|
|
|
},
|
|
|
|
|
programWithDepth: Handlebars.VM.programWithDepth,
|
|
|
|
|
noop: Handlebars.VM.noop,
|
|
|
|
@ -276,21 +299,27 @@ var Handlebars = {};
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
programWithDepth: function(fn, data, $depth) {
|
|
|
|
|
var args = Array.prototype.slice.call(arguments, 2);
|
|
|
|
|
programWithDepth: function(i, fn, data /*, $depth */) {
|
|
|
|
|
var args = Array.prototype.slice.call(arguments, 3);
|
|
|
|
|
|
|
|
|
|
return function(context, options) {
|
|
|
|
|
var program = function(context, options) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
|
|
return fn.apply(this, [context, options.data || data].concat(args));
|
|
|
|
|
};
|
|
|
|
|
program.program = i;
|
|
|
|
|
program.depth = args.length;
|
|
|
|
|
return program;
|
|
|
|
|
},
|
|
|
|
|
program: function(fn, data) {
|
|
|
|
|
return function(context, options) {
|
|
|
|
|
program: function(i, fn, data) {
|
|
|
|
|
var program = function(context, options) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
|
|
return fn(context, options.data || data);
|
|
|
|
|
};
|
|
|
|
|
program.program = i;
|
|
|
|
|
program.depth = 0;
|
|
|
|
|
return program;
|
|
|
|
|
},
|
|
|
|
|
noop: function() { return ""; },
|
|
|
|
|
invokePartial: function(partial, name, context, helpers, partials, data) {
|
|
|
|
@ -307,10 +336,10 @@ var Handlebars = {};
|
|
|
|
|
return partials[name](context, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.template = Handlebars.VM.template;
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/browser-suffix.js
|
|
|
|
|
Handlebars.template = Handlebars.VM.template;
|
|
|
|
|
;
|
|
|
|
|
// lib/handlebars/browser-suffix.js
|
|
|
|
|
})(Handlebars);
|
|
|
|
|
;
|