diff --git a/.travis.yml b/.travis.yml index e9eb249..901ac78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,12 @@ matrix: env: TEST="all" notifications: email: - - jdemorais@linkedin.com - - vbasavaraj@linkedin.com - jleppert@linkedin.com + - jchan@linkedin.com + - skinast@linkedin.com before_install: + - npm install -g npm@1.4 + - npm --version - npm install -g grunt-cli - - npm install -g npm script: - "[ $TEST = 'all' ] && grunt test || grunt testNode" \ No newline at end of file diff --git a/lib/dust-helpers.js b/lib/dust-helpers.js index a4387b3..6f99aad 100644 --- a/lib/dust-helpers.js +++ b/lib/dust-helpers.js @@ -94,16 +94,16 @@ var helpers = { Reference resolution rules: if value exists in JSON: "" or '' will evaluate to false, boolean false, null, or undefined will evaluate to false, - numeric 0 evaluates to true, so does, string "0", string "null", string "undefined" and string "false". + numeric 0 evaluates to true, so does, string "0", string "null", string "undefined" and string "false". Also note that empty array -> [] is evaluated to false and empty object -> {} and non-empty object are evaluated to true - The type of the return value is string ( since we concatenate to support interpolated references + The type of the return value is string ( since we concatenate to support interpolated references if value does not exist in JSON and the input is a single reference: {x} - dust render emits empty string, and we then return false - + dust render emits empty string, and we then return false + if values does not exist in JSON and the input is interpolated references : {x} < {y} - dust render emits < and we return the partial output - + dust render emits < and we return the partial output + */ "tap": function(input, chunk, context) { // return given input if there is no dust reference to resolve @@ -359,8 +359,9 @@ var helpers = { "eq": function(chunk, context, bodies, params) { if(params) { params.filterOpType = "eq"; + return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); } - return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); + return chunk; }, /** @@ -379,7 +380,7 @@ var helpers = { params.filterOpType = "ne"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual !== expected; }); } - return chunk; + return chunk; }, /** @@ -394,10 +395,11 @@ var helpers = { Note : use type="number" when comparing numeric **/ "lt": function(chunk, context, bodies, params) { - if(params) { - params.filterOpType = "lt"; - return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); - } + if(params) { + params.filterOpType = "lt"; + return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); + } + return chunk; }, /** @@ -412,10 +414,10 @@ var helpers = { Note : use type="number" when comparing numeric **/ "lte": function(chunk, context, bodies, params) { - if(params) { - params.filterOpType = "lte"; - return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); - } + if(params) { + params.filterOpType = "lte"; + return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); + } return chunk; }, @@ -456,7 +458,7 @@ var helpers = { params.filterOpType = "gte"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; }); } - return chunk; + return chunk; }, // to be used in conjunction with the select helper @@ -502,8 +504,8 @@ var helpers = { } return chunk.write(value); } - - + + }; for (var key in helpers) { @@ -514,4 +516,4 @@ var helpers = { module.exports = dust; } -})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust); \ No newline at end of file +})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust); diff --git a/test/jasmine-test/spec/helpersTests.js b/test/jasmine-test/spec/helpersTests.js index 3cd3340..8b0531b 100644 --- a/test/jasmine-test/spec/helpersTests.js +++ b/test/jasmine-test/spec/helpersTests.js @@ -23,6 +23,13 @@ expected: "", message: "should test if helper with no body and fail gracefully" }, + { + name: "if helper with no condition", + source: '{@if}Hello{/if}', + context: { x: 2, y: 3 }, + expected: "", + message: "should test if helper with no condition fails gracefully" + }, { name: "if helper without else", source: '{@if cond="{x}<{y}"}