From 18a0e89640c514b1b5bdab03880db7711f455179 Mon Sep 17 00:00:00 2001 From: brandonpayton Date: Wed, 19 Oct 2011 21:57:00 -0700 Subject: [PATCH 1/2] Fix for dot notation returning a value of boolean true for kinda_truthy values '0' and 'false'. --- examples/dot_notation.html | 7 ++++++- examples/dot_notation.js | 7 ++++++- examples/dot_notation.txt | 5 +++++ mustache.js | 7 +++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/dot_notation.html b/examples/dot_notation.html index 749ca3d..da1bad7 100644 --- a/examples/dot_notation.html +++ b/examples/dot_notation.html @@ -1,4 +1,9 @@ +

{{name}}

Authors:

Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} {{availability.text}}{{/price.currency}}

-

VAT: {{price.currency.symbol}}{{price.vat}}

\ No newline at end of file +

VAT: {{price.currency.symbol}}{{price.vat}}

+ +

Test truthy false values:

+

Zero: {{truthy.zero}}

+

False: {{truthy.notTrue}}

diff --git a/examples/dot_notation.js b/examples/dot_notation.js index f41fafb..a28f8db 100644 --- a/examples/dot_notation.js +++ b/examples/dot_notation.js @@ -14,5 +14,10 @@ var dot_notation = { availability:{ status: true, text: "In Stock" + }, + // And now, some truthy false values + truthy: { + zero: 0, + notTrue: false } -}; \ No newline at end of file +}; diff --git a/examples/dot_notation.txt b/examples/dot_notation.txt index 770e4ce..d0e4707 100644 --- a/examples/dot_notation.txt +++ b/examples/dot_notation.txt @@ -1,4 +1,9 @@ +

A Book

Authors:

Price: €200 Euro In Stock

VAT: €40

+ +

Test truthy false values:

+

Zero: 0

+

False: false

diff --git a/mustache.js b/mustache.js index 21d5726..4310d70 100644 --- a/mustache.js +++ b/mustache.js @@ -272,7 +272,10 @@ var Mustache = function() { // check for dot notation eg. foo.bar if(name.match(/([a-z_]+)\./ig)){ - value = is_kinda_truthy(this.walk_context(name, context)); + var childValue = this.walk_context(name, context); + if(is_kinda_truthy(childValue)) { + value = childValue; + } } else{ if(is_kinda_truthy(context[name])) { @@ -416,4 +419,4 @@ var Mustache = function() { } } }); -}(); \ No newline at end of file +}(); From 55c434665617461cf369fa1bc47d5ce5b93a6b09 Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Sun, 30 Oct 2011 11:42:15 -0700 Subject: [PATCH 2/2] Add missing comma to dot_notation test's object literal. --- examples/dot_notation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dot_notation.js b/examples/dot_notation.js index 0628b7d..c1295f5 100644 --- a/examples/dot_notation.js +++ b/examples/dot_notation.js @@ -14,7 +14,7 @@ var dot_notation = { availability:{ status: true, text: "In Stock" - } + }, // And now, some truthy false values truthy: { zero: 0,