Skip to content

Commit

Permalink
Merge pull request #229 from huntie/master
Browse files Browse the repository at this point in the history
Update behaviour of {{ifNth}} helper to directly use value given, resolves #228
  • Loading branch information
jonschlinkert committed Jan 8, 2017
2 parents 70f0d9f + 9c8ca9b commit c8980ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/comparison.js
Expand Up @@ -277,7 +277,7 @@ helpers.ifEven = function(num, options) {
*/

helpers.ifNth = function(a, b, options) {
if (++b % a === 0) {
if (utils.isNumber(a) && utils.isNumber(b) && b % a === 0) {
return options.fn(this);
}
return options.inverse(this);
Expand Down
8 changes: 4 additions & 4 deletions test/comparison.js
Expand Up @@ -307,7 +307,7 @@ describe('comparison', function() {

describe('ifNth', function() {
it('should render a custom class on even rows', function() {
var source = '{{#each items}}<div {{#ifNth "2" @index}}class="row-alternate"{{/ifNth}}>{{name}}</div>{{/each}}';
var source = '{{#each items}}<div{{#ifNth 2 @index}}{{else}} class="row-alternate"{{/ifNth}}>{{name}}</div>{{/each}}';
var fn = hbs.compile(source);
var context = {
items: [
Expand All @@ -319,11 +319,11 @@ describe('comparison', function() {
]
};
assert(fn(context), [
'<div >Philip J. Fry</div>',
'<div>Philip J. Fry</div>',
'<div class="row-alternate">Turanga Leela</div>',
'<div >Bender Bending Rodriguez</div>',
'<div>Bender Bending Rodriguez</div>',
'<div class="row-alternate">Amy Wong</div>',
'<div >Hermes Conrad</div>'
'<div>Hermes Conrad</div>'
].join(''));
});
});
Expand Down

0 comments on commit c8980ae

Please sign in to comment.