| @@ -8,6 +8,12 @@ var Mustache = function() { | |||||
| var regexCache = {}; | var regexCache = {}; | ||||
| var Renderer = function() {}; | var Renderer = function() {}; | ||||
| var _toString = Object.prototype.toString; | |||||
| Array.isArray = Array.isArray || function (obj) { | |||||
| return _toString.call(obj) == "[object Array]"; | |||||
| } | |||||
| Renderer.prototype = { | Renderer.prototype = { | ||||
| otag: "{{", | otag: "{{", | ||||
| ctag: "}}", | ctag: "}}", | ||||
| @@ -161,14 +167,14 @@ var Mustache = function() { | |||||
| value = that.find(name, context); | value = that.find(name, context); | ||||
| if (type === "^") { // inverted section | if (type === "^") { // inverted section | ||||
| if (!value || that.is_array(value) && value.length === 0) { | |||||
| if (!value || Array.isArray(value) && value.length === 0) { | |||||
| // false or empty list, render it | // false or empty list, render it | ||||
| renderedContent = that.render(content, context, partials, true); | renderedContent = that.render(content, context, partials, true); | ||||
| } else { | } else { | ||||
| renderedContent = ""; | renderedContent = ""; | ||||
| } | } | ||||
| } else if (type === "#") { // normal section | } else if (type === "#") { // normal section | ||||
| if (that.is_array(value)) { // Enumerable, Let's loop! | |||||
| if (Array.isArray(value)) { // Enumerable, Let's loop! | |||||
| renderedContent = that.map(value, function(row) { | renderedContent = that.map(value, function(row) { | ||||
| return that.render(content, that.create_context(row), partials, true); | return that.render(content, that.create_context(row), partials, true); | ||||
| }).join(""); | }).join(""); | ||||
| @@ -269,7 +275,7 @@ var Mustache = function() { | |||||
| } | } | ||||
| var value; | var value; | ||||
| // check for dot notation eg. foo.bar | // check for dot notation eg. foo.bar | ||||
| if(name.match(/([a-z_]+)\./ig)){ | if(name.match(/([a-z_]+)\./ig)){ | ||||
| var childValue = this.walk_context(name, context); | var childValue = this.walk_context(name, context); | ||||
| @@ -354,10 +360,6 @@ var Mustache = function() { | |||||
| return a && typeof a == "object"; | return a && typeof a == "object"; | ||||
| }, | }, | ||||
| is_array: function(a) { | |||||
| return Object.prototype.toString.call(a) === '[object Array]'; | |||||
| }, | |||||
| /* | /* | ||||
| Gets rid of leading and trailing whitespace | Gets rid of leading and trailing whitespace | ||||
| */ | */ | ||||