Skip to content
Browse files

Merge remote-tracking branch 'pepve/dot-notation'

  • Loading branch information...
2 parents f239c9c + dd3329f commit 8ed421c5cd85956030a2d58ee01ddcfa33892ddb @raycmorgan committed Jun 3, 2012
View
16 lib/mu/renderer.js
@@ -107,10 +107,22 @@ function normalize(context, name, body) {
function walkToFind(context, name) {
var i = context.length;
+ var names = name.split('.');
+ var current;
+
+ walk:
while (i--) {
- if (name in context[i]) {
- return context[i][name];
+ current = context[i];
+
+ for (var j = 0; j < names.length; j++) {
+ if (names[j] in current) {
+ current = current[names[j]];
+ } else {
+ continue walk;
+ }
}
+
+ return current;
}
return undefined;
View
5 test/examples/dot_notation.html
@@ -0,0 +1,5 @@
+Hello {{person.name}}
+You have just won ${{price.value}}!
+{{#person.in_ca}}
+Well, ${{ states.ca.taxed_value }}, after taxes.
+{{/person.in_ca}}
View
16 test/examples/dot_notation.js
@@ -0,0 +1,16 @@
+{
+ person: {
+ name: "Chris",
+ in_ca: true
+ },
+ price: {
+ value: 10000
+ },
+ states: {
+ ca: {
+ taxed_value: function () {
+ return this.price.value - (this.price.value * 0.4);
+ }
+ }
+ }
+}
View
5 test/examples/dot_notation.txt
@@ -0,0 +1,5 @@
+Hello Chris
+You have just won $10000!
+
+Well, $6000, after taxes.
+
View
1 test/run_examples_test.js
@@ -20,6 +20,7 @@ mu.root = path.join(__dirname, 'examples');
'recursion_with_same_names',
'reuse_of_enumerables',
'simple',
+ 'dot_notation',
'twice',
'two_in_a_row',
'unescaped'

0 comments on commit 8ed421c

Please sign in to comment.
Something went wrong with that request. Please try again.