mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #1239 from cobbspur/tagsprefix
adds prefix option to tag helper
This commit is contained in:
commit
80bbcf7205
2 changed files with 40 additions and 4 deletions
|
@ -120,14 +120,27 @@ coreHelpers = function (ghost) {
|
||||||
// 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 = ', ',
|
||||||
|
prefix,
|
||||||
|
output,
|
||||||
tagNames;
|
tagNames;
|
||||||
|
|
||||||
if (_.isString(options.hash.separator)) {
|
if (_.isString(options.hash.separator)) {
|
||||||
separator = options.hash.separator;
|
separator = options.hash.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_.isString(options.hash.prefix)) {
|
||||||
|
prefix = options.hash.prefix;
|
||||||
|
}
|
||||||
|
|
||||||
tagNames = _.pluck(this.tags, 'name');
|
tagNames = _.pluck(this.tags, 'name');
|
||||||
return tagNames.join(separator);
|
|
||||||
|
if (tagNames.length && prefix) {
|
||||||
|
output = prefix + tagNames.join(separator);
|
||||||
|
} else {
|
||||||
|
output = tagNames.join(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
});
|
});
|
||||||
|
|
||||||
// ### Content Helper
|
// ### Content Helper
|
||||||
|
|
|
@ -399,7 +399,7 @@ describe('Core Helpers', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can return string with tags', function () {
|
it('can return string with tags', function () {
|
||||||
var tags = [{name:'foo'}, {name:'bar'}],
|
var tags = [{name: 'foo'}, {name: 'bar'}],
|
||||||
rendered = handlebars.helpers.tags.call(
|
rendered = handlebars.helpers.tags.call(
|
||||||
{tags: tags},
|
{tags: tags},
|
||||||
{"hash": {}}
|
{"hash": {}}
|
||||||
|
@ -410,7 +410,7 @@ describe('Core Helpers', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use a different separator', function () {
|
it('can use a different separator', function () {
|
||||||
var tags = [{name:'haunted'},{name:'ghost'}],
|
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||||
rendered = handlebars.helpers.tags.call(
|
rendered = handlebars.helpers.tags.call(
|
||||||
{tags: tags},
|
{tags: tags},
|
||||||
{"hash": {separator: '|'}}
|
{"hash": {separator: '|'}}
|
||||||
|
@ -420,6 +420,29 @@ describe('Core Helpers', function () {
|
||||||
|
|
||||||
String(rendered).should.equal('haunted|ghost');
|
String(rendered).should.equal('haunted|ghost');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can add a single prefix to multiple tags', function () {
|
||||||
|
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||||
|
rendered = handlebars.helpers.tags.call(
|
||||||
|
{tags: tags},
|
||||||
|
{"hash": {prefix: 'on '}}
|
||||||
|
);
|
||||||
|
|
||||||
|
should.exist(rendered);
|
||||||
|
|
||||||
|
String(rendered).should.equal('on haunted, ghost');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not add prefix if no tags exist', function () {
|
||||||
|
var rendered = handlebars.helpers.tags.call(
|
||||||
|
{},
|
||||||
|
{"hash": {prefix: 'on '}}
|
||||||
|
);
|
||||||
|
|
||||||
|
should.exist(rendered);
|
||||||
|
|
||||||
|
String(rendered).should.equal('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("meta_title helper", function () {
|
describe("meta_title helper", function () {
|
||||||
|
|
Loading…
Reference in a new issue