mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Merge pull request #3445 from ErisDS/issue-3389
Adding new {{title}} helper
This commit is contained in:
commit
bdb75c8f07
@ -298,6 +298,10 @@ coreHelpers.content = function (options) {
|
||||
return new hbs.handlebars.SafeString(this.html);
|
||||
};
|
||||
|
||||
coreHelpers.title = function () {
|
||||
return new hbs.handlebars.SafeString(hbs.handlebars.Utils.escapeExpression(this.title || ''));
|
||||
};
|
||||
|
||||
// ### Excerpt Helper
|
||||
//
|
||||
// *Usage example:*
|
||||
@ -787,6 +791,8 @@ registerHelpers = function (adminHbs, assetHash) {
|
||||
|
||||
registerThemeHelper('content', coreHelpers.content);
|
||||
|
||||
registerThemeHelper('title', coreHelpers.title);
|
||||
|
||||
registerThemeHelper('date', coreHelpers.date);
|
||||
|
||||
registerThemeHelper('encode', coreHelpers.encode);
|
||||
|
@ -169,6 +169,38 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Title Helper', function () {
|
||||
it('has loaded title helper', function () {
|
||||
should.exist(handlebars.helpers.title);
|
||||
});
|
||||
|
||||
it('can render title', function () {
|
||||
var title = 'Hello World',
|
||||
rendered = helpers.title.call({title: title});
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal(title);
|
||||
});
|
||||
|
||||
it('escapes correctly', function () {
|
||||
var rendered = helpers.title.call({'title': '<h1>I am a title</h1>'});
|
||||
|
||||
rendered.string.should.equal('<h1>I am a title</h1>');
|
||||
});
|
||||
|
||||
it('returns a blank string where title is missing', function () {
|
||||
var rendered = helpers.title.call({'title': null});
|
||||
|
||||
rendered.string.should.equal('');
|
||||
});
|
||||
|
||||
it('returns a blank string where data missing', function () {
|
||||
var rendered = helpers.title.call({});
|
||||
|
||||
rendered.string.should.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Author Helper', function () {
|
||||
|
||||
it('has loaded author helper', function () {
|
||||
@ -215,7 +247,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
describe('Plural Helper', function () {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user