From 3bc7d7b9989a504148f875f4ef6bd786066f4299 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 29 Jul 2013 21:30:42 -0500 Subject: [PATCH 01/13] ID lexer control class --- dist/handlebars.js | 2 +- src/handlebars.l | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dist/handlebars.js b/dist/handlebars.js index 90f20ecd..f8eb1f2a 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -640,7 +640,7 @@ case 31:return 5; break; } }; -lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}\/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/]; +lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}\/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/]; 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,31],"inclusive":false},"emu":{"rules":[3],"inclusive":false},"com":{"rules":[4],"inclusive":false},"INITIAL":{"rules":[0,1,2,31],"inclusive":true}}; return lexer;})() parser.lexer = lexer; diff --git a/src/handlebars.l b/src/handlebars.l index 5fd0bcda..d13e111a 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -1,6 +1,17 @@ %x mu emu com +/* +ID is the inverse of control characters. +Control characters ranges: + [\s] Whitespace + [!"#%-,\./] !, ", #, %, &, ', (, ), *, +, ,, ., /, Exceptions in range: $, - + [;->@] ;, <, =, >, @, Exceptions in range: :, ? + [\[-\^`] [, \, ], ^, `, Exceptions in range: _ + [\{-~] {, |, }, ~ +*/ +ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] + %% "\\\\"/("{{") yytext = "\\"; return 'CONTENT'; @@ -45,16 +56,7 @@ "false"/[}\s] return 'BOOLEAN'; \-?[0-9]+/[}\s] return 'INTEGER'; -/* -ID is the inverse of control characters. -Control characters ranges: - [\s] Whitespace - [!"#%-,\./] !, ", #, %, &, ', (, ), *, +, ,, ., /, Exceptions in range: $, - - [;->@] ;, <, =, >, @, Exceptions in range: :, ? - [\[-\^`] [, \, ], ^, `, Exceptions in range: _ - [\{-~] {, |, }, ~ -*/ -[^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] return 'ID'; +{ID} return 'ID'; '['[^\]]*']' yytext = yytext.substr(1, yyleng-2); return 'ID'; . return 'INVALID'; From 03310df95e91880ea647f38805dc9694a3258a65 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 29 Jul 2013 21:37:04 -0500 Subject: [PATCH 02/13] Add strip lex helper method --- dist/handlebars.js | 20 +++++++++++++------- src/handlebars.l | 24 ++++++++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/dist/handlebars.js b/dist/handlebars.js index f8eb1f2a..be599eb4 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -564,13 +564,19 @@ pushState:function begin(condition) { lexer.options = {}; lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { + +function strip(start, end) { + return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng-end); +} + + var YYSTATE=YY_START switch($avoiding_name_collisions) { case 0:yy_.yytext = "\\"; return 14; break; case 1: if(yy_.yytext.slice(-1) !== "\\") this.begin("mu"); - if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu"); + if(yy_.yytext.slice(-1) === "\\") strip(0,1), this.begin("emu"); if(yy_.yytext) return 14; break; @@ -578,11 +584,11 @@ case 2:return 14; break; case 3: if(yy_.yytext.slice(-1) !== "\\") this.popState(); - if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1); + if(yy_.yytext.slice(-1) === "\\") strip(0,1); return 14; break; -case 4:yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15; +case 4:strip(0,4); this.popState(); return 15; break; case 5:return 25; break; @@ -600,7 +606,7 @@ case 11:return 22; break; case 12:this.popState(); this.begin('com'); break; -case 13:yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15; +case 13:strip(3,5); this.popState(); return 15; break; case 14:return 22; break; @@ -618,9 +624,9 @@ case 20:this.popState(); return 24; break; case 21:this.popState(); return 18; break; -case 22:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 32; +case 22:yy_.yytext = strip(1,2).replace(/\\"/g,'"'); return 32; break; -case 23:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 32; +case 23:yy_.yytext = strip(1,2).replace(/\\'/g,"'"); return 32; break; case 24:return 40; break; @@ -632,7 +638,7 @@ case 27:return 33; break; case 28:return 38; break; -case 29:yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 38; +case 29:yy_.yytext = strip(1,2); return 38; break; case 30:return 'INVALID'; break; diff --git a/src/handlebars.l b/src/handlebars.l index d13e111a..018096b0 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -1,6 +1,15 @@ %x mu emu com +%{ + +function strip(start, end) { + return yytext = yytext.substr(start, yyleng-end); +} + +%} + + /* ID is the inverse of control characters. Control characters ranges: @@ -17,7 +26,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] "\\\\"/("{{") yytext = "\\"; return 'CONTENT'; [^\x00]*?/("{{") { if(yytext.slice(-1) !== "\\") this.begin("mu"); - if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1), this.begin("emu"); + if(yytext.slice(-1) === "\\") strip(0,1), this.begin("emu"); if(yytext) return 'CONTENT'; } @@ -25,11 +34,11 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] [^\x00]{2,}?/("{{"|<>) { if(yytext.slice(-1) !== "\\") this.popState(); - if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1); + if(yytext.slice(-1) === "\\") strip(0,1); return 'CONTENT'; } -[\s\S]*?"--}}" yytext = yytext.substr(0, yyleng-4); this.popState(); return 'COMMENT'; +[\s\S]*?"--}}" strip(0,4); this.popState(); return 'COMMENT'; "{{>" return 'OPEN_PARTIAL'; "{{#" return 'OPEN_BLOCK'; @@ -39,7 +48,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] "{{{" return 'OPEN_UNESCAPED'; "{{&" return 'OPEN'; "{{!--" this.popState(); this.begin('com'); -"{{!"[\s\S]*?"}}" yytext = yytext.substr(3,yyleng-5); this.popState(); return 'COMMENT'; +"{{!"[\s\S]*?"}}" strip(3,5); this.popState(); return 'COMMENT'; "{{" return 'OPEN'; "=" return 'EQUALS'; @@ -49,8 +58,8 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] \s+ /*ignore whitespace*/ "}}}" this.popState(); return 'CLOSE_UNESCAPED'; "}}" this.popState(); return 'CLOSE'; -'"'("\\"["]|[^"])*'"' yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; -"'"("\\"[']|[^'])*"'" yytext = yytext.substr(1,yyleng-2).replace(/\\'/g,"'"); return 'STRING'; +'"'("\\"["]|[^"])*'"' yytext = strip(1,2).replace(/\\"/g,'"'); return 'STRING'; +"'"("\\"[']|[^'])*"'" yytext = strip(1,2).replace(/\\'/g,"'"); return 'STRING'; "@" return 'DATA'; "true"/[}\s] return 'BOOLEAN'; "false"/[}\s] return 'BOOLEAN'; @@ -58,8 +67,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.] {ID} return 'ID'; -'['[^\]]*']' yytext = yytext.substr(1, yyleng-2); return 'ID'; +'['[^\]]*']' yytext = strip(1,2); return 'ID'; . return 'INVALID'; <> return 'EOF'; - From 9ca4f9c606cf562372d1123def592f27ba1a4928 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Tue, 30 Jul 2013 11:07:41 -0500 Subject: [PATCH 03/13] Remove unused var --- dist/handlebars.js | 6 +++--- lib/handlebars/compiler/javascript-compiler.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/handlebars.js b/dist/handlebars.js index be599eb4..4f1b1e16 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -1667,10 +1667,10 @@ JavaScriptCompiler.prototype = { // [lookupData] // // On stack, before: ... - // On stack, after: data[id], ... + // On stack, after: data, ... // - // Push the result of looking up `id` on the current data - lookupData: function(id) { + // Push the data lookup operator + lookupData: function() { this.push('data'); }, diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 4548c6ae..0bb18169 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -350,10 +350,10 @@ JavaScriptCompiler.prototype = { // [lookupData] // // On stack, before: ... - // On stack, after: data[id], ... + // On stack, after: data, ... // - // Push the result of looking up `id` on the current data - lookupData: function(id) { + // Push the data lookup operator + lookupData: function() { this.push('data'); }, From 4f5c05ffe9117617b652c37e313b462b9f6f12ae Mon Sep 17 00:00:00 2001 From: kpdecker Date: Tue, 30 Jul 2013 11:08:46 -0500 Subject: [PATCH 04/13] Simplify inverse only block case --- dist/handlebars.js | 2 +- spec/parser.js | 4 ++-- src/handlebars.yy | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/handlebars.js b/dist/handlebars.js index 4f1b1e16..e0a83681 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -205,7 +205,7 @@ case 4:this.$ = new yy.ProgramNode($$[$0-1], []); break; case 5:this.$ = new yy.ProgramNode($$[$0]); break; -case 6:this.$ = new yy.ProgramNode([], []); +case 6:this.$ = new yy.ProgramNode([]); break; case 7:this.$ = new yy.ProgramNode([]); break; diff --git a/spec/parser.js b/spec/parser.js index 06a60db3..3397105f 100644 --- a/spec/parser.js +++ b/spec/parser.js @@ -108,11 +108,11 @@ describe('parser', function() { }); it('parses empty blocks with empty inverse section', function() { - ast_for("{{#foo}}{{^}}{{/foo}}").should.equal("BLOCK:\n {{ ID:foo [] }}\n PROGRAM:\n {{^}}\n"); + ast_for("{{#foo}}{{^}}{{/foo}}").should.equal("BLOCK:\n {{ ID:foo [] }}\n PROGRAM:\n"); }); it('parses empty blocks with empty inverse (else-style) section', function() { - ast_for("{{#foo}}{{else}}{{/foo}}").should.equal("BLOCK:\n {{ ID:foo [] }}\n PROGRAM:\n {{^}}\n"); + ast_for("{{#foo}}{{else}}{{/foo}}").should.equal("BLOCK:\n {{ ID:foo [] }}\n PROGRAM:\n"); }); it('parses non-empty blocks with empty inverse section', function() { diff --git a/src/handlebars.yy b/src/handlebars.yy index 5764f6f1..d2f24c45 100644 --- a/src/handlebars.yy +++ b/src/handlebars.yy @@ -13,7 +13,7 @@ program | statements simpleInverse statements -> new yy.ProgramNode($1, $3) | statements simpleInverse -> new yy.ProgramNode($1, []) | statements -> new yy.ProgramNode($1) - | simpleInverse -> new yy.ProgramNode([], []) + | simpleInverse -> new yy.ProgramNode([]) | "" -> new yy.ProgramNode([]) ; From e62999f9ece7d9218b9768a908f8df9c11d7e920 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Tue, 30 Jul 2013 11:08:58 -0500 Subject: [PATCH 05/13] Improve uglify compression --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 30187d74..d1b703a2 100644 --- a/Rakefile +++ b/Rakefile @@ -79,8 +79,8 @@ task :build => [:compile] do |task| Rake::Task["dist/handlebars.js"].execute Rake::Task["dist/handlebars.runtime.js"].execute - system "./node_modules/.bin/uglifyjs --comments -o dist/handlebars.min.js dist/handlebars.js" - system "./node_modules/.bin/uglifyjs --comments -o dist/handlebars.runtime.min.js dist/handlebars.runtime.js" + system "./node_modules/.bin/uglifyjs -m -c --comments -o dist/handlebars.min.js dist/handlebars.js" + system "./node_modules/.bin/uglifyjs -m -c --comments -o dist/handlebars.runtime.min.js dist/handlebars.runtime.js" end # Updates the various version numbers. From 7c1ce99ebac314cf6e9c06d2ac47f62b187cac04 Mon Sep 17 00:00:00 2001 From: Jon Schlinkert Date: Tue, 6 Aug 2013 19:20:31 -0400 Subject: [PATCH 06/13] adds Assemble and handlebars-helpers projects to "Handlebars in the Wild" section of README. Bullets are now ordered alphabetically --- README.markdown | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/README.markdown b/README.markdown index a279c1ac..f593a689 100644 --- a/README.markdown +++ b/README.markdown @@ -355,28 +355,41 @@ Known Issues * Using a variable, helper, or partial named `class` causes errors in IE browsers. (Instead, use `className`) Handlebars in the Wild ------------------ +---------------------- + +* [Assemble](http://assemble.io), by [@jonschlinkert](https://github.com/jonschlinkert) + and [@doowb](https://github.com/doowb), is a static site generator that uses Handlebars.js + as its template engine. +* [Ember.js](http://www.emberjs.com) makes Handlebars.js the primary way to + structure your views, also with automatic data binding support. +* [handlebars_assets](http://github.com/leshill/handlebars_assets): A Rails Asset Pipeline gem + from Les Hill (@leshill). +* [handlebars-helpers](https://github.com/assemble/handlebars-helpers) is an extensive library + with 100+ handlebars helpers. +* [hbs](http://github.com/donpark/hbs): An Express.js view engine adapter for Handlebars.js, + from Don Park. * [jblotus](http://github.com/jblotus) created [http://tryhandlebarsjs.com](http://tryhandlebarsjs.com) for anyone who would like to try out Handlebars.js in their browser. -* Don Park wrote an Express.js view engine adapter for Handlebars.js called - [hbs](http://github.com/donpark/hbs). +* [jQuery plugin](http://71104.github.io/jquery-handlebars/): allows you to use + Handlebars.js with [jQuery](http://jquery.com/). +* [Lumbar](walmartlabs.github.io/lumbar) provides easy module-based template management for + handlebars projects. * [sammy.js](http://github.com/quirkey/sammy) by Aaron Quint, a.k.a. quirkey, supports Handlebars.js as one of its template plugins. * [SproutCore](http://www.sproutcore.com) uses Handlebars.js as its main templating engine, extending it with automatic data binding support. -* [Ember.js](http://www.emberjs.com) makes Handlebars.js the primary way to - structure your views, also with automatic data binding support. -* Les Hill (@leshill) wrote a Rails Asset Pipeline gem named - [handlebars_assets](http://github.com/leshill/handlebars_assets). -* [Gist about Synchronous and asynchronous loading of external handlebars templates](https://gist.github.com/2287070) -* [Lumbar](walmartlabs.github.io/lumbar) provides easy module-based template management for handlebars projects. * [YUI](http://yuilibrary.com/yui/docs/handlebars/) implements a port of handlebars -* This [jQuery plugin](http://71104.github.io/jquery-handlebars/) allows you to use Handlebars.js with [jQuery](http://jquery.com/). + +External Resources +------------------ + +* [Gist about Synchronous and asynchronous loading of external handlebars templates](https://gist.github.com/2287070) Have a project using Handlebars? Send us a [pull request](https://github.com/wycats/handlebars.js/pull/new/master)! Helping Out ----------- + To build Handlebars.js you'll need a few things installed. * Node.js From 860853ddb4ed4cce3a54bbf070bdfb2e07320633 Mon Sep 17 00:00:00 2001 From: Kevin Decker Date: Wed, 14 Aug 2013 13:11:01 -0400 Subject: [PATCH 07/13] Update external url --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f593a689..781113d0 100644 --- a/README.markdown +++ b/README.markdown @@ -372,7 +372,7 @@ Handlebars in the Wild for anyone who would like to try out Handlebars.js in their browser. * [jQuery plugin](http://71104.github.io/jquery-handlebars/): allows you to use Handlebars.js with [jQuery](http://jquery.com/). -* [Lumbar](walmartlabs.github.io/lumbar) provides easy module-based template management for +* [Lumbar](http://walmartlabs.github.io/lumbar) provides easy module-based template management for handlebars projects. * [sammy.js](http://github.com/quirkey/sammy) by Aaron Quint, a.k.a. quirkey, supports Handlebars.js as one of its template plugins. From db47593e349ca5226b70a61405d6177b63c19119 Mon Sep 17 00:00:00 2001 From: Tuomas Palenius Date: Thu, 15 Aug 2013 06:05:11 +0300 Subject: [PATCH 08/13] Fix #597. If-helper doesn't anymore consider 0 as falsy value. --- lib/handlebars/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index 44a369c5..b8e11eb2 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -137,7 +137,7 @@ Handlebars.registerHelper('if', function(conditional, options) { var type = toString.call(conditional); if(type === functionType) { conditional = conditional.call(this); } - if(!conditional || Handlebars.Utils.isEmpty(conditional)) { + if(Handlebars.Utils.isEmpty(conditional)) { return options.inverse(this); } else { return options.fn(this); From d02c90c0fbc984523a7a8950e15435938979acbe Mon Sep 17 00:00:00 2001 From: Parker Selbert Date: Thu, 23 May 2013 16:18:53 -0500 Subject: [PATCH 09/13] Use the ('' + string) form of string coercion Using string.toString() will throw errors in current versions of Safari (6.0.5 currently) for some values. The error is a particularly cryptic "Type Error: type error", which no indication as to the value that caused the error. By using the '' + string form of coercion the error doesn't seem to occur. Depending on the browser used there is a sizable performance increase in using the concatenation form of coercion. In instances where there is not a performance improvement (i.e. Firefox), the speed difference is entirely negligable. See: http://jsperf.com/convert-to-string-bj/3 --- lib/handlebars/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 1e0e4c90..e104dcf7 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -21,7 +21,7 @@ Handlebars.SafeString = function(string) { this.string = string; }; Handlebars.SafeString.prototype.toString = function() { - return this.string.toString(); + return "" + this.string; }; var escape = { @@ -60,7 +60,7 @@ Handlebars.Utils = { // 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(); + string = "" + string; if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); From 534d0ebcc3c242b539b2c37a54dbae8d81255eca Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 15 Aug 2013 10:29:37 -0500 Subject: [PATCH 10/13] Add test case --- spec/builtins.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/builtins.js b/spec/builtins.js index 4379725b..a29616f9 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -20,6 +20,8 @@ describe('builtin helpers', function() { "if with non-empty array shows the contents"); shouldCompileTo(string, {goodbye: [], world: "world"}, "cruel world!", "if with empty array does not show the contents"); + shouldCompileTo(string, {goodbye: 0, world: "world"}, "GOODBYE cruel world!", + "if with zero does show the contents"); }); it("if with function argument", function() { From 0b92db7b0ccd5c347cfe2f14571f998b84185a2e Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 15 Aug 2013 10:30:15 -0500 Subject: [PATCH 11/13] Rebuild --- dist/handlebars.js | 6 +++--- dist/handlebars.runtime.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/handlebars.js b/dist/handlebars.js index e0a83681..1942eb53 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -160,7 +160,7 @@ Handlebars.registerHelper('if', function(conditional, options) { var type = toString.call(conditional); if(type === functionType) { conditional = conditional.call(this); } - if(!conditional || Handlebars.Utils.isEmpty(conditional)) { + if(Handlebars.Utils.isEmpty(conditional)) { return options.inverse(this); } else { return options.fn(this); @@ -813,7 +813,7 @@ Handlebars.SafeString = function(string) { this.string = string; }; Handlebars.SafeString.prototype.toString = function() { - return this.string.toString(); + return "" + this.string; }; var escape = { @@ -852,7 +852,7 @@ Handlebars.Utils = { // 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(); + string = "" + string; if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); diff --git a/dist/handlebars.runtime.js b/dist/handlebars.runtime.js index fac2cc5a..947b8f07 100644 --- a/dist/handlebars.runtime.js +++ b/dist/handlebars.runtime.js @@ -160,7 +160,7 @@ Handlebars.registerHelper('if', function(conditional, options) { var type = toString.call(conditional); if(type === functionType) { conditional = conditional.call(this); } - if(!conditional || Handlebars.Utils.isEmpty(conditional)) { + if(Handlebars.Utils.isEmpty(conditional)) { return options.inverse(this); } else { return options.fn(this); @@ -202,7 +202,7 @@ Handlebars.SafeString = function(string) { this.string = string; }; Handlebars.SafeString.prototype.toString = function() { - return this.string.toString(); + return "" + this.string; }; var escape = { @@ -241,7 +241,7 @@ Handlebars.Utils = { // 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(); + string = "" + string; if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); From 182ba044bb8ff02b9ad36e533e6d769efabe031d Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 15 Aug 2013 10:33:45 -0500 Subject: [PATCH 12/13] Update release notes --- release-notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release-notes.md b/release-notes.md index d2800f92..e7f5ca0f 100644 --- a/release-notes.md +++ b/release-notes.md @@ -2,6 +2,8 @@ ## Development +- [#602](https://github.com/wycats/handlebars.js/pull/602) - Handle zero uniformly between mustache conditionals and the if helper ([@artiee](https://github.com/artiee)) +- [#535](https://github.com/wycats/handlebars.js/pull/535) - Fix for probably JIT error under Safari. ([@sorentwo](https://github.com/sorentwo)) - [#537](https://github.com/wycats/handlebars.js/issues/537) - Add CommonJS and AMD loader support ([@spikebrehm](https://github.com/spikebrehm)) - [#544](https://github.com/wycats/handlebars.js/issues/544) - Push travis builds to build server ([@fivetanley](https://github.com/fivetanley)) From 87b5d4ee61605b026506e92c9e8873d867c5f150 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 17 Aug 2013 09:21:25 -0500 Subject: [PATCH 13/13] Update npmignore for new files --- .npmignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.npmignore b/.npmignore index 2f42c9f4..a43e7ecf 100644 --- a/.npmignore +++ b/.npmignore @@ -1,9 +1,14 @@ .DS_Store .gitignore .rvmrc +.jshintrc +.travis.yml +.rspec Gemfile Gemfile.lock Rakefile +*.gemspec +*.nuspec bench/* spec/* src/*