vendor/ember/development/handlebars-runtime.js in ember-rails-0.8.0 vs vendor/ember/development/handlebars-runtime.js in ember-rails-0.9.2
- old
+ new
@@ -1,13 +1,13 @@
// lib/handlebars/base.js
/*jshint eqnull:true*/
this.Handlebars = {};
-(function() {
+(function(Handlebars) {
-Handlebars.VERSION = "1.0.rc.1";
+Handlebars.VERSION = "1.0.rc.2";
Handlebars.helpers = {};
Handlebars.partials = {};
Handlebars.registerHelper = function(name, fn, inverse) {
@@ -42,33 +42,75 @@
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.logger = {
+ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
+
+ methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
+
+ // can be overridden in the host environment
+ log: function(level, obj) {
+ if (Handlebars.logger.level <= level) {
+ var method = Handlebars.logger.methodMap[level];
+ if (typeof console !== 'undefined' && console[method]) {
+ console[method].call(console, obj);
+ }
+ }
+ }
+};
+
+Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
+
Handlebars.registerHelper('each', function(context, options) {
var fn = options.fn, inverse = options.inverse;
- var ret = "";
+ var i = 0, ret = "", data;
- if(context && context.length > 0) {
- for(var i=0, j=context.length; i<j; i++) {
- ret = ret + fn(context[i]);
+ if (options.data) {
+ data = Handlebars.createFrame(options.data);
+ }
+
+ if(context && typeof context === 'object') {
+ if(context instanceof Array){
+ for(var j = context.length; i<j; i++) {
+ if (data) { data.index = i; }
+ ret = ret + fn(context[i], { data: data });
+ }
+ } else {
+ for(var key in context) {
+ if(context.hasOwnProperty(key)) {
+ if(data) { data.key = key; }
+ ret = ret + fn(context[key], {data: data});
+ i++;
+ }
+ }
}
- } else {
+ }
+
+ if(i === 0){
ret = inverse(this);
}
+
return ret;
});
Handlebars.registerHelper('if', function(context, options) {
var type = toString.call(context);
@@ -91,25 +133,28 @@
Handlebars.registerHelper('with', function(context, options) {
return options.fn(context);
});
-Handlebars.registerHelper('log', function(context) {
- Handlebars.log(context);
+Handlebars.registerHelper('log', function(context, options) {
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
+ Handlebars.log(level, context);
});
-}());
+}(this.Handlebars));
;
// lib/handlebars/utils.js
+
+var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
+
Handlebars.Exception = function(message) {
var tmp = Error.prototype.constructor.apply(this, arguments);
- for (var p in tmp) {
- if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
+ // 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]];
}
-
- this.message = tmp.message;
};
Handlebars.Exception.prototype = new Error();
// Build out our basic SafeString type
Handlebars.SafeString = function(string) {
@@ -119,18 +164,19 @@
return this.string.toString();
};
(function() {
var escape = {
+ "&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"`": "`"
};
- var badChars = /&(?!\w+;)|[<>"'`]/g;
+ var badChars = /[&<>"'`]/g;
var possible = /[&<>"'`]/;
var escapeChar = function(chr) {
return escape[chr] || "&";
};
@@ -147,16 +193,12 @@
if(!possible.test(string)) { return string; }
return string.replace(badChars, escapeChar);
},
isEmpty: function(value) {
- if (typeof value === "undefined") {
+ if (!value && value !== 0) {
return true;
- } else if (value === null) {
- return true;
- } else if (value === false) {
- return true;
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
return true;
} else {
return false;
}
@@ -217,10 +259,10 @@
} 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);
}
}
};