mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fix the author context block
fixes #3599 - If the author helper is called as a block (i.e. fn is present) then treat it as a with call
This commit is contained in:
parent
954fde1cd2
commit
157cf5c3b9
2 changed files with 19 additions and 8 deletions
|
@ -202,11 +202,15 @@ coreHelpers.asset = function (context, options) {
|
||||||
// Returns the full name of the author of a given post, or a blank string
|
// Returns the full name of the author of a given post, or a blank string
|
||||||
// if the author could not be determined.
|
// if the author could not be determined.
|
||||||
//
|
//
|
||||||
coreHelpers.author = function (options) {
|
coreHelpers.author = function (context, options) {
|
||||||
options = options || {};
|
if (_.isUndefined(options)) {
|
||||||
options.hash = options.hash || {};
|
options = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.fn) {
|
||||||
|
return hbs.handlebars.helpers['with'].call(this, this.author, options);
|
||||||
|
}
|
||||||
|
|
||||||
/*jshint unused:false*/
|
|
||||||
var autolink = _.isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true,
|
var autolink = _.isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true,
|
||||||
output = '';
|
output = '';
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ describe('Core Helpers', function () {
|
||||||
|
|
||||||
it('Returns the link to the author from the context', function () {
|
it('Returns the link to the author from the context', function () {
|
||||||
var data = {'author': {'name': 'abc 123', slug: 'abc123', bio: '', website: '', status: '', location: ''}},
|
var data = {'author': {'name': 'abc 123', slug: 'abc123', bio: '', website: '', status: '', location: ''}},
|
||||||
result = helpers.author.call(data);
|
result = helpers.author.call(data, {hash: {}});
|
||||||
|
|
||||||
String(result).should.equal('<a href="/author/abc123/">abc 123</a>');
|
String(result).should.equal('<a href="/author/abc123/">abc 123</a>');
|
||||||
});
|
});
|
||||||
|
@ -224,13 +224,22 @@ describe('Core Helpers', function () {
|
||||||
|
|
||||||
it('Returns a blank string where author data is missing', function () {
|
it('Returns a blank string where author data is missing', function () {
|
||||||
var data = {'author': null},
|
var data = {'author': null},
|
||||||
result = helpers.author.call(data);
|
result = helpers.author.call(data, {hash: {}});
|
||||||
|
|
||||||
String(result).should.equal('');
|
String(result).should.equal('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Functions as block helper if called with #', function () {
|
||||||
|
var data = {'author': {'name': 'abc 123', slug: 'abc123'}},
|
||||||
|
// including fn emulates the #
|
||||||
|
result = helpers.author.call(data, {hash: {}, fn: function () { return 'FN'; }});
|
||||||
|
|
||||||
|
// It outputs the result of fn
|
||||||
|
String(result).should.equal('FN');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('encode Helper', function () {
|
describe('encode Helper', function () {
|
||||||
|
|
||||||
it('has loaded encode helper', function () {
|
it('has loaded encode helper', function () {
|
||||||
|
@ -247,8 +256,6 @@ describe('Core Helpers', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('Plural Helper', function () {
|
describe('Plural Helper', function () {
|
||||||
|
|
||||||
it('has loaded plural helper', function () {
|
it('has loaded plural helper', function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue