-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 🎨 Cleanup & simplify theme helpers (#8223)
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
- Loading branch information
Showing
40 changed files
with
230 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
// Dirty requires! | ||
var hbs = require('express-hbs'), | ||
logging = require('../../../../logging'), | ||
i18n = require('../../../../i18n'), | ||
labs = require('../../../../utils/labs'), | ||
|
||
errorMessages = [ | ||
i18n.t('warnings.helpers.helperNotAvailable', {helperName: 'subscribe_form'}), | ||
i18n.t('warnings.helpers.apiMustBeEnabled', {helperName: 'subscribe_form', flagName: 'subscribers'}), | ||
i18n.t('warnings.helpers.seeLink', {url: 'http://support.ghost.org/subscribers-beta/'}) | ||
]; | ||
var labs = require('../../../../utils/labs'); | ||
|
||
module.exports = function registerHelpers(ghost) { | ||
var err; | ||
|
||
ghost.helpers.register('input_email', require('./input_email')); | ||
|
||
ghost.helpers.register('subscribe_form', function labsEnabledHelper() { | ||
if (labs.isSet('subscribers') === true) { | ||
return require('./subscribe_form').apply(this, arguments); | ||
} | ||
|
||
err = new Error(); | ||
err.message = i18n.t('warnings.helpers.helperNotAvailable', {helperName: 'subscribe_form'}); | ||
err.context = i18n.t('warnings.helpers.apiMustBeEnabled', {helperName: 'subscribe_form', flagName: 'subscribers'}); | ||
err.help = i18n.t('warnings.helpers.seeLink', {url: 'http://support.ghost.org/subscribers-beta/'}); | ||
|
||
logging.error(err); | ||
var self = this, | ||
args = arguments; | ||
|
||
return new hbs.handlebars.SafeString('<script>console.error("' + errorMessages.join(' ') + '");</script>'); | ||
return labs.enabledHelper({ | ||
flagKey: 'subscribers', | ||
flagName: 'Subscribers', | ||
helperName: 'subscribe_form', | ||
helpUrl: 'http://support.ghost.org/subscribers-beta/' | ||
}, function executeHelper() { | ||
return require('./subscribe_form').apply(self, args); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,46 @@ | ||
var settingsCache = require('../settings/cache'), | ||
flagIsSet; | ||
_ = require('lodash'), | ||
Promise = require('bluebird'), | ||
hbs = require('express-hbs'), | ||
errors = require('../errors'), | ||
logging = require('../logging'), | ||
i18n = require('../i18n'), | ||
labs = module.exports = {}; | ||
|
||
flagIsSet = function flagIsSet(flag) { | ||
labs.isSet = function isSet(flag) { | ||
var labsConfig = settingsCache.get('labs'); | ||
return labsConfig && labsConfig[flag] && labsConfig[flag] === true; | ||
}; | ||
|
||
module.exports.isSet = flagIsSet; | ||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.