diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index db96569483..3568822aad 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -89,6 +89,32 @@ coreHelpers = function (ghost) { ); }); + + ghost.registerThemeHelper('bodyclass', function (options) { + var classes = []; + if (!this.path || this.path === '/' || this.path === '') { + classes.push('home'); + } else { + classes.push('post'); + } + + return ghost.doFilter('bodyclass', classes, function (classes) { + var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); + return new hbs.handlebars.SafeString(classString.trim()); + }); + }); + + ghost.registerThemeHelper('postclass', function (options) { + var classes = ['post']; + + // TODO: add tag names once we have them + return ghost.doFilter('postclass', classes, function (classes) { + var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); + return new hbs.handlebars.SafeString(classString.trim()); + }); + }); + + /** * [ description] * diff --git a/core/test/unit/frontend_helpers_index_spec.js b/core/test/unit/frontend_helpers_index_spec.js index 8061697fd3..471563ed3e 100644 --- a/core/test/unit/frontend_helpers_index_spec.js +++ b/core/test/unit/frontend_helpers_index_spec.js @@ -116,8 +116,43 @@ describe('Core Helpers', function () { should.exist(rendered); rendered.string.should.equal(expected); }); + }); + describe('Bodyclass Helper', function () { + it('has loaded bodyclass helper', function () { + should.exist(handlebars.helpers.bodyclass); + }); + it('can render class string', function () { + var rendered = handlebars.helpers.bodyclass.call({}); + should.exist(rendered); + + rendered.string.should.equal('home'); + }); + + it('can render class string for context', function () { + var rendered1 = handlebars.helpers.bodyclass.call({path: '/'}), + rendered2 = handlebars.helpers.bodyclass.call({path: '/a-post-title'}); + + should.exist(rendered1); + should.exist(rendered2); + + rendered1.string.should.equal('home'); + rendered2.string.should.equal('post'); + }); + }); + + describe('Postclass Helper', function () { + it('has loaded postclass helper', function () { + should.exist(handlebars.helpers.postclass); + }); + + it('can render class string', function () { + var rendered = handlebars.helpers.postclass.call({}); + should.exist(rendered); + + rendered.string.should.equal('post'); + }); }); describe('Navigation Helper', function () {