Permalink
Browse files

Merge pull request #229 from huntie/master

Update behaviour of {{ifNth}} helper to directly use value given, resolves #228
  • Loading branch information...
2 parents 70f0d9f + 9c8ca9b commit c8980ae5c696a44454e23b5225070601f8c9d255 @jonschlinkert jonschlinkert committed on GitHub Jan 8, 2017
Showing with 5 additions and 5 deletions.
  1. +1 −1 lib/comparison.js
  2. +4 −4 test/comparison.js
View
@@ -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);
View
@@ -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: [
@@ -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(''));
});
});

0 comments on commit c8980ae

Please sign in to comment.