Skip to content

Commit

Permalink
Use the tap method in the select helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jairodemorais committed Jul 2, 2012
1 parent 3147779 commit bee98ff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function isSelect(context) {
function filter(chunk, context, bodies, params, filter) {
var params = params || {},
actual, expected;

if (params.key) {
actual = context.get(params.key);
} else if (isSelect(context)) {
Expand All @@ -29,8 +28,8 @@ function filter(chunk, context, bodies, params, filter) {
} else {
throw "No key specified for filter and no key found in context from select statement";
}

expected = params.value;
expected = helpers.tap(params.value, chunk, context);
if (filter(expected, coerce(actual, params.type, context))) {
if (isSelect(context)) {
context.current().isResolved = true;
Expand Down
38 changes: 38 additions & 0 deletions test/jasmine-test/spec/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,44 @@ var dustExamples = [
expected: "",
message: "Select helper works correctly with no matching conditions"
},
{
name: "select helper: using tap - eq",
source: ['{@select key="y"}',
'{@eq value="{y}"}<div>FOO</div>{/eq}',
'{@eq value="{x}"}<div>BAR</div>{/eq}',
'{/select}'].join("\n"),
context: { y: 'foo', x: 'bar' },
expected: "<div>FOO</div>",
message: "Select helper works correctly using tap for eq"
},
{
name: "select helper: using tap - gte",
source: "{@select key=\"foo\"}{@gte value=\"{x}\"}foobar{/gte}{/select}",
context: {foo : 10 , x : 10},
expected: "foobar",
message: "Select helper works correctly using tap for gte"
},
{
name: "select helper: using tap - lte",
source: "{@select key=\"foo\"}{@lte value=\"{x}\"}foobar{/lte}{/select}",
context: {foo : 10 , x : 10},
expected: "foobar",
message: "Select helper works correctly using tap for lte"
},
{
name: "select helper: using tap - gt",
source: "{@select key=\"foo\"}{@gt value=\"{x}\"}foobar{/gt}{/select}",
context: {foo : 10 , x : 5},
expected: "foobar",
message: "Select helper works correctly using tap for gt"
},
{
name: "select helper: using tap - lt",
source: "{@select key=\"foo\"}{@lt value=\"{x}\"}foobar{/lt}{/select}",
context: {foo : 10 , x : 15},
expected: "foobar",
message: "Select helper works correctly using tap for lt"
},
{
name: "ws updated to allow eol",
source: ['{#authors ',
Expand Down

0 comments on commit bee98ff

Please sign in to comment.