Add featured class when post is featured

fixes #1112
This commit is contained in:
Fabian Becker 2013-10-16 11:41:49 +00:00
parent 7419e05b3a
commit f4ac715f97
2 changed files with 14 additions and 1 deletions

View File

@ -227,12 +227,17 @@ coreHelpers = function (ghost) {
ghost.registerThemeHelper('post_class', function (options) { ghost.registerThemeHelper('post_class', function (options) {
var classes = ['post'], var classes = ['post'],
tags = this.post && this.post.tags ? this.post.tags : this.tags || []; tags = this.post && this.post.tags ? this.post.tags : this.tags || [],
featured = this.post && this.post.featured ? this.post.featured : this.featured || false;
if (tags) { if (tags) {
classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; })); classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; }));
} }
if (featured) {
classes.push('featured');
}
return ghost.doFilter('post_class', classes, function (classes) { return ghost.doFilter('post_class', classes, function (classes) {
var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(classString.trim()); return new hbs.handlebars.SafeString(classString.trim());

View File

@ -197,6 +197,14 @@ describe('Core Helpers', function () {
rendered.string.should.equal('post'); rendered.string.should.equal('post');
}); });
it('can render featured class', function () {
var post = { featured: true },
rendered = handlebars.helpers.post_class.call(post);
should.exist(rendered);
rendered.string.should.equal('post featured');
});
}); });
describe('ghost_head Helper', function () { describe('ghost_head Helper', function () {