Skip to content

Commit 157cf5c

Browse files
committed
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
1 parent 954fde1 commit 157cf5c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

core/server/helpers/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,15 @@ coreHelpers.asset = function (context, options) {
202202
// Returns the full name of the author of a given post, or a blank string
203203
// if the author could not be determined.
204204
//
205-
coreHelpers.author = function (options) {
206-
options = options || {};
207-
options.hash = options.hash || {};
205+
coreHelpers.author = function (context, options) {
206+
if (_.isUndefined(options)) {
207+
options = context;
208+
}
209+
210+
if (options.fn) {
211+
return hbs.handlebars.helpers['with'].call(this, this.author, options);
212+
}
208213

209-
/*jshint unused:false*/
210214
var autolink = _.isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true,
211215
output = '';
212216

core/test/unit/server_helpers_index_spec.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('Core Helpers', function () {
209209

210210
it('Returns the link to the author from the context', function () {
211211
var data = {'author': {'name': 'abc 123', slug: 'abc123', bio: '', website: '', status: '', location: ''}},
212-
result = helpers.author.call(data);
212+
result = helpers.author.call(data, {hash: {}});
213213

214214
String(result).should.equal('<a href="/author/abc123/">abc 123</a>');
215215
});
@@ -224,13 +224,22 @@ describe('Core Helpers', function () {
224224

225225
it('Returns a blank string where author data is missing', function () {
226226
var data = {'author': null},
227-
result = helpers.author.call(data);
227+
result = helpers.author.call(data, {hash: {}});
228228

229229
String(result).should.equal('');
230230
});
231231

232+
it('Functions as block helper if called with #', function () {
233+
var data = {'author': {'name': 'abc 123', slug: 'abc123'}},
234+
// including fn emulates the #
235+
result = helpers.author.call(data, {hash: {}, fn: function () { return 'FN'; }});
236+
237+
// It outputs the result of fn
238+
String(result).should.equal('FN');
239+
});
232240
});
233241

242+
234243
describe('encode Helper', function () {
235244

236245
it('has loaded encode helper', function () {
@@ -247,8 +256,6 @@ describe('Core Helpers', function () {
247256
});
248257
});
249258

250-
251-
252259
describe('Plural Helper', function () {
253260

254261
it('has loaded plural helper', function () {

0 commit comments

Comments
 (0)