0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Updated messaging around {{get}} helper access

closes #10447

- Get helper message talks about the old API, but upgrading is the best way to solve the problem
- Had to create a way to add a custom message to a labs enabled helper to achieve this
This commit is contained in:
Hannah Wolfe 2019-02-04 17:58:35 +00:00
parent 5365094dfc
commit 426c122ed1
4 changed files with 20 additions and 14 deletions

View file

@ -197,7 +197,10 @@ module.exports = function getLabsWrapper() {
flagKey: 'publicAPI', flagKey: 'publicAPI',
flagName: 'Public API', flagName: 'Public API',
helperName: 'get', helperName: 'get',
helpUrl: 'https://docs.ghost.org/faq/api-versioning/', // Even though this is a labs enabled helper, really we want users to upgrade to v2 API.
errMessagePath: 'warnings.helpers.get.apiRequired.message',
errContextPath: 'warnings.helpers.get.apiRequired.context',
helpUrl: 'https://docs.ghost.org/api/handlebars-themes/packagejson/',
async: true async: true
}, function executeHelper() { }, function executeHelper() {
return get.apply(self, args); return get.apply(self, args);

View file

@ -18,7 +18,8 @@ labs.isSet = function isSet(flag) {
}; };
labs.enabledHelper = function enabledHelper(options, callback) { labs.enabledHelper = function enabledHelper(options, callback) {
var errDetails, errString; const errDetails = {};
let errString;
if (labs.isSet(options.flagKey) === true) { if (labs.isSet(options.flagKey) === true) {
// helper is active, use the callback // helper is active, use the callback
@ -26,14 +27,12 @@ labs.enabledHelper = function enabledHelper(options, callback) {
} }
// Else, the helper is not active and we need to handle this as an error // Else, the helper is not active and we need to handle this as an error
errDetails = { errDetails.message = common.i18n.t(options.errMessagePath || 'warnings.helpers.helperNotAvailable', {helperName: options.helperName}),
message: common.i18n.t('warnings.helpers.helperNotAvailable', {helperName: options.helperName}), errDetails.context = common.i18n.t(options.errContextPath || 'warnings.helpers.flagMustBeEnabled', {
context: common.i18n.t('warnings.helpers.flagMustBeEnabled', { helperName: options.helperName,
helperName: options.helperName, flagName: options.flagName
flagName: options.flagName });
}), errDetails.help = common.i18n.t(options.errHelpPath || 'warnings.helpers.seeLink', {url: options.helpUrl});
help: common.i18n.t('warnings.helpers.seeLink', {url: options.helpUrl})
};
common.logging.error(new common.errors.DisabledFeatureError(errDetails)); common.logging.error(new common.errors.DisabledFeatureError(errDetails));

View file

@ -565,7 +565,11 @@
"iteratorNeeded": "Need to pass an iterator to #foreach" "iteratorNeeded": "Need to pass an iterator to #foreach"
}, },
"get": { "get": {
"invalidResource": "Invalid resource given to get helper" "invalidResource": "Invalid resource given to get helper",
"apiRequired": {
"message": "The \\{\\{#get\\}\\} helper requires your theme to have API access.",
"context": "Please enable the v2 API via your theme's package.json file."
}
}, },
"has": { "has": {
"invalidAttribute": "Invalid or no attribute given to has helper" "invalidAttribute": "Invalid or no attribute given to has helper"

View file

@ -45,9 +45,9 @@ describe('{{#get}} helper', function () {
result.should.be.a.Function(); result.should.be.a.Function();
result().should.be.an.Object().with.property( result().should.be.an.Object().with.property(
'string', 'string',
'<script>console.error("The {{get}} helper is not available. ' + '<script>console.error("The {{#get}} helper requires your theme to have API access. ' +
'The Public API flag must be enabled in labs if you wish to use the {{get}} helper. ' + 'Please enable the v2 API via your theme\'s package.json file. ' +
'See https://docs.ghost.org/faq/api-versioning/");</script>' 'See https://docs.ghost.org/api/handlebars-themes/packagejson/");</script>'
); );
done(); done();