Merge pull request #5859 from ErisDS/plural

Add replacement for zero in plural helper
This commit is contained in:
Sebastian Gierlinger 2015-09-23 18:42:01 +02:00
commit 48919a96c0
2 changed files with 15 additions and 1 deletions

View File

@ -20,7 +20,7 @@ plural = function (context, options) {
} }
if (context === 0) { if (context === 0) {
return new hbs.handlebars.SafeString(options.hash.empty); return new hbs.handlebars.SafeString(options.hash.empty.replace('%', context));
} else if (context === 1) { } else if (context === 1) {
return new hbs.handlebars.SafeString(options.hash.singular.replace('%', context)); return new hbs.handlebars.SafeString(options.hash.singular.replace('%', context));
} else if (context >= 2) { } else if (context >= 2) {

View File

@ -31,6 +31,20 @@ describe('{{plural}} helper', function () {
rendered.string.should.equal(expected); rendered.string.should.equal(expected);
}); });
it('will show no-value string with placement', function () {
var expected = '0 Posts',
rendered = helpers.plural.call({}, 0, {
hash: {
empty: '% Posts',
singular: '% Post',
plural: '% Posts'
}
});
should.exist(rendered);
rendered.string.should.equal(expected);
});
it('will show singular string', function () { it('will show singular string', function () {
var expected = '1 Post', var expected = '1 Post',
rendered = helpers.plural.call({}, 1, { rendered = helpers.plural.call({}, 1, {