« index
Coverage for /Users/jdemorai/projects/dust-Linkedin/dustjs/lib/dust-helpers.js : 90%
51 lines |
46 run |
5 missing |
1 partial |
13 blocks |
9 blocks run |
4 blocks missing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | (function(dust){ var helpers = { sep: function(chunk, context, bodies) { if (context.stack.index === context.stack.of - 1) { return chunk; } return bodies.block(chunk, context); }, 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 ){ // resolve dust references in the expression if( typeof cond === "function" ){ cond = ''; chunk.tap( function( data ){ cond += data; return ''; } ).render( params.cond, context ).untap(); if( cond === '' ){ cond = false; } } // 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 ){ window.console.log( "No expression given!" ); } } return chunk; } }; dust.helpers = helpers; })(typeof exports !== 'undefined' ? exports : window.dust); |