Permalink
Browse files

Remove some logs, bump version

  • Loading branch information...
1 parent fe212eb commit 38e22f4c86c49ce15efd29bdc916dcb68a7d0b12 @chbrown committed Jan 29, 2013
Showing with 10 additions and 14 deletions.
  1. +9 −13 lib/rendering.js
  2. +1 −1 package.json
View
@@ -60,16 +60,14 @@ function escapeHtml(s) {
});
}
-function stringEval(context, expression) {
+function dottedEval(context, expression) {
// handles strings that occur in context or dotted paths that traverse a context object
if (expression == '.') return context['.']; // for those embedded sections (silly Mu spec, should be _)
var parts = expression.split('.');
for (var i = 0, part; (part = parts[i]) !== undefined; i++) {
- var context = context[part];
- if (context === undefined || context === null) {
- return undefined;
- }
+ context = context[part];
+ if (context === undefined || context === null) break;
}
return context;
}
@@ -79,9 +77,9 @@ function expressionEval(context, expression) {
var m;
if (m = expression.match(/^(\S+)\s*([!=<>]+)\s*(\S+)$/)) {
// booleans: ==, ===, !=, !==, <, <=, >, >=
- var left = stringEval(context, m[1]);
+ var left = dottedEval(context, m[1]);
var op = m[2];
- var right = stringEval(context, m[3]);
+ var right = dottedEval(context, m[3]);
if (op === '==') return left == right;
else if (op === '===') return left === right;
else if (op === '!=') return left != right;
@@ -102,12 +100,10 @@ function expressionEval(context, expression) {
// var argument_part = new_node.val.substring(open_parens_index + 1, close_parens_index);
// trim whitespace/quotes since arguments can only be strings or ints anyway. At least, for now.
// (todo: let them embed commas in strings)
- console.log('\nm:', m[1], '(', m[2], ')', context);
- var func = stringEval(context, m[1]) || eval(m[1]);
- console.log('func:', func);
+ // console.log('\nm:', m[1], '(', m[2], ')', context);
+ var func = dottedEval(context, m[1]) || eval(m[1]);
var args = m[2].split(',').map(function(raw) {
var val = raw.replace(/^\s+|\s+$/g, '');
- console.log('arg:', val);
if (val.match(/^('|").*\1$/)) { // string literal
val = val.slice(1, -1);
}
@@ -118,15 +114,15 @@ function expressionEval(context, expression) {
val = parseFloat(val);
}
else if (val.match(/^\w+$/)) { // variable reference
- val = stringEval(context, val);
+ val = dottedEval(context, val);
}
return val;
});
return func.apply(null, args);
}
else {
- return stringEval(context, expression);
+ return dottedEval(context, expression);
}
}
View
@@ -1,6 +1,6 @@
{
"name": "amulet",
- "version": "0.2.5",
+ "version": "0.2.6",
"description": "As-soon-as-possible streaming async Mustache templating",
"keywords": ["template", "mustache", "mu", "asynchronous", "streaming", "nodeps"],
"homepage": "http://github.com/chbrown/amulet",

0 comments on commit 38e22f4

Please sign in to comment.