diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index 7ee6b4615d..7a70ba228e 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -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; diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index 59115b8b2c..502f6b5a92 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -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);