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:
commit
68f78c9cc4
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
|
// Note that the standard {{#each tags}} implementation is unaffected by this helper
|
||||||
// and can be used for more complex templates.
|
// and can be used for more complex templates.
|
||||||
ghost.registerThemeHelper('tags', function (options) {
|
ghost.registerThemeHelper('tags', function (options) {
|
||||||
var separator = ', ',
|
var separator = _.isString(options.hash.separator) ? options.hash.separator : ', ',
|
||||||
prefix,
|
prefix = _.isString(options.hash.prefix) ? options.hash.prefix : '',
|
||||||
output,
|
suffix = _.isString(options.hash.suffix) ? options.hash.suffix : '',
|
||||||
tagNames;
|
output = '',
|
||||||
|
tagNames = _.pluck(this.tags, 'name');
|
||||||
|
|
||||||
if (_.isString(options.hash.separator)) {
|
if (tagNames.length) {
|
||||||
separator = options.hash.separator;
|
output = prefix + tagNames.join(separator) + suffix;
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
|
@ -443,10 +443,34 @@ describe('Core Helpers', function () {
|
||||||
String(rendered).should.equal('on haunted, ghost');
|
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(
|
var rendered = handlebars.helpers.tags.call(
|
||||||
{},
|
{},
|
||||||
{"hash": {prefix: 'on '}}
|
{"hash": {prefix: 'on ', suffix: ' forever'}}
|
||||||
);
|
);
|
||||||
|
|
||||||
should.exist(rendered);
|
should.exist(rendered);
|
||||||
|
|
Loading…
Add table
Reference in a new issue