mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed frontend require in labs
- Replaced requiring SafeString all the way from the theme engine, with using express-hbs directly - This is quite a big require, just for the safe string function, but without this we have to tie labs to our theme layer - Also removed i18n and updated the jsdoc for enabledHelper - The labs service can be moved to shared now!
This commit is contained in:
parent
2e731f91a7
commit
2072361022
1 changed files with 26 additions and 5 deletions
|
@ -1,12 +1,19 @@
|
|||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const SafeString = require('../../frontend/services/theme-engine/engine').SafeString;
|
||||
const SafeString = require('express-hbs').SafeString;
|
||||
const errors = require('@tryghost/errors');
|
||||
const i18n = require('../../shared/i18n');
|
||||
const logging = require('@tryghost/logging');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
|
||||
const settingsCache = require('../../shared/settings-cache');
|
||||
const config = require('../../shared/config');
|
||||
|
||||
const messages = {
|
||||
errorMessage: 'The \\{\\{{helperName}\\}\\} helper is not available.',
|
||||
errorContext: 'The {flagName} flag must be enabled in labs if you wish to use the \\{\\{{helperName}\\}\\} helper.',
|
||||
errorHelp: 'See {url}'
|
||||
};
|
||||
|
||||
// NOTE: this allowlist is meant to be used to filter out any unexpected
|
||||
// input for the "labs" setting value
|
||||
const BETA_FEATURES = [
|
||||
|
@ -46,6 +53,20 @@ module.exports.isSet = function isSet(flag) {
|
|||
return !!(labsConfig && labsConfig[flag] && labsConfig[flag] === true);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {string} options.flagKey the interal lookup key of the flag e.g. labs.isSet(matchHelper)
|
||||
* @param {string} options.flagName the user-facing name of the flag e.g. Match helper
|
||||
* @param {string} options.helperName Name of the helper to be enabled/disabled
|
||||
* @param {string} [options.errorMessage] Optional replacement error message
|
||||
* @param {string} [options.errorContext] Optional replacement context message
|
||||
* @param {string} [options.errorHelp] Optional replacement help message
|
||||
* @param {string} [options.helpUrl] Url to show in the help message
|
||||
* @param {string} [options.async] is the helper async?
|
||||
* @param {function} callback
|
||||
* @returns {Promise<Handlebars.SafeString>|Handlebars.SafeString}
|
||||
*/
|
||||
module.exports.enabledHelper = function enabledHelper(options, callback) {
|
||||
const errDetails = {};
|
||||
let errString;
|
||||
|
@ -56,12 +77,12 @@ module.exports.enabledHelper = function enabledHelper(options, callback) {
|
|||
}
|
||||
|
||||
// Else, the helper is not active and we need to handle this as an error
|
||||
errDetails.message = i18n.t(options.errMessagePath || 'warnings.helpers.helperNotAvailable', {helperName: options.helperName}),
|
||||
errDetails.context = i18n.t(options.errContextPath || 'warnings.helpers.flagMustBeEnabled', {
|
||||
errDetails.message = tpl(options.errorMessage || messages.errorMessage, {helperName: options.helperName}),
|
||||
errDetails.context = tpl(options.errorContext || messages.errorContext, {
|
||||
helperName: options.helperName,
|
||||
flagName: options.flagName
|
||||
});
|
||||
errDetails.help = i18n.t(options.errHelpPath || 'warnings.helpers.seeLink', {url: options.helpUrl});
|
||||
errDetails.help = tpl(options.errorHelp || messages.errorHelp, {url: options.helpUrl});
|
||||
|
||||
logging.error(new errors.DisabledFeatureError(errDetails));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue