mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
870bf27394
- i18n is an old pattern that failed - we are slowly replacing i18n with the tpl helper
34 lines
874 B
JavaScript
34 lines
874 B
JavaScript
// # Is Helper
|
|
// Usage: `{{#is "paged"}}`, `{{#is "index, paged"}}`
|
|
// Checks whether we're in a given context.
|
|
const {logging, tpl} = require('../services/proxy');
|
|
const _ = require('lodash');
|
|
|
|
const messages = {
|
|
invalidAttribute: 'Invalid or no attribute given to is helper'
|
|
};
|
|
|
|
module.exports = function is(context, options) {
|
|
options = options || {};
|
|
|
|
const currentContext = options.data.root.context;
|
|
|
|
if (!_.isString(context)) {
|
|
logging.warn(tpl(messages.invalidAttribute));
|
|
return;
|
|
}
|
|
|
|
function evaluateContext(expr) {
|
|
return expr.split(',').map(function (v) {
|
|
return v.trim();
|
|
}).reduce(function (p, c) {
|
|
return p || _.includes(currentContext, c);
|
|
}, false);
|
|
}
|
|
|
|
if (evaluateContext(context)) {
|
|
return options.fn(this);
|
|
}
|
|
return options.inverse(this);
|
|
};
|