Ghost/core/server/helpers/post_class.js
Hannah Wolfe bcf5a1bc34
Switch to Eslint (#9197)
refs #9178

* Add eslint deps, remove old lint deps
* Add eslint config, remove old lint configs
* Config for server and tests are different
* Tweaked rules to suit us
* Fix linting in codebase - lots of indent changes.
* Fix a real broken test
2017-11-01 13:44:54 +00:00

35 lines
1011 B
JavaScript

// # Post Class Helper
// Usage: `{{post_class}}`
//
// Output classes for the body element
var proxy = require('./proxy'),
_ = require('lodash'),
SafeString = proxy.SafeString;
// We use the name post_class to match the helper for consistency:
module.exports = function post_class() { // eslint-disable-line camelcase
var classes = ['post'],
tags = this.post && this.post.tags ? this.post.tags : this.tags || [],
featured = this.post && this.post.featured ? this.post.featured : this.featured || false,
page = this.post && this.post.page ? this.post.page : this.page || false;
if (tags) {
classes = classes.concat(tags.map(function (tag) {
return 'tag-' + tag.slug;
}));
}
if (featured) {
classes.push('featured');
}
if (page) {
classes.push('page');
}
classes = _.reduce(classes, function (memo, item) {
return memo + ' ' + item;
}, '');
return new SafeString(classes.trim());
};