mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
243b387063
refs #8126, #8221, #8223 ✨ New 'Proxy' for all helper requires - this is not currently enforced, but could be, much like apps - the proxy object is HUGE - changed date to use SafeString, this should have been there anyway - use the proxy for all helpers, including those in apps 😁 ✨ 🎨 Single instance of hbs for theme + for errors - we now have theme/engine instead of requiring express-hbs everywhere - only error-handler still also requires express-hbs, this is so that we can render errors without extra crud - TODO: remove the asset helper after #8126 IF it is not needed, or else remove the TODO 🎨 Cleanup visibility utils 🎨 Clean up the proxy a little bit 🚨 Unskip test as it now works! 🎨 Minor amends as per comments
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
var settingsCache = require('../settings/cache'),
|
|
_ = require('lodash'),
|
|
Promise = require('bluebird'),
|
|
SafeString = require('../themes/engine').SafeString,
|
|
errors = require('../errors'),
|
|
logging = require('../logging'),
|
|
i18n = require('../i18n'),
|
|
labs = module.exports = {};
|
|
|
|
labs.isSet = function isSet(flag) {
|
|
var labsConfig = settingsCache.get('labs');
|
|
return labsConfig && labsConfig[flag] && labsConfig[flag] === true;
|
|
};
|
|
|
|
labs.enabledHelper = function enabledHelper(options, callback) {
|
|
var errDetails, errString;
|
|
|
|
if (labs.isSet(options.flagKey) === true) {
|
|
// helper is active, use the callback
|
|
return callback();
|
|
}
|
|
|
|
// Else, the helper is not active and we need to handle this as an error
|
|
errDetails = {
|
|
message: i18n.t('warnings.helpers.helperNotAvailable', {helperName: options.helperName}),
|
|
context: i18n.t('warnings.helpers.flagMustBeEnabled', {
|
|
helperName: options.helperName,
|
|
flagName: options.flagName
|
|
}),
|
|
help: i18n.t('warnings.helpers.seeLink', {url: options.helpUrl})
|
|
};
|
|
|
|
logging.error(new errors.GhostError(errDetails));
|
|
|
|
errString = new SafeString(
|
|
'<script>console.error("' + _.values(errDetails).join(' ') + '");</script>'
|
|
);
|
|
|
|
if (options.async) {
|
|
return Promise.resolve(function asyncError() {
|
|
return errString;
|
|
});
|
|
}
|
|
|
|
return errString;
|
|
};
|