0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Merge pull request #1315 from cobbspur/suffix

added suffix to tag helper
This commit is contained in:
Hannah Wolfe 2013-10-28 15:24:11 -07:00
commit 68f78c9cc4
2 changed files with 33 additions and 20 deletions

View file

@ -119,25 +119,14 @@ coreHelpers = function (ghost) {
// Note that the standard {{#each tags}} implementation is unaffected by this helper
// and can be used for more complex templates.
ghost.registerThemeHelper('tags', function (options) {
var separator = ', ',
prefix,
output,
tagNames;
var separator = _.isString(options.hash.separator) ? options.hash.separator : ', ',
prefix = _.isString(options.hash.prefix) ? options.hash.prefix : '',
suffix = _.isString(options.hash.suffix) ? options.hash.suffix : '',
output = '',
tagNames = _.pluck(this.tags, 'name');
if (_.isString(options.hash.separator)) {
separator = options.hash.separator;
}
if (_.isString(options.hash.prefix)) {
prefix = options.hash.prefix;
}
tagNames = _.pluck(this.tags, 'name');
if (tagNames.length && prefix) {
output = prefix + tagNames.join(separator);
} else {
output = tagNames.join(separator);
if (tagNames.length) {
output = prefix + tagNames.join(separator) + suffix;
}
return output;

View file

@ -443,10 +443,34 @@ describe('Core Helpers', function () {
String(rendered).should.equal('on haunted, ghost');
});
it('does not add prefix if no tags exist', function () {
it('can add a single suffix to multiple tags', function () {
var tags = [{name: 'haunted'}, {name: 'ghost'}],
rendered = handlebars.helpers.tags.call(
{tags: tags},
{"hash": {suffix: ' forever'}}
);
should.exist(rendered);
String(rendered).should.equal('haunted, ghost forever');
});
it('can add a prefix and suffix to multiple tags', function () {
var tags = [{name: 'haunted'}, {name: 'ghost'}],
rendered = handlebars.helpers.tags.call(
{tags: tags},
{"hash": {suffix: ' forever', prefix: 'on '}}
);
should.exist(rendered);
String(rendered).should.equal('on haunted, ghost forever');
});
it('does not add prefix or suffix if no tags exist', function () {
var rendered = handlebars.helpers.tags.call(
{},
{"hash": {prefix: 'on '}}
{"hash": {prefix: 'on ', suffix: ' forever'}}
);
should.exist(rendered);