Skip to content

Commit

Permalink
preventing dust to crash on non existant condition or when running in…
Browse files Browse the repository at this point in the history
… node environment
  • Loading branch information
seriousManual committed Jun 5, 2012
1 parent c034210 commit 1ed45cb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/dust-helpers.js
Expand Up @@ -3,7 +3,7 @@
function isSelect(context) {
var value = context.current();
return typeof value === "object" && value.isSelect === true;
};
}

function filter(chunk, context, bodies, params, filter) {
var params = params || {},
Expand Down Expand Up @@ -31,7 +31,7 @@ function filter(chunk, context, bodies, params, filter) {
}

return chunk.write('');
};
}

function coerce (value, type, context) {
if (value) {
Expand All @@ -45,7 +45,7 @@ function coerce (value, type, context) {
}

return value;
};
}

var helpers = {

Expand All @@ -59,11 +59,11 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},

"if": function( chunk, context, bodies, params ){
var cond = ( params.cond );

if( params && params.cond ){
var cond = params.cond;

// resolve dust references in the expression
if( typeof cond === "function" ){
cond = '';
Expand All @@ -78,14 +78,14 @@ var helpers = {
// eval expressions with no dust references
if( eval( cond ) ){
return chunk.render( bodies.block, context );
}
}
if( bodies['else'] ){
return chunk.render( bodies['else'], context );
}
}
}
// no condition
else {
if( window.console ){
if( typeof window !== 'undefined' && window.console ){
window.console.log( "No expression given!" );
}
}
Expand Down

0 comments on commit 1ed45cb

Please sign in to comment.