mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
3cea203459
no issue 🔥 Remove adminHbs concept from tests 🔥 Get rid of unnecessary helper test utils 🔥 Remove helper missing code - this hasn't been registered / used for ages 😱 - gscan no longer allows us to activate themes that have missing helpers, so this wouldn't be used anyway TODO: consider whether we should make a way to override this? 🎨 Reduce coupling inside of /helpers 🎨 Use settingsCache in ghost_foot ✨ Labs util for enabling helpers 🎨 Move loadCoreHelpers to blog - This needs a proper home, but at the very least it doesn't belong in server/app.js! 🎨 Use settingsCache in ghost_head
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
var settingsCache = require('../settings/cache'),
|
|
_ = require('lodash'),
|
|
Promise = require('bluebird'),
|
|
hbs = require('express-hbs'),
|
|
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 hbs.handlebars.SafeString(
|
|
'<script>console.error("' + _.values(errDetails).join(' ') + '");</script>'
|
|
);
|
|
|
|
if (options.async) {
|
|
return Promise.resolve(function asyncError() {
|
|
return errString;
|
|
});
|
|
}
|
|
|
|
return errString;
|
|
};
|