mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-13 10:55:58 +03:00
Added bodyclass and postclass helper
closes #472 - filterable as array, output as string - with unit tests
This commit is contained in:
parent
2d3e2f36b1
commit
98e4923077
@ -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]
|
||||
*
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user