mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
52b924638d
- The frontend proxy is meant to be a way to pass critical internal pieces of Ghost core into the frontend - These fundamental @tryghost packages are shared and can be required directly, hence there's no need to pass them via the proxy - Reducing the surface area of the proxy reduces the proxies API - This makes it easier to see what's left in terms of decoupling the frontend, and what will always need to be passed (e.g. api) Note on @tryghost/social-urls: - this is a small utility that helps create URLs for social profiles, it's a util for working with data on the frontend aka part of the sdk - I think there should be many of these small helpers and we'll probably want to bundle them for the frontend at some point - for now, I'm leaving these as part of the proxy, as need to figure out where they belong
35 lines
905 B
JavaScript
35 lines
905 B
JavaScript
// # Is Helper
|
|
// Usage: `{{#is "paged"}}`, `{{#is "index, paged"}}`
|
|
// Checks whether we're in a given context.
|
|
const logging = require('@tryghost/logging');
|
|
const tpl = require('@tryghost/tpl');
|
|
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);
|
|
};
|