Просмотр исходного кода

Merge https://github.com/janl/mustache.js

Conflicts:
	examples/dot_notation.js
	mustache.js
tags/0.4.0
Brandon Payton 14 лет назад
Родитель
Сommit
1d59e5c746
2 измененных файлов: 45 добавлений и 45 удалений
  1. +21
    -21
      examples/dot_notation.js
  2. +24
    -24
      mustache.js

+ 21
- 21
examples/dot_notation.js Просмотреть файл

@@ -1,23 +1,23 @@
var dot_notation = { var dot_notation = {
name: "A Book",
authors: ["John Power", "Jamie Walsh"],
price:{
value: 200,
vat: function() {
return this.value * 0.2;
},
currency: {
symbol: '€',
name: 'Euro'
}
},
availability:{
status: true,
text: "In Stock"
},
// And now, some truthy false values
truthy: {
zero: 0,
notTrue: false
}
name: "A Book",
authors: ["John Power", "Jamie Walsh"],
price:{
value: 200,
vat: function() {
return this.value * 0.2;
},
currency: {
symbol: '€',
name: 'Euro'
}
},
availability:{
status: true,
text: "In Stock"
}
// And now, some truthy false values
truthy: {
zero: 0,
notTrue: false
}
}; };

+ 24
- 24
mustache.js Просмотреть файл

@@ -269,21 +269,21 @@ var Mustache = function() {
} }


var value; var value;
// check for dot notation eg. foo.bar
if(name.match(/([a-z_]+)\./ig)){
// check for dot notation eg. foo.bar
if(name.match(/([a-z_]+)\./ig)){
var childValue = this.walk_context(name, context); var childValue = this.walk_context(name, context);
if(is_kinda_truthy(childValue)) { if(is_kinda_truthy(childValue)) {
value = childValue; value = childValue;
} }
}
else{
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
}
}
else{
if(is_kinda_truthy(context[name])) {
value = context[name];
} else if(is_kinda_truthy(this.context[name])) {
value = this.context[name];
}
}


if(typeof value === "function") { if(typeof value === "function") {
return value.apply(context); return value.apply(context);
@@ -295,21 +295,21 @@ var Mustache = function() {
return ""; return "";
}, },


walk_context: function(name, context){
var path = name.split('.');
// if the var doesn't exist in current context, check the top level context
var value_context = (context[path[0]] != undefined) ? context : this.context;
var value = value_context[path.shift()];
while(value != undefined && path.length > 0){
value_context = value;
value = value[path.shift()];
}
// if the value is a function, call it, binding the correct context
if(typeof value === "function") {
walk_context: function(name, context){
var path = name.split('.');
// if the var doesn't exist in current context, check the top level context
var value_context = (context[path[0]] != undefined) ? context : this.context;
var value = value_context[path.shift()];
while(value != undefined && path.length > 0){
value_context = value;
value = value[path.shift()];
}
// if the value is a function, call it, binding the correct context
if(typeof value === "function") {
return value.apply(value_context); return value.apply(value_context);
} }
return value;
},
return value;
},


// Utility methods // Utility methods




Загрузка…
Отмена
Сохранить