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

Remove @if and @idx #110

Merged
merged 2 commits into from
Mar 4, 2015
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
43 changes: 0 additions & 43 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,6 @@ var helpers = {
return chunk;
},

"idx": function(chunk, context, bodies) {
var body = bodies.block;
// Will be removed in 1.6
_deprecated("{@idx}");
if(body) {
return body(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
},

/**
* contextDump helper
* @param key specifies how much to dump.
Expand Down Expand Up @@ -261,37 +249,6 @@ var helpers = {
cond argument should evaluate to a valid javascript expression
**/

"if": function( chunk, context, bodies, params ) {
var body = bodies.block,
skip = bodies['else'],
cond;

if(params && params.cond) {
// Will be removed in 1.6
_deprecated("{@if}");

cond = dust.helpers.tap(params.cond, chunk, context);
// eval expressions with given dust references
if(eval(cond)){
if(body) {
return chunk.render( bodies.block, context );
}
else {
_log("Missing body block in the if helper!");
return chunk;
}
}
if(skip){
return chunk.render( bodies['else'], context );
}
}
// no condition
else {
_log("No condition given in the if helper!");
}
return chunk;
},

/**
* math helper
* @param key is the value to perform math against
Expand Down
73 changes: 0 additions & 73 deletions test/jasmine-test/spec/helpersTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,6 @@
}
]
},
{
name: "if",
tests: [
{
name: "if helper with no body",
source: '{@if cond="{x}<{y}"/}',
context: { x: 2, y: 3 },
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}"}<div> X < Y </div>{/if}',
context: { x: 2, y: 3 },
expected: "<div> X < Y </div>",
message: "should test if helper without else"
},
{
name: "if helper with else block",
source: '{@if cond=" \'{x}\'.length && \'{y}\'.length "}<div> X and Y exists </div>{:else}<div> X and Y does not exists </div>{/if}',
context: {},
expected: "<div> X and Y does not exists </div>",
message: "should test if helper with else block"
},
{
name: "if helper with else using the or condition",
source: '{@if cond=" \'{x}\'.length || \'{y}\'.length "}<div> X or Y exists </div>{:else}<div> X or Y does not exists </div>{/if}',
context: { x: 1},
expected: "<div> X or Y exists </div>",
message: "should test if helper with else using the or condition"
},
{
name: "if helper with else using the and conditon",
source: '{@if cond="( \'{x}\'.length ) && ({x}<3)"}<div> X exists and is 1 </div>{:else}<div> x is not there </div>{/if}',
context: { x : 1},
expected: "<div> X exists and is 1 </div>",
message: "should test if helper with else usingt he and conditon"
},
{
name: "if helper using $idx",
source: '{#list}{@if cond="( {$idx} == 1 )"}<div>{y}</div>{/if}{/list}',
context: { x : 1, list: [ { y: 'foo' }, { y: 'bar'} ]},
expected: "<div>bar</div>",
message: "should test the if helper using $idx"
}
]
},
{
name: "math",
tests: [
Expand Down Expand Up @@ -1488,25 +1434,6 @@
}
]
},
{
name: "idx",
tests: [
{
name: "idx helper with no body",
source: '{#n}{@idx/}{.} {/n}',
context: { n: ["Mick", "Tom", "Bob"] },
expected: "Mick Tom Bob ",
message: "idx helper with no body should not render"
},
{
name: "idx helper within partial included in a array",
source: '{#n}{@idx}{.}>>{/idx}{>hello_there name=. count="30"/}{/n}',
context: { n: ["Mick", "Tom", "Bob"] },
expected: "0>>Hello Mick! You have 30 new messages.1>>Hello Tom! You have 30 new messages.2>>Hello Bob! You have 30 new messages.",
message: "should test idx helper within partial included in a array"
}
]
},
{
name: "sep / first / last",
tests: [
Expand Down