vendor/assets/javascripts/handlebars.js in handlebars_assets-0.1.2 vs vendor/assets/javascripts/handlebars.js in handlebars_assets-0.1.3
- old
+ new
@@ -83,10 +83,14 @@
});
Handlebars.registerHelper('with', function(context, options) {
return options.fn(context);
});
+
+Handlebars.registerHelper('log', function(context) {
+ Handlebars.log(context);
+});
;
// lib/handlebars/compiler/parser.js
/* Jison generated parser */
var handlebars = (function(){
@@ -531,18 +535,20 @@
break;
case 21: return 29;
break;
case 22: return 33;
break;
-case 23: return 'INVALID';
+case 23: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 33;
break;
-case 24: return 5;
+case 24: return 'INVALID';
break;
+case 25: return 5;
+break;
}
};
-lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s/.])/,/^./,/^$/];
-lexer.conditions = {"mu":{"rules":[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"inclusive":false},"INITIAL":{"rules":[0,1,24],"inclusive":true}};return lexer;})()
+lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s/.])/,/^\[.*\]/,/^./,/^$/];
+lexer.conditions = {"mu":{"rules":[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],"inclusive":false},"INITIAL":{"rules":[0,1,25],"inclusive":true}};return lexer;})()
parser.lexer = lexer;
return parser;
})();
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
exports.parser = handlebars;
@@ -847,11 +853,12 @@
'helperMissing': true,
'blockHelperMissing': true,
'each': true,
'if': true,
'unless': true,
- 'with': true
+ 'with': true,
+ 'log': true
};
if (knownHelpers) {
for (var name in knownHelpers) {
this.options.knownHelpers[name] = knownHelpers[name];
}
@@ -1057,16 +1064,17 @@
JavaScriptCompiler.prototype = {
// PUBLIC API: You can override these methods in a subclass to provide
// alternative compiled forms for name lookup and buffering semantics
nameLookup: function(parent, name, type) {
- if(JavaScriptCompiler.RESERVED_WORDS[name] || name.indexOf('-') !== -1 || !isNaN(name)) {
- return parent + "['" + name + "']";
- } else if (/^[0-9]+$/.test(name)) {
+ if (/^[0-9]+$/.test(name)) {
return parent + "[" + name + "]";
- } else {
- return parent + "." + name;
+ } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
+ return parent + "." + name;
+ }
+ else {
+ return parent + "['" + name + "']";
}
},
appendToBuffer: function(string) {
if (this.environment.isSimple) {
@@ -1264,20 +1272,22 @@
toPush = topStack + " = "
+ this.nameLookup('helpers', name, 'helper')
+ " || "
+ this.nameLookup('depth' + this.lastContext, name, 'context');
}
-
+
+ toPush += ';';
this.source.push(toPush);
} else {
this.pushStack('depth' + this.lastContext);
}
},
lookup: function(name) {
var topStack = this.topStack();
- this.source.push(topStack + " = " + this.nameLookup(topStack, name, 'context') + ";");
+ this.source.push(topStack + " = (" + topStack + " === null || " + topStack + " === undefined || " + topStack + " === false ? " +
+ topStack + " : " + this.nameLookup(topStack, name, 'context') + ");");
},
pushStringParam: function(string) {
this.pushStack('depth' + this.lastContext);
this.pushString(string);
@@ -1476,10 +1486,17 @@
for(var i=0, l=reservedWords.length; i<l; i++) {
compilerWords[reservedWords[i]] = true;
}
+ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
+ if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
+ return true;
+ }
+ return false;
+ }
+
})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
Handlebars.precompile = function(string, options) {
options = options || {};
@@ -1489,13 +1506,24 @@
};
Handlebars.compile = function(string, options) {
options = options || {};
- var ast = Handlebars.parse(string);
- var environment = new Handlebars.Compiler().compile(ast, options);
- var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
- return Handlebars.template(templateSpec);
+ var compiled;
+ function compile() {
+ var ast = Handlebars.parse(string);
+ var environment = new Handlebars.Compiler().compile(ast, options);
+ var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
+ return Handlebars.template(templateSpec);
+ }
+
+ // Template is only compiled on first use and cached after that point.
+ return function(context, options) {
+ if (!compiled) {
+ compiled = compile();
+ }
+ return compiled.call(this, context, options);
+ };
};
;
// lib/handlebars/vm.js
Handlebars.VM = {
template: function(templateSpec) {