mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Moved non-helper code out of helpers
- the helper dir also contained some code used with helpers - utils and helper-helpers? - the goal here was for helpers to be the only thing in their folder so we can look at moving them out - all other code has been moved to services/themes for now, which is not the right place either - services/themes is a catch-all for theme storage, loading, validation, rendering and more, needs to be broken down
This commit is contained in:
parent
f3ed965987
commit
59b9f161dd
@ -1,10 +1,4 @@
|
||||
const register = require('./register');
|
||||
|
||||
const coreHelpers = {};
|
||||
const registerThemeHelper = register.registerThemeHelper;
|
||||
const registerAsyncThemeHelper = register.registerAsyncThemeHelper;
|
||||
|
||||
let registerAllCoreHelpers;
|
||||
|
||||
coreHelpers.asset = require('./asset');
|
||||
coreHelpers.author = require('./author');
|
||||
@ -45,49 +39,4 @@ coreHelpers.title = require('./title');
|
||||
coreHelpers.twitter_url = require('./twitter_url');
|
||||
coreHelpers.url = require('./url');
|
||||
|
||||
registerAllCoreHelpers = function registerAllCoreHelpers() {
|
||||
// Register theme helpers
|
||||
registerThemeHelper('asset', coreHelpers.asset);
|
||||
registerThemeHelper('author', coreHelpers.author);
|
||||
registerThemeHelper('authors', coreHelpers.authors);
|
||||
registerThemeHelper('body_class', coreHelpers.body_class);
|
||||
registerThemeHelper('cancel_link', coreHelpers.cancel_link);
|
||||
registerThemeHelper('concat', coreHelpers.concat);
|
||||
registerThemeHelper('content', coreHelpers.content);
|
||||
registerThemeHelper('date', coreHelpers.date);
|
||||
registerThemeHelper('encode', coreHelpers.encode);
|
||||
registerThemeHelper('excerpt', coreHelpers.excerpt);
|
||||
registerThemeHelper('foreach', coreHelpers.foreach);
|
||||
registerThemeHelper('ghost_foot', coreHelpers.ghost_foot);
|
||||
registerThemeHelper('has', coreHelpers.has);
|
||||
registerThemeHelper('is', coreHelpers.is);
|
||||
registerThemeHelper('img_url', coreHelpers.img_url);
|
||||
registerThemeHelper('lang', coreHelpers.lang);
|
||||
registerThemeHelper('link', coreHelpers.link);
|
||||
registerThemeHelper('link_class', coreHelpers.link_class);
|
||||
registerThemeHelper('meta_description', coreHelpers.meta_description);
|
||||
registerThemeHelper('meta_title', coreHelpers.meta_title);
|
||||
registerThemeHelper('navigation', coreHelpers.navigation);
|
||||
registerThemeHelper('page_url', coreHelpers.page_url);
|
||||
registerThemeHelper('pagination', coreHelpers.pagination);
|
||||
registerThemeHelper('plural', coreHelpers.plural);
|
||||
registerThemeHelper('post_class', coreHelpers.post_class);
|
||||
registerThemeHelper('price', coreHelpers.price);
|
||||
registerThemeHelper('raw', coreHelpers.raw);
|
||||
registerThemeHelper('reading_time', coreHelpers.reading_time);
|
||||
registerThemeHelper('t', coreHelpers.t);
|
||||
registerThemeHelper('tags', coreHelpers.tags);
|
||||
registerThemeHelper('title', coreHelpers.title);
|
||||
registerThemeHelper('twitter_url', coreHelpers.twitter_url);
|
||||
registerThemeHelper('facebook_url', coreHelpers.facebook_url);
|
||||
registerThemeHelper('url', coreHelpers.url);
|
||||
|
||||
// Async theme helpers
|
||||
registerAsyncThemeHelper('ghost_head', coreHelpers.ghost_head);
|
||||
registerAsyncThemeHelper('next_post', coreHelpers.next_post);
|
||||
registerAsyncThemeHelper('prev_post', coreHelpers.prev_post);
|
||||
registerAsyncThemeHelper('get', coreHelpers.get);
|
||||
};
|
||||
|
||||
module.exports = coreHelpers;
|
||||
module.exports.loadCoreHelpers = registerAllCoreHelpers;
|
||||
|
@ -1,7 +1,7 @@
|
||||
// # link helper
|
||||
const _ = require('lodash');
|
||||
const {config, SafeString, errors, i18n} = require('../services/proxy');
|
||||
const {buildLinkClasses} = require('./utils');
|
||||
const {config, SafeString, errors, i18n, localUtils} = require('../services/proxy');
|
||||
const {buildLinkClasses} = localUtils;
|
||||
|
||||
const managedAttributes = ['href', 'class', 'activeClass', 'parentActiveClass'];
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// # link_class helper
|
||||
const _ = require('lodash');
|
||||
const {config, SafeString, errors, i18n} = require('../services/proxy');
|
||||
const {buildLinkClasses} = require('./utils');
|
||||
const {config, SafeString, errors, i18n, localUtils} = require('../services/proxy');
|
||||
const {buildLinkClasses} = localUtils;
|
||||
|
||||
module.exports = function link_class(options) { // eslint-disable-line camelcase
|
||||
options = options || {};
|
||||
|
@ -1,4 +1,4 @@
|
||||
const helpers = require('../../helpers/register');
|
||||
const helpers = require('../../services/themes/handlebars/register');
|
||||
const routingService = require('../../services/routing');
|
||||
|
||||
module.exports.getInstance = function getInstance() {
|
||||
|
@ -57,12 +57,12 @@ module.exports = {
|
||||
},
|
||||
|
||||
// The local template thing, should this be merged with the channels one?
|
||||
templates: require('../helpers/template'),
|
||||
templates: require('./themes/handlebars/template'),
|
||||
|
||||
// Various utils, needs cleaning up / simplifying
|
||||
socialUrls: require('@tryghost/social-urls'),
|
||||
blogIcon: require('../../server/lib/image/blog-icon'),
|
||||
urlService: require('./url'),
|
||||
urlUtils: require('../../server/lib/url-utils'),
|
||||
localUtils: require('../helpers/utils')
|
||||
localUtils: require('./themes/handlebars/utils')
|
||||
};
|
||||
|
53
core/frontend/services/themes/handlebars/helpers.js
Normal file
53
core/frontend/services/themes/handlebars/helpers.js
Normal file
@ -0,0 +1,53 @@
|
||||
const register = require('./register');
|
||||
const coreHelpers = require('../../../helpers');
|
||||
const registerThemeHelper = register.registerThemeHelper;
|
||||
const registerAsyncThemeHelper = register.registerAsyncThemeHelper;
|
||||
|
||||
let registerAllCoreHelpers;
|
||||
|
||||
registerAllCoreHelpers = function registerAllCoreHelpers() {
|
||||
// Register theme helpers
|
||||
registerThemeHelper('asset', coreHelpers.asset);
|
||||
registerThemeHelper('author', coreHelpers.author);
|
||||
registerThemeHelper('authors', coreHelpers.authors);
|
||||
registerThemeHelper('body_class', coreHelpers.body_class);
|
||||
registerThemeHelper('cancel_link', coreHelpers.cancel_link);
|
||||
registerThemeHelper('concat', coreHelpers.concat);
|
||||
registerThemeHelper('content', coreHelpers.content);
|
||||
registerThemeHelper('date', coreHelpers.date);
|
||||
registerThemeHelper('encode', coreHelpers.encode);
|
||||
registerThemeHelper('excerpt', coreHelpers.excerpt);
|
||||
registerThemeHelper('foreach', coreHelpers.foreach);
|
||||
registerThemeHelper('ghost_foot', coreHelpers.ghost_foot);
|
||||
registerThemeHelper('has', coreHelpers.has);
|
||||
registerThemeHelper('is', coreHelpers.is);
|
||||
registerThemeHelper('img_url', coreHelpers.img_url);
|
||||
registerThemeHelper('lang', coreHelpers.lang);
|
||||
registerThemeHelper('link', coreHelpers.link);
|
||||
registerThemeHelper('link_class', coreHelpers.link_class);
|
||||
registerThemeHelper('meta_description', coreHelpers.meta_description);
|
||||
registerThemeHelper('meta_title', coreHelpers.meta_title);
|
||||
registerThemeHelper('navigation', coreHelpers.navigation);
|
||||
registerThemeHelper('page_url', coreHelpers.page_url);
|
||||
registerThemeHelper('pagination', coreHelpers.pagination);
|
||||
registerThemeHelper('plural', coreHelpers.plural);
|
||||
registerThemeHelper('post_class', coreHelpers.post_class);
|
||||
registerThemeHelper('price', coreHelpers.price);
|
||||
registerThemeHelper('raw', coreHelpers.raw);
|
||||
registerThemeHelper('reading_time', coreHelpers.reading_time);
|
||||
registerThemeHelper('t', coreHelpers.t);
|
||||
registerThemeHelper('tags', coreHelpers.tags);
|
||||
registerThemeHelper('title', coreHelpers.title);
|
||||
registerThemeHelper('twitter_url', coreHelpers.twitter_url);
|
||||
registerThemeHelper('facebook_url', coreHelpers.facebook_url);
|
||||
registerThemeHelper('url', coreHelpers.url);
|
||||
|
||||
// Async theme helpers
|
||||
registerAsyncThemeHelper('ghost_head', coreHelpers.ghost_head);
|
||||
registerAsyncThemeHelper('next_post', coreHelpers.prev_post);
|
||||
registerAsyncThemeHelper('prev_post', coreHelpers.prev_post);
|
||||
registerAsyncThemeHelper('get', coreHelpers.get);
|
||||
};
|
||||
|
||||
module.exports = coreHelpers;
|
||||
module.exports.loadCoreHelpers = registerAllCoreHelpers;
|
@ -1,5 +1,7 @@
|
||||
const Promise = require('bluebird');
|
||||
const {config, hbs, errors, logging} = require('../services/proxy');
|
||||
const hbs = require('../engine');
|
||||
const config = require('../../../../server/config');
|
||||
const {errors, logging} = require('../../../../server/lib/common');
|
||||
|
||||
// Register an async handlebars helper for a given handlebars instance
|
||||
function asyncHelperWrapper(hbs, name, fn) {
|
@ -2,8 +2,8 @@
|
||||
const templates = {};
|
||||
const _ = require('lodash');
|
||||
const errors = require('@tryghost/errors');
|
||||
const hbs = require('../services/themes/engine');
|
||||
const i18n = require('../../server/lib/common/i18n');
|
||||
const hbs = require('../engine');
|
||||
const {i18n} = require('../../../../server/lib/common');
|
||||
|
||||
// Execute a template helper
|
||||
// All template helpers are register as partial view.
|
@ -105,5 +105,6 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
storage: require('./storage'),
|
||||
middleware: require('./middleware')
|
||||
middleware: require('./middleware'),
|
||||
loadCoreHelpers: require('./handlebars/helpers').loadCoreHelpers
|
||||
};
|
||||
|
@ -130,7 +130,7 @@ module.exports = function setupSiteApp(options = {}) {
|
||||
// We do this here, at the top level, because helpers require so much stuff.
|
||||
// Moving this to being inside themes, where it probably should be requires the proxy to be refactored
|
||||
// Else we end up with circular dependencies
|
||||
require('../../../frontend/helpers').loadCoreHelpers();
|
||||
themeService.loadCoreHelpers();
|
||||
debug('Helpers done');
|
||||
|
||||
// Members middleware
|
||||
|
@ -1,6 +1,6 @@
|
||||
const should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
helpers = require('../../../../core/frontend/helpers/register'),
|
||||
helpers = require('../../../../core/frontend/services/themes/handlebars/register'),
|
||||
AppProxy = require('../../../../core/frontend/services/apps/proxy'),
|
||||
routing = require('../../../../core/frontend/services/routing');
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
var should = require('should'),
|
||||
_ = require('lodash'),
|
||||
hbs = require('../../../core/frontend/services/themes/engine'),
|
||||
const should = require('should');
|
||||
const _ = require('lodash');
|
||||
const hbs = require('../../../../../core/frontend/services/themes/engine');
|
||||
|
||||
// Stuff we are testing
|
||||
helpers = require('../../../core/frontend/helpers');
|
||||
const helpers = require('../../../../../core/frontend/helpers');
|
||||
|
||||
describe('Helpers', function () {
|
||||
var hbsHelpers = ['each', 'if', 'unless', 'with', 'helperMissing', 'blockHelperMissing', 'log', 'lookup', 'block', 'contentFor'],
|
@ -1,6 +1,6 @@
|
||||
var should = require('should'),
|
||||
hbs = require('../../../core/frontend/services/themes/engine'),
|
||||
template = require('../../../core/frontend/helpers/template');
|
||||
const should = require('should');
|
||||
const hbs = require('../../../../../core/frontend/services/themes/engine');
|
||||
const template = require('../../../../../core/frontend/services/themes/handlebars/template');
|
||||
|
||||
describe('Helpers Template', function () {
|
||||
it('can execute a template', function () {
|
Loading…
Reference in New Issue
Block a user