2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Add replacement for zero in plural helper

- currently, the plural helper doesn't replace % with the number when the number is zero, which is inconsistent
- this change ensures that theme developers can choose to show the number or a plain string
This commit is contained in:
Hannah Wolfe 2015-09-22 16:00:20 +01:00
parent ed7bfe8f4a
commit d1c7ec0799
2 changed files with 15 additions and 1 deletions

View file

@ -20,7 +20,7 @@ plural = function (context, options) {
}
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) {
return new hbs.handlebars.SafeString(options.hash.singular.replace('%', context));
} else if (context >= 2) {

View file

@ -31,6 +31,20 @@ describe('{{plural}} helper', function () {
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 () {
var expected = '1 Post',
rendered = helpers.plural.call({}, 1, {