mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
52b924638d
- The frontend proxy is meant to be a way to pass critical internal pieces of Ghost core into the frontend - These fundamental @tryghost packages are shared and can be required directly, hence there's no need to pass them via the proxy - Reducing the surface area of the proxy reduces the proxies API - This makes it easier to see what's left in terms of decoupling the frontend, and what will always need to be passed (e.g. api) Note on @tryghost/social-urls: - this is a small utility that helps create URLs for social profiles, it's a util for working with data on the frontend aka part of the sdk - I think there should be many of these small helpers and we'll probably want to bundle them for the frontend at some point - for now, I'm leaving these as part of the proxy, as need to figure out where they belong
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
// # {{cancel_link}} Helper
|
|
// Usage: `{{cancel_link}}`, `{{cancel_link class="custom-cancel-class"}}`, `{{cancel_link cancelLabel="Cancel please!"}}`
|
|
//
|
|
// Should be used inside of a subscription context, e.g.: `{{#foreach @member.subscriptions}} {{cancel_link}} {{/foreach}}`
|
|
// Outputs cancel/renew links to manage subscription renewal after the subscription period ends.
|
|
//
|
|
// Defaults to class="cancel-subscription-link" errorClass="cancel-subscription-error" cancelLabel="Cancel subscription" continueLabel="Continue subscription"
|
|
const {templates, labs} = require('../services/proxy');
|
|
|
|
const errors = require('@tryghost/errors');
|
|
const tpl = require('@tryghost/tpl');
|
|
|
|
const messages = {
|
|
invalidData: 'The {{cancel_link}} helper was used outside of a subscription context. See https://ghost.org/docs/themes/members/#cancel-links.'
|
|
};
|
|
|
|
function cancel_link(options) { // eslint-disable-line camelcase
|
|
let truncateOptions = (options || {}).hash || {};
|
|
|
|
if (this.id === undefined || this.cancel_at_period_end === undefined) {
|
|
throw new errors.IncorrectUsageError({message: tpl(messages.invalidData)});
|
|
}
|
|
|
|
const data = {
|
|
id: this.id,
|
|
cancel_at_period_end: this.cancel_at_period_end,
|
|
class: truncateOptions.class || 'gh-subscription-cancel',
|
|
errorClass: truncateOptions.errorClass || 'gh-error gh-error-subscription-cancel',
|
|
cancelLabel: truncateOptions.cancelLabel || 'Cancel subscription',
|
|
continueLabel: truncateOptions.continueLabel || 'Continue subscription'
|
|
};
|
|
|
|
return templates.execute('cancel_link', data);
|
|
}
|
|
|
|
module.exports = function cancelLabsWrapper() {
|
|
let self = this;
|
|
let args = arguments;
|
|
|
|
return labs.enabledHelper({
|
|
flagKey: 'members',
|
|
flagName: 'Members',
|
|
helperName: 'cancel_link',
|
|
helpUrl: 'https://ghost.org/docs/themes/members/'
|
|
}, () => {
|
|
return cancel_link.apply(self, args);
|
|
});
|
|
};
|