Merge pull request #3445 from ErisDS/issue-3389

Adding new {{title}} helper
This commit is contained in:
Sebastian Gierlinger 2014-07-30 08:20:36 +02:00
commit bdb75c8f07
2 changed files with 39 additions and 1 deletions

View File

@ -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);

View File

@ -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('&lt;h1&gt;I am a title&lt;/h1&gt;');
});
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 () {