mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
added suffix to tag helper
closes #607 - added suffix as optional parameter to tag helper
This commit is contained in:
parent
46dc171362
commit
d605100709
2 changed files with 33 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -433,10 +433,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);
|
||||
|
|
Loading…
Add table
Reference in a new issue