Skip to content

Commit

Permalink
remove if and idx helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyhchan committed Jan 15, 2015
1 parent eb10839 commit ec13559
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 116 deletions.
43 changes: 0 additions & 43 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ var helpers = {
}
},

"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 @@ -239,37 +227,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 @@ -1430,25 +1376,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",
tests: [
Expand Down

0 comments on commit ec13559

Please sign in to comment.