Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison helpers should still execute when their key parameter is set ... #105

Merged
merged 2 commits into from
Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ function filter(chunk, context, bodies, params, filterOp) {
actualKey,
expectedValue,
filterOpType = params.filterOpType || '';

// when @eq, @lt etc are used as standalone helpers, key is required and hence check for defined
if ( typeof params.key !== "undefined") {
if (params.hasOwnProperty("key")) {
actualKey = dust.helpers.tap(params.key, chunk, context);
}
else if (isSelect(context)) {
} else if (isSelect(context)) {
actualKey = context.current().selectKey;
// supports only one of the blocks in the select to be selected
if (context.current().isResolved) {
filterOp = function() { return false; };
}
}
else {
} else {
_log("No key specified for filter in:" + filterOpType + " helper ");
return chunk;
}
Expand All @@ -57,19 +56,17 @@ function filter(chunk, context, bodies, params, filterOp) {
// we want helpers without bodies to fail gracefully so check it first
if(body) {
return chunk.render(body, context);
}
else {
_log("No key specified for filter in:" + filterOpType + " helper ");
} else {
_log("No body specified for " + filterOpType + " helper ");
return chunk;
}
}
else if (bodies['else']) {
} else if (bodies['else']) {
return chunk.render(bodies['else'], context);
}
return chunk;
}

function coerce (value, type, context) {
function coerce(value, type, context) {
if (typeof value !== "undefined") {
switch (type || typeof value) {
case 'number': return +value;
Expand Down
16 changes: 15 additions & 1 deletion test/jasmine-test/spec/helpersTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,25 @@
},
{
name: "eq helper with no params",
source: "{@eq}Hello{/eq}",
source: "{@eq}Hello{:else}Goodbye{/eq}",
context: {},
expected: "",
message: "eq helper with no params does not execute"
},
{
name: "eq helper with key that resolves to undefined",
source: "{@eq key=foo value=\"0\"}Hello{:else}Goodbye{/eq}",
context: {},
expected: "Goodbye",
message: "eq helper with key that resolves to undefined uses that as comparison"
},
{
name: "eq helper with both key and value undefined",
source: "{@eq key=foo value=bar}Hello{:else}Goodbye{/eq}",
context: {},
expected: "Hello",
message: "eq helper with key and value that both resolve to undefined is true"
},
{
name: "eq helper matching string case",
source: "{@eq key=\"foo\" value=\"foo\"}equal{/eq}",
Expand Down