Moved helper proxy into a service

- The proxy is not a helper, we want the helpers folder to only include helpers
- The proxy is also meant to be the interface to Ghost for the helpers, and we want to enforce that
- This is a small step on the way
This commit is contained in:
Hannah Wolfe 2020-04-08 16:56:37 +01:00
parent 790a5701c9
commit 35e3e0708c
45 changed files with 49 additions and 50 deletions

View File

@ -8,7 +8,7 @@
// By default supported AMP HTML tags (no additional script tag necessary):
// amp-img, amp-ad, amp-embed, amp-video and amp-pixel.
// (less) dirty requires
const proxy = require('../../../../helpers/proxy'),
const proxy = require('../../../../services/proxy'),
SafeString = proxy.SafeString;
function ampComponents() {

View File

@ -8,7 +8,7 @@
// there if available. The cacheId is a combination of `updated_at` and the `slug`.
const Promise = require('bluebird'),
moment = require('moment'),
proxy = require('../../../../helpers/proxy'),
proxy = require('../../../../services/proxy'),
SafeString = proxy.SafeString,
logging = proxy.logging,
i18n = proxy.i18n,

View File

@ -4,7 +4,7 @@
// Password input used on private.hbs for password-protected blogs
// (less) dirty requires
const proxy = require('../../../../helpers/proxy'),
const proxy = require('../../../../services/proxy'),
SafeString = proxy.SafeString,
templates = proxy.templates;

View File

@ -2,7 +2,7 @@
// Usage: `{{asset "css/screen.css"}}`
//
// Returns the path to the specified asset.
const {SafeString, metaData, errors, i18n} = require('./proxy');
const {SafeString, metaData, errors, i18n} = require('../services/proxy');
const get = require('lodash/get');
const {getAssetUrl} = metaData;

View File

@ -9,7 +9,7 @@
//
// Block helper: `{{#author}}{{/author}}`
// This is the default handlebars behaviour of dropping into the author object scope
const {urlService, SafeString, hbs, templates} = require('./proxy');
const {urlService, SafeString, hbs, templates} = require('../services/proxy');
const buildInHelpers = hbs.handlebars.helpers;
const _ = require('lodash');

View File

@ -7,7 +7,7 @@
//
// Note that the standard {{#each authors}} implementation is unaffected by this helper.
const _ = require('lodash');
const {SafeString, templates, urlService} = require('./proxy');
const {SafeString, templates, urlService} = require('../services/proxy');
const ghostHelperUtils = require('@tryghost/helpers').utils;
module.exports = function authors(options = {}) {

View File

@ -2,7 +2,7 @@
// Usage: `{{body_class}}`
//
// Output classes for the body element
const {SafeString} = require('./proxy');
const {SafeString} = require('../services/proxy');
// We use the name body_class to match the helper for consistency
module.exports = function body_class(options) { // eslint-disable-line camelcase
@ -43,4 +43,3 @@ module.exports = function body_class(options) { // eslint-disable-line camelcase
return new SafeString(classes);
};

View File

@ -6,7 +6,7 @@
//
// Defaults to class="cancel-subscription-link" errorClass="cancel-subscription-error" cancelLabel="Cancel subscription" continueLabel="Continue subscription"
const {templates, errors, i18n} = require('./proxy');
const {templates, errors, i18n} = require('../services/proxy');
module.exports = function excerpt(options) {
let truncateOptions = (options || {}).hash || {};

View File

@ -1,4 +1,4 @@
const {SafeString} = require('./proxy');
const {SafeString} = require('../services/proxy');
module.exports = function concat(...args) {
const options = args.pop();

View File

@ -6,7 +6,7 @@
//
// Enables tag-safe truncation of content by characters or words.
const {SafeString} = require('./proxy');
const {SafeString} = require('../services/proxy');
const downsize = require('downsize');
module.exports = function content(options = {}) {

View File

@ -3,7 +3,7 @@
//
// Formats a date using moment-timezone.js. Formats published_at by default but will also take a date as a parameter
const {SafeString, themeI18n} = require('./proxy');
const {SafeString, themeI18n} = require('../services/proxy');
const moment = require('moment-timezone');
module.exports = function (date, options) {

View File

@ -4,7 +4,7 @@
//
// Returns URI encoded string
const {SafeString} = require('./proxy');
const {SafeString} = require('../services/proxy');
module.exports = function encode(string, options) {
const uri = string || options;

View File

@ -5,7 +5,7 @@
//
// Defaults to words="50"
const {SafeString, metaData} = require('./proxy');
const {SafeString, metaData} = require('../services/proxy');
const _ = require('lodash');
const getMetaDataExcerpt = metaData.getMetaDataExcerpt;

View File

@ -2,7 +2,7 @@
// Usage: `{{facebook_url}}` or `{{facebook_url author.facebook}}`
//
// Output a url for a facebook username
const {socialUrls, localUtils} = require('./proxy');
const {socialUrls, localUtils} = require('../services/proxy');
// We use the name facebook_url to match the helper for consistency:
module.exports = function facebook_url(username, options) { // eslint-disable-line camelcase

View File

@ -3,7 +3,7 @@
//
// Block helper designed for looping through posts
const _ = require('lodash');
const {logging, i18n, hbs} = require('./proxy');
const {logging, i18n, hbs} = require('../services/proxy');
const {Utils: hbsUtils, handlebars: {createFrame}} = hbs;
const ghostHelperUtils = require('@tryghost/helpers').utils;

View File

@ -1,7 +1,7 @@
// # Get Helper
// Usage: `{{#get "posts" limit="5"}}`, `{{#get "tags" limit="all"}}`
// Fetches data from the API
const {config, logging, errors, i18n, hbs, api} = require('./proxy');
const {config, logging, errors, i18n, hbs, api} = require('../services/proxy');
const _ = require('lodash');
const Promise = require('bluebird');
const jsonpath = require('jsonpath');

View File

@ -2,7 +2,7 @@
// Usage: `{{ghost_foot}}`
//
// Outputs scripts and other assets at the bottom of a Ghost theme
const {SafeString, settingsCache} = require('./proxy');
const {SafeString, settingsCache} = require('../services/proxy');
const _ = require('lodash');
// We use the name ghost_foot to match the helper for consistency:

View File

@ -2,7 +2,7 @@
// Usage: `{{ghost_head}}`
//
// Outputs scripts and other assets at the top of a Ghost theme
const {metaData, escapeExpression, SafeString, logging, settingsCache, config, blogIcon, labs} = require('./proxy');
const {metaData, escapeExpression, SafeString, logging, settingsCache, config, blogIcon, labs} = require('../services/proxy');
const _ = require('lodash');
const debug = require('ghost-ignition').debug('ghost_head');

View File

@ -4,7 +4,7 @@
//
// Checks if a post has a particular property
const {logging, i18n} = require('./proxy');
const {logging, i18n} = require('../services/proxy');
const _ = require('lodash');
const validAttrs = ['tag', 'author', 'slug','visibility', 'id', 'number', 'index', 'any', 'all'];

View File

@ -9,7 +9,7 @@
const url = require('url');
const _ = require('lodash');
const {urlUtils, logging, i18n} = require('./proxy');
const {urlUtils, logging, i18n} = require('../services/proxy');
const STATIC_IMAGE_URL_PREFIX = `${urlUtils.STATIC_IMAGE_URL_PREFIX}`;

View File

@ -1,4 +1,4 @@
const proxy = require('./proxy');
const proxy = require('../services/proxy');
const register = require('./register');
const coreHelpers = {};

View File

@ -1,7 +1,7 @@
// # Is Helper
// Usage: `{{#is "paged"}}`, `{{#is "index, paged"}}`
// Checks whether we're in a given context.
const {logging, i18n} = require('./proxy');
const {logging, i18n} = require('../services/proxy');
const _ = require('lodash');
module.exports = function is(context, options) {

View File

@ -12,7 +12,7 @@
// Language tags in HTML and XML
// https://www.w3.org/International/articles/language-tags/
const {SafeString, themeI18n} = require('./proxy');
const {SafeString, themeI18n} = require('../services/proxy');
module.exports = function lang() {
return new SafeString(themeI18n.locale());

View File

@ -1,6 +1,6 @@
// # link helper
const _ = require('lodash');
const {config, SafeString, errors, i18n} = require('./proxy');
const {config, SafeString, errors, i18n} = require('../services/proxy');
const {buildLinkClasses} = require('./utils');
const managedAttributes = ['href', 'class', 'activeClass', 'parentActiveClass'];

View File

@ -1,6 +1,6 @@
// # link_class helper
const _ = require('lodash');
const {config, SafeString, errors, i18n} = require('./proxy');
const {config, SafeString, errors, i18n} = require('../services/proxy');
const {buildLinkClasses} = require('./utils');
module.exports = function link_class(options) { // eslint-disable-line camelcase

View File

@ -2,7 +2,7 @@
// Usage: `{{meta_description}}`
//
// Page description used for sharing and SEO
const {metaData} = require('./proxy');
const {metaData} = require('../services/proxy');
const {getMetaDataDescription} = metaData;
// We use the name meta_description to match the helper for consistency:

View File

@ -2,7 +2,7 @@
// Usage: `{{meta_title}}`
//
// Page title used for sharing and SEO
const {metaData} = require('./proxy');
const {metaData} = require('../services/proxy');
const {getMetaDataTitle} = metaData;
// We use the name meta_title to match the helper for consistency:

View File

@ -2,7 +2,7 @@
// `{{navigation}}`
// Outputs navigation menu of static urls
const {SafeString, i18n, errors, templates, hbs} = require('./proxy');
const {SafeString, i18n, errors, templates, hbs} = require('../services/proxy');
const {slugify} = require('@tryghost/string');
const _ = require('lodash');
const createFrame = hbs.handlebars.createFrame;

View File

@ -4,7 +4,7 @@
// `{{page_url 2}}`
//
// Returns the URL for the page specified in the current object context.
const {metaData} = require('./proxy');
const {metaData} = require('../services/proxy');
const getPaginatedUrl = metaData.getPaginatedUrl;
// We use the name page_url to match the helper for consistency:

View File

@ -2,7 +2,7 @@
// `{{pagination}}`
// Outputs previous and next buttons, along with info about the current page
const {errors, i18n, templates, hbs} = require('./proxy');
const {errors, i18n, templates, hbs} = require('../services/proxy');
const _ = require('lodash');
const createFrame = hbs.handlebars.createFrame;

View File

@ -10,7 +10,7 @@
// The 3rd argument is the string that will be output if the variable's value is 1
// The 4th argument is the string that will be output if the variable's value is 2+
const {errors, i18n, SafeString} = require('./proxy');
const {errors, i18n, SafeString} = require('../services/proxy');
const isUndefined = require('lodash/isUndefined');
module.exports = function plural(number, options) {

View File

@ -2,7 +2,7 @@
// Usage: `{{post_class}}`
//
// Output classes for the body element
const {SafeString} = require('./proxy');
const {SafeString} = require('../services/proxy');
// We use the name post_class to match the helper for consistency:
module.exports = function post_class() { // eslint-disable-line camelcase

View File

@ -3,7 +3,7 @@
// `{{#prev_post}}<a href ="{{url}}>previous post</a>{{/prev_post}}'
// `{{#next_post}}<a href ="{{url absolute="true">next post</a>{{/next_post}}'
const {logging, i18n, api, hbs, checks} = require('./proxy');
const {logging, i18n, api, hbs, checks} = require('../services/proxy');
const get = require('lodash/get');
const Promise = require('bluebird');
const moment = require('moment');

View File

@ -5,7 +5,7 @@
// Returns amount equal to the dominant denomintation of the currency.
// For example, if 2100 is passed, it will return 21.
const isNumber = require('lodash/isNumber');
const {errors, i18n} = require('./proxy');
const {errors, i18n} = require('../services/proxy');
module.exports = function price(amount) {
// CASE: if no amount is passed, e.g. `{{price}}` we throw an error

View File

@ -10,7 +10,7 @@
//
// Returns estimated reading time for post
const {SafeString, checks} = require('./proxy');
const {SafeString, checks} = require('../services/proxy');
const calculateReadingTime = require('@tryghost/helpers').readingTime;
module.exports = function reading_time(options) {// eslint-disable-line camelcase

View File

@ -1,5 +1,5 @@
const Promise = require('bluebird');
const {config, hbs, errors, logging} = require('./proxy');
const {config, hbs, errors, logging} = require('../services/proxy');
// Register an async handlebars helper for a given handlebars instance
function asyncHelperWrapper(hbs, name, fn) {

View File

@ -10,7 +10,7 @@
// because often other helpers need that (t) returns a string to be able to work as subexpression; e.g.:
// {{tags prefix=(t " on ")}}
const {themeI18n} = require('./proxy');
const {themeI18n} = require('../services/proxy');
module.exports = function t(text, options) {
var bindings = {},

View File

@ -5,7 +5,7 @@
// By default, tags are separated by commas.
//
// Note that the standard {{#each tags}} implementation is unaffected by this helper
const {urlService, SafeString, templates} = require('./proxy');
const {urlService, SafeString, templates} = require('../services/proxy');
const _ = require('lodash');
const ghostHelperUtils = require('@tryghost/helpers').utils;

View File

@ -3,7 +3,7 @@
//
// Overrides the standard behaviour of `{[title}}` to ensure the content is correctly escaped
const {SafeString, escapeExpression} = require('./proxy');
const {SafeString, escapeExpression} = require('../services/proxy');
module.exports = function title() {
return new SafeString(escapeExpression(this.title || ''));

View File

@ -2,7 +2,7 @@
// Usage: `{{twitter_url}}` or `{{twitter_url author.twitter}}`
//
// Output a url for a twitter username
const {socialUrls, localUtils} = require('./proxy');
const {socialUrls, localUtils} = require('../services/proxy');
// We use the name twitter_url to match the helper for consistency:
module.exports = function twitter_url(username, options) { // eslint-disable-line camelcase

View File

@ -4,7 +4,7 @@
// Returns the URL for the current object scope i.e. If inside a post scope will return post permalink
// `absolute` flag outputs absolute URL, else URL is relative
const {SafeString, metaData} = require('./proxy');
const {SafeString, metaData} = require('../services/proxy');
const {getMetaDataUrl} = metaData;
module.exports = function url(options) {

View File

@ -1,7 +1,7 @@
// This file defines everything that helpers "require"
// With the exception of modules like lodash, Bluebird
// We can later refactor to enforce this something like we did in apps
var hbs = require('../services/themes/engine'),
var hbs = require('./themes/engine'),
settingsCache = require('../../server/services/settings/cache'),
config = require('../../server/config');
@ -29,7 +29,7 @@ module.exports = {
logging: require('../../server/lib/common/logging'),
// Theme i18n is separate to common i18n
themeI18n: require('../services/themes/i18n'),
themeI18n: require('./themes/i18n'),
// This is used to detect if "isPost" is true in prevNext.
checks: require('../../server/data/schema').checks,
@ -57,12 +57,12 @@ module.exports = {
},
// The local template thing, should this be merged with the channels one?
templates: require('./template'),
templates: require('../helpers/template'),
// Various utils, needs cleaning up / simplifying
socialUrls: require('@tryghost/social-urls'),
blogIcon: require('../../server/lib/image/blog-icon'),
urlService: require('../services/url'),
urlService: require('./url'),
urlUtils: require('../../server/lib/url-utils'),
localUtils: require('./utils')
localUtils: require('../helpers/utils')
};

View File

@ -1,7 +1,7 @@
var should = require('should'),
sinon = require('sinon'),
helpers = require('../../../core/frontend/helpers'),
proxy = require('../../../core/frontend/helpers/proxy'),
proxy = require('../../../core/frontend/services/proxy'),
settingsCache = proxy.settingsCache;
describe('{{ghost_foot}} helper', function () {

View File

@ -12,7 +12,7 @@ const should = require('should'),
routing = require('../../../core/frontend/services/routing'),
urlService = require('../../../core/frontend/services/url'),
helpers = require('../../../core/frontend/helpers'),
proxy = require('../../../core/frontend/helpers/proxy'),
proxy = require('../../../core/frontend/services/proxy'),
settingsCache = proxy.settingsCache;
describe('{{ghost_head}} helper', function () {

View File

@ -1,7 +1,7 @@
const should = require('should');
const settingsCache = require('../../../core/server/services/settings/cache');
const helpers = require('../../../core/frontend/helpers');
const proxy = require('../../../core/frontend/helpers/proxy');
const proxy = require('../../../core/frontend/services/proxy');
describe('{{lang}} helper', function () {
beforeEach(function () {