Skip to content

Commit 2ead28a

Browse files
committed
Merge pull request janl#134 from brandonpayton/master
Dot notation support renders 0 and boolean false values as "true"
2 parents e2e29b2 + 55c4346 commit 2ead28a

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

examples/dot_notation.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
<!-- exciting part -->
12
<h1>{{name}}</h1>
23
<p>Authors: <ul>{{#authors}}<li>{{.}}</li>{{/authors}}</ul></p>
34
<p>Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p>
4-
<p>VAT: {{price.currency.symbol}}{{price.vat}}</p>
5+
<p>VAT: {{price.currency.symbol}}{{price.vat}}</p>
6+
<!-- boring part -->
7+
<h2>Test truthy false values:</h2>
8+
<p>Zero: {{truthy.zero}}</p>
9+
<p>False: {{truthy.notTrue}}</p>

examples/dot_notation.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ var dot_notation = {
1414
availability:{
1515
status: true,
1616
text: "In Stock"
17+
},
18+
// And now, some truthy false values
19+
truthy: {
20+
zero: 0,
21+
notTrue: false
1722
}
1823
};

examples/dot_notation.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
<!-- exciting part -->
12
<h1>A Book</h1>
23
<p>Authors: <ul><li>John Power</li><li>Jamie Walsh</li></ul></p>
34
<p>Price: &euro;200 Euro <b>In Stock</b></p>
45
<p>VAT: &euro;40</p>
6+
<!-- boring part -->
7+
<h2>Test truthy false values:</h2>
8+
<p>Zero: 0</p>
9+
<p>False: false</p>

mustache.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ var Mustache = function() {
272272

273273
// check for dot notation eg. foo.bar
274274
if(name.match(/([a-z_]+)\./ig)){
275-
value = is_kinda_truthy(this.walk_context(name, context));
275+
var childValue = this.walk_context(name, context);
276+
if(is_kinda_truthy(childValue)) {
277+
value = childValue;
278+
}
276279
}
277280
else{
278281
if(is_kinda_truthy(context[name])) {

0 commit comments

Comments
 (0)