Parcourir la source

Merge pull request #134 from brandonpayton/master

Dot notation support renders 0 and boolean false values as "true"
tags/0.4.0
Jan Lehnardt il y a 14 ans
Parent
révision
2ead28a60e
4 fichiers modifiés avec 20 ajouts et 2 suppressions
  1. +6
    -1
      examples/dot_notation.html
  2. +5
    -0
      examples/dot_notation.js
  3. +5
    -0
      examples/dot_notation.txt
  4. +4
    -1
      mustache.js

+ 6
- 1
examples/dot_notation.html Voir le fichier

@@ -1,4 +1,9 @@
<!-- exciting part -->
<h1>{{name}}</h1>
<p>Authors: <ul>{{#authors}}<li>{{.}}</li>{{/authors}}</ul></p>
<p>Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p>
<p>VAT: {{price.currency.symbol}}{{price.vat}}</p>
<p>VAT: {{price.currency.symbol}}{{price.vat}}</p>
<!-- boring part -->
<h2>Test truthy false values:</h2>
<p>Zero: {{truthy.zero}}</p>
<p>False: {{truthy.notTrue}}</p>

+ 5
- 0
examples/dot_notation.js Voir le fichier

@@ -14,5 +14,10 @@ var dot_notation = {
availability:{
status: true,
text: "In Stock"
},
// And now, some truthy false values
truthy: {
zero: 0,
notTrue: false
}
};

+ 5
- 0
examples/dot_notation.txt Voir le fichier

@@ -1,4 +1,9 @@
<!-- exciting part -->
<h1>A Book</h1>
<p>Authors: <ul><li>John Power</li><li>Jamie Walsh</li></ul></p>
<p>Price: &euro;200 Euro <b>In Stock</b></p>
<p>VAT: &euro;40</p>
<!-- boring part -->
<h2>Test truthy false values:</h2>
<p>Zero: 0</p>
<p>False: false</p>

+ 4
- 1
mustache.js Voir le fichier

@@ -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])) {


Chargement…
Annuler
Enregistrer