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

add optional 'start' param to '{@idx}' #80

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 8 additions & 2 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,16 @@ var helpers = {
}
},

"idx": function(chunk, context, bodies) {
"idx": function(chunk, context, bodies, params) {
var start = 0;

if (params) {
start = +dust.helpers.tap(params.start, chunk, context) || start;
}

var body = bodies.block;
if(body) {
return bodies.block(chunk, context.push(context.stack.index));
return bodies.block(chunk, context.push(context.stack.index + start));
}
else {
return chunk;
Expand Down
14 changes: 14 additions & 0 deletions test/jasmine-test/spec/helpersTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,20 @@ var helpersTests = [
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: "idx helper within partial included in a array (start param (=0) given)",
source: '{#n}{@idx start="0"}{.}>>{/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: "idx helper within partial included in a array (start param (=5) given)",
source: '{#n}{@idx start="5"}{.}>>{/idx}{>hello_there name=. count="30"/}{/n}',
context: { n: ["Mick", "Tom", "Bob"] },
expected: "5>>Hello Mick! You have 30 new messages.6>>Hello Tom! You have 30 new messages.7>>Hello Bob! You have 30 new messages.",
message: "should test idx helper within partial included in a array"
}
]
},
Expand Down