mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
Merge pull request #3600 from ErisDS/author-helper
Fix the author context block
This commit is contained in:
commit
5590628d54
@ -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…
Reference in New Issue
Block a user