Skip to content

Commit

Permalink
Evaluate truth test bodies inside a @select before resolving the select.
Browse files Browse the repository at this point in the history
Fixes #134
  • Loading branch information
Seth Kinast committed Apr 27, 2015
1 parent fdf8392 commit 9167dfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ function filter(chunk, context, bodies, params, helperName, test) {
value = coerce(context.resolve(params.value), type);

if (test(key, value)) {
if(body) {
chunk = chunk.render(body, context);
}
if (selectState) {
selectState.isResolved = true;
}
if(body) {
return chunk.render(body, context);
}
} else if (skip) {
return chunk.render(skip, context);
chunk = chunk.render(skip, context);
}
return chunk;
}
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine-test/spec/helpersTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,27 @@
},
expected: "done done outside default default outside",
message: "should test select helper with params in an outer section"
},
{
name: "select with nested @eq",
source: ['{@select key=selectKey}',
'{@eq value=1}One',
'{@eq key=test value=5}Correct!{/eq}',
'{@select}',
'{@eq key=test value=5}InnerCorrect!{/eq}',
'{@eq key=test value=5}Bug! True, but inner select is resolved.{/eq}',
'{/select}',
'{/eq}',
'{@eq value=1}Bug! True, but select is resolved.{:else}Bug! Not false{/eq}',
'{@eq key=key value=2}Bug! True, but select is resolved.{:else}Bug! Not false{/eq}',
'{/select}'].join(''),
context: {
selectKey: 1,
test: 5,
key: 2
},
expected: "OneCorrect!InnerCorrect!",
message: "Truth tests should only be skipped at the top level of a select"
}
]
},
Expand Down

0 comments on commit 9167dfd

Please sign in to comment.