Merge pull request #3600 from ErisDS/author-helper

Fix the author context block
This commit is contained in:
Sebastian Gierlinger 2014-08-05 19:59:53 +02:00
commit 5590628d54
2 changed files with 19 additions and 8 deletions

View File

@ -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 = '';

View File

@ -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,12 +224,21 @@ 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 () {
@ -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 () {