Fixing how arguments are deciphered in call to render

This commit is contained in:
Phil Gates-Idem 2014-06-01 15:50:17 -04:00
parent 745108e49d
commit 258daee6db

View File

@ -49,16 +49,27 @@ function Template(renderFunc) {
}
Template.prototype = {
render: function(data, context) {
render: function(data, context, callback) {
if (data == null) {
data = {};
}
var callback;
// callback is last argument if provided
callback = arguments[arguments.length - 1];
if (typeof callback === 'function') {
if (typeof context === 'function') {
callback = context;
context = new Context();
// found a callback function
if (arguments.length < 3) {
// context could not have been created so create
context = undefined;
if (arguments.length < 2) {
// data could not have been provided
data = undefined;
}
}
context = context || new Context();
context
.on('end', function() {