handlebars
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -32,8 +32,9 @@ /* | ||
Handlebars.VERSION = "1.0.0-rc.3"; | ||
Handlebars.COMPILER_REVISION = 2; | ||
Handlebars.VERSION = "1.0.0-rc.4"; | ||
Handlebars.COMPILER_REVISION = 3; | ||
Handlebars.REVISION_CHANGES = { | ||
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it | ||
2: '>= 1.0.0-rc.3' | ||
2: '== 1.0.0-rc.3', | ||
3: '>= 1.0.0-rc.4' | ||
}; | ||
@@ -44,9 +45,22 @@ | ||
var toString = Object.prototype.toString, | ||
functionType = '[object Function]', | ||
objectType = '[object Object]'; | ||
Handlebars.registerHelper = function(name, fn, inverse) { | ||
if(inverse) { fn.not = inverse; } | ||
this.helpers[name] = fn; | ||
if (toString.call(name) === objectType) { | ||
if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); } | ||
Handlebars.Utils.extend(this.helpers, name); | ||
} else { | ||
if (inverse) { fn.not = inverse; } | ||
this.helpers[name] = fn; | ||
} | ||
}; | ||
Handlebars.registerPartial = function(name, str) { | ||
this.partials[name] = str; | ||
if (toString.call(name) === objectType) { | ||
Handlebars.Utils.extend(this.partials, name); | ||
} else { | ||
this.partials[name] = str; | ||
} | ||
}; | ||
@@ -62,4 +76,2 @@ | ||
var toString = Object.prototype.toString, functionType = "[object Function]"; | ||
Handlebars.registerHelper('blockHelperMissing', function(context, options) { | ||
@@ -162,3 +174,3 @@ var inverse = options.inverse || function() {}, fn = options.fn; | ||
Handlebars.registerHelper('with', function(context, options) { | ||
return options.fn(context); | ||
if (!Handlebars.Utils.isEmpty(context)) return options.fn(context); | ||
}); | ||
@@ -210,2 +222,10 @@ | ||
Handlebars.Utils = { | ||
extend: function(obj, value) { | ||
for(var key in value) { | ||
if(value.hasOwnProperty(key)) { | ||
obj[key] = value[key]; | ||
} | ||
} | ||
}, | ||
escapeExpression: function(string) { | ||
@@ -219,2 +239,7 @@ // don't escape SafeStrings, since they're already safe | ||
// Force a string conversion as this will be done by the append regardless and | ||
// the regex test will do this transparently behind the scenes, causing issues if | ||
// an object's to string has escaped characters in it. | ||
string = string.toString(); | ||
if(!possible.test(string)) { return string; } | ||
@@ -247,9 +272,7 @@ return string.replace(badChars, escapeChar); | ||
if(data) { | ||
return Handlebars.VM.program(fn, data); | ||
} else if(programWrapper) { | ||
return programWrapper; | ||
} else { | ||
programWrapper = this.programs[i] = Handlebars.VM.program(fn); | ||
return programWrapper; | ||
programWrapper = Handlebars.VM.program(i, fn, data); | ||
} else if (!programWrapper) { | ||
programWrapper = this.programs[i] = Handlebars.VM.program(i, fn); | ||
} | ||
return programWrapper; | ||
}, | ||
@@ -286,6 +309,6 @@ programWithDepth: Handlebars.VM.programWithDepth, | ||
programWithDepth: function(fn, data, $depth) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
programWithDepth: function(i, fn, data /*, $depth */) { | ||
var args = Array.prototype.slice.call(arguments, 3); | ||
return function(context, options) { | ||
var program = function(context, options) { | ||
options = options || {}; | ||
@@ -295,5 +318,8 @@ | ||
}; | ||
program.program = i; | ||
program.depth = args.length; | ||
return program; | ||
}, | ||
program: function(fn, data) { | ||
return function(context, options) { | ||
program: function(i, fn, data) { | ||
var program = function(context, options) { | ||
options = options || {}; | ||
@@ -303,2 +329,5 @@ | ||
}; | ||
program.program = i; | ||
program.depth = 0; | ||
return program; | ||
}, | ||
@@ -305,0 +334,0 @@ noop: function() { return ""; }, |
@@ -9,8 +9,9 @@ /*jshint eqnull: true */ | ||
Handlebars.VERSION = "1.0.0-rc.3"; | ||
Handlebars.COMPILER_REVISION = 2; | ||
Handlebars.VERSION = "1.0.0-rc.4"; | ||
Handlebars.COMPILER_REVISION = 3; | ||
Handlebars.REVISION_CHANGES = { | ||
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it | ||
2: '>= 1.0.0-rc.3' | ||
2: '== 1.0.0-rc.3', | ||
3: '>= 1.0.0-rc.4' | ||
}; | ||
@@ -21,9 +22,22 @@ | ||
var toString = Object.prototype.toString, | ||
functionType = '[object Function]', | ||
objectType = '[object Object]'; | ||
Handlebars.registerHelper = function(name, fn, inverse) { | ||
if(inverse) { fn.not = inverse; } | ||
this.helpers[name] = fn; | ||
if (toString.call(name) === objectType) { | ||
if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); } | ||
Handlebars.Utils.extend(this.helpers, name); | ||
} else { | ||
if (inverse) { fn.not = inverse; } | ||
this.helpers[name] = fn; | ||
} | ||
}; | ||
Handlebars.registerPartial = function(name, str) { | ||
this.partials[name] = str; | ||
if (toString.call(name) === objectType) { | ||
Handlebars.Utils.extend(this.partials, name); | ||
} else { | ||
this.partials[name] = str; | ||
} | ||
}; | ||
@@ -39,4 +53,2 @@ | ||
var toString = Object.prototype.toString, functionType = "[object Function]"; | ||
Handlebars.registerHelper('blockHelperMissing', function(context, options) { | ||
@@ -139,3 +151,3 @@ var inverse = options.inverse || function() {}, fn = options.fn; | ||
Handlebars.registerHelper('with', function(context, options) { | ||
return options.fn(context); | ||
if (!Handlebars.Utils.isEmpty(context)) return options.fn(context); | ||
}); | ||
@@ -142,0 +154,0 @@ |
@@ -192,2 +192,6 @@ var compilerbase = require("./base"); | ||
if (this.options.stringParams) { | ||
if(val.depth) { | ||
this.addDepth(val.depth); | ||
} | ||
this.opcode('getContext', val.depth || 0); | ||
this.opcode('pushStringParam', val.stringModeValue, val.type); | ||
@@ -276,3 +280,3 @@ } else { | ||
this.opcode('invokeKnownHelper', params.length, name); | ||
} else if (this.knownHelpersOnly) { | ||
} else if (this.options.knownHelpersOnly) { | ||
throw new Error("You specified knownHelpersOnly, but used the unknown helper " + name); | ||
@@ -778,6 +782,7 @@ } else { | ||
this.register('hashTypes', '{}'); | ||
this.register('hashContexts', '{}'); | ||
} | ||
}, | ||
pushHash: function() { | ||
this.hash = {values: [], types: []}; | ||
this.hash = {values: [], types: [], contexts: []}; | ||
}, | ||
@@ -789,2 +794,3 @@ popHash: function() { | ||
if (this.options.stringParams) { | ||
this.register('hashContexts', '{' + hash.contexts.join(',') + '}'); | ||
this.register('hashTypes', '{' + hash.types.join(',') + '}'); | ||
@@ -932,2 +938,3 @@ } | ||
var value = this.popStack(), | ||
context, | ||
type; | ||
@@ -937,6 +944,9 @@ | ||
type = this.popStack(); | ||
this.popStack(); | ||
context = this.popStack(); | ||
} | ||
var hash = this.hash; | ||
if (context) { | ||
hash.contexts.push("'" + key + "': " + context); | ||
} | ||
if (type) { | ||
@@ -1002,8 +1012,3 @@ hash.types.push("'" + key + "': " + type); | ||
if(depths.length === 0) { | ||
return "self.program(" + programParams.join(", ") + ")"; | ||
} else { | ||
programParams.shift(); | ||
return "self.programWithDepth(" + programParams.join(", ") + ")"; | ||
} | ||
return (depths.length === 0 ? "self.program(" : "self.programWithDepth(") + programParams.join(", ") + ")"; | ||
}, | ||
@@ -1140,3 +1145,5 @@ | ||
.replace(/\n/g, '\\n') | ||
.replace(/\r/g, '\\r') + '"'; | ||
.replace(/\r/g, '\\r') | ||
.replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4 | ||
.replace(/\u2029/g, '\\u2029') + '"'; | ||
}, | ||
@@ -1197,2 +1204,3 @@ | ||
options.push("types:[" + types.join(",") + "]"); | ||
options.push("hashContexts:hashContexts"); | ||
options.push("hashTypes:hashTypes"); | ||
@@ -1248,3 +1256,3 @@ } | ||
Handlebars.precompile = function(input, options) { | ||
if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) { | ||
if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) { | ||
throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input); | ||
@@ -1263,3 +1271,3 @@ } | ||
Handlebars.compile = function(input, options) { | ||
if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) { | ||
if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) { | ||
throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input); | ||
@@ -1266,0 +1274,0 @@ } |
@@ -391,3 +391,5 @@ // BEGIN(BROWSER) | ||
switch($avoiding_name_collisions) { | ||
case 0: | ||
case 0: yy_.yytext = "\\"; return 14; | ||
break; | ||
case 1: | ||
if(yy_.yytext.slice(-1) !== "\\") this.begin("mu"); | ||
@@ -398,5 +400,5 @@ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu"); | ||
break; | ||
case 1: return 14; | ||
case 2: return 14; | ||
break; | ||
case 2: | ||
case 3: | ||
if(yy_.yytext.slice(-1) !== "\\") this.popState(); | ||
@@ -407,66 +409,66 @@ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1); | ||
break; | ||
case 3: yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15; | ||
case 4: yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15; | ||
break; | ||
case 4: this.begin("par"); return 24; | ||
case 5: this.begin("par"); return 24; | ||
break; | ||
case 5: return 16; | ||
case 6: return 16; | ||
break; | ||
case 6: return 20; | ||
case 7: return 20; | ||
break; | ||
case 7: return 19; | ||
break; | ||
case 8: return 19; | ||
break; | ||
case 9: return 23; | ||
case 9: return 19; | ||
break; | ||
case 10: return 23; | ||
break; | ||
case 11: this.popState(); this.begin('com'); | ||
case 11: return 23; | ||
break; | ||
case 12: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15; | ||
case 12: this.popState(); this.begin('com'); | ||
break; | ||
case 13: return 22; | ||
case 13: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15; | ||
break; | ||
case 14: return 36; | ||
case 14: return 22; | ||
break; | ||
case 15: return 35; | ||
case 15: return 36; | ||
break; | ||
case 16: return 35; | ||
break; | ||
case 17: return 39; | ||
case 17: return 35; | ||
break; | ||
case 18: /*ignore whitespace*/ | ||
case 18: return 39; | ||
break; | ||
case 19: this.popState(); return 18; | ||
case 19: /*ignore whitespace*/ | ||
break; | ||
case 20: this.popState(); return 18; | ||
break; | ||
case 21: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 30; | ||
case 21: this.popState(); return 18; | ||
break; | ||
case 22: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 30; | ||
case 22: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 30; | ||
break; | ||
case 23: yy_.yytext = yy_.yytext.substr(1); return 28; | ||
case 23: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 30; | ||
break; | ||
case 24: return 32; | ||
case 24: yy_.yytext = yy_.yytext.substr(1); return 28; | ||
break; | ||
case 25: return 32; | ||
break; | ||
case 26: return 31; | ||
case 26: return 32; | ||
break; | ||
case 27: return 35; | ||
case 27: return 31; | ||
break; | ||
case 28: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 35; | ||
case 28: return 35; | ||
break; | ||
case 29: return 'INVALID'; | ||
case 29: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 35; | ||
break; | ||
case 30: /*ignore whitespace*/ | ||
case 30: return 'INVALID'; | ||
break; | ||
case 31: this.popState(); return 37; | ||
case 31: /*ignore whitespace*/ | ||
break; | ||
case 32: return 5; | ||
case 32: this.popState(); return 37; | ||
break; | ||
case 33: return 5; | ||
break; | ||
} | ||
}; | ||
lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[} ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:\s+)/,/^(?:[a-zA-Z0-9_$-/]+)/,/^(?:$)/]; | ||
lexer.conditions = {"mu":{"rules":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,32],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"com":{"rules":[3],"inclusive":false},"par":{"rules":[30,31],"inclusive":false},"INITIAL":{"rules":[0,1,32],"inclusive":true}}; | ||
lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$:\-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:\s+)/,/^(?:[a-zA-Z0-9_$\-\/]+)/,/^(?:$)/]; | ||
lexer.conditions = {"mu":{"rules":[5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,33],"inclusive":false},"emu":{"rules":[3],"inclusive":false},"com":{"rules":[4],"inclusive":false},"par":{"rules":[31,32],"inclusive":false},"INITIAL":{"rules":[0,1,2,33],"inclusive":true}}; | ||
return lexer;})() | ||
@@ -473,0 +475,0 @@ parser.lexer = lexer; |
@@ -15,9 +15,7 @@ exports.attach = function(Handlebars) { | ||
if(data) { | ||
return Handlebars.VM.program(fn, data); | ||
} else if(programWrapper) { | ||
return programWrapper; | ||
} else { | ||
programWrapper = this.programs[i] = Handlebars.VM.program(fn); | ||
return programWrapper; | ||
programWrapper = Handlebars.VM.program(i, fn, data); | ||
} else if (!programWrapper) { | ||
programWrapper = this.programs[i] = Handlebars.VM.program(i, fn); | ||
} | ||
return programWrapper; | ||
}, | ||
@@ -54,6 +52,6 @@ programWithDepth: Handlebars.VM.programWithDepth, | ||
programWithDepth: function(fn, data, $depth) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
programWithDepth: function(i, fn, data /*, $depth */) { | ||
var args = Array.prototype.slice.call(arguments, 3); | ||
return function(context, options) { | ||
var program = function(context, options) { | ||
options = options || {}; | ||
@@ -63,5 +61,8 @@ | ||
}; | ||
program.program = i; | ||
program.depth = args.length; | ||
return program; | ||
}, | ||
program: function(fn, data) { | ||
return function(context, options) { | ||
program: function(i, fn, data) { | ||
var program = function(context, options) { | ||
options = options || {}; | ||
@@ -71,2 +72,5 @@ | ||
}; | ||
program.program = i; | ||
program.depth = 0; | ||
return program; | ||
}, | ||
@@ -73,0 +77,0 @@ noop: function() { return ""; }, |
exports.attach = function(Handlebars) { | ||
var toString = Object.prototype.toString; | ||
// BEGIN(BROWSER) | ||
@@ -42,2 +44,10 @@ | ||
Handlebars.Utils = { | ||
extend: function(obj, value) { | ||
for(var key in value) { | ||
if(value.hasOwnProperty(key)) { | ||
obj[key] = value[key]; | ||
} | ||
} | ||
}, | ||
escapeExpression: function(string) { | ||
@@ -51,2 +61,7 @@ // don't escape SafeStrings, since they're already safe | ||
// Force a string conversion as this will be done by the append regardless and | ||
// the regex test will do this transparently behind the scenes, causing issues if | ||
// an object's to string has escaped characters in it. | ||
string = string.toString(); | ||
if(!possible.test(string)) { return string; } | ||
@@ -53,0 +68,0 @@ return string.replace(badChars, escapeChar); |
{ | ||
"name": "handlebars", | ||
"description": "Extension of the Mustache logicless template language", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"homepage": "http://www.handlebarsjs.com/", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184077
30
4380
370