vendor/assets/javascripts/handlebars.runtime.js in handlebars_assets-0.6.5 vs vendor/assets/javascripts/handlebars.runtime.js in handlebars_assets-0.6.6
- old
+ new
@@ -1,10 +1,14 @@
// lib/handlebars/base.js
-var Handlebars = {};
-Handlebars.VERSION = "1.0.beta.6";
+/*jshint eqnull:true*/
+this.Handlebars = {};
+(function(Handlebars) {
+
+Handlebars.VERSION = "1.0.rc.1";
+
Handlebars.helpers = {};
Handlebars.partials = {};
Handlebars.registerHelper = function(name, fn, inverse) {
if(inverse) { fn.not = inverse; }
@@ -38,29 +42,40 @@
return fn(this);
} else if(context === false || context == null) {
return inverse(this);
} else if(type === "[object Array]") {
if(context.length > 0) {
- for(var i=0, j=context.length; i<j; i++) {
- ret = ret + fn(context[i]);
- }
+ return Handlebars.helpers.each(context, options);
} else {
- ret = inverse(this);
+ return 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 = "";
+ 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++) {
- ret = ret + fn(context[i]);
+ if (data) { data.index = i; }
+ ret = ret + fn(context[i], { data: data });
}
} else {
ret = inverse(this);
}
return ret;
@@ -90,10 +105,12 @@
});
Handlebars.registerHelper('log', function(context) {
Handlebars.log(context);
});
+
+}(this.Handlebars));
;
// lib/handlebars/utils.js
Handlebars.Exception = function(message) {
var tmp = Error.prototype.constructor.apply(this, arguments);
@@ -101,11 +118,11 @@
if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
}
this.message = tmp.message;
};
-Handlebars.Exception.prototype = new Error;
+Handlebars.Exception.prototype = new Error();
// Build out our basic SafeString type
Handlebars.SafeString = function(string) {
this.string = string;
};
@@ -113,18 +130,19 @@
return this.string.toString();
};
(function() {
var escape = {
+ "&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"`": "`"
};
- var badChars = /&(?!\w+;)|[<>"'`]/g;
+ var badChars = /[&<>"'`]/g;
var possible = /[&<>"'`]/;
var escapeChar = function(chr) {
return escape[chr] || "&";
};
@@ -202,19 +220,19 @@
return fn(context, options.data || data);
};
},
noop: function() { return ""; },
invokePartial: function(partial, name, context, helpers, partials, data) {
- options = { helpers: helpers, partials: partials, data: data };
+ var options = { helpers: helpers, partials: partials, data: data };
if(partial === undefined) {
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);
+ partials[name] = Handlebars.compile(partial, {data: data !== undefined});
return partials[name](context, options);
}
}
};