From 05729d2f292711363d76864d5031e7a0f23e02d8 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 25 Oct 2017 16:22:46 +0100 Subject: [PATCH] Group channel-handling code together refs #5091 - Move all of the code to do with handling channels into one folder - Still keeping all the shared/simlar code for rendering etc inside weird frontend folder until I am sure what this will look like --- core/server/blog/routes.js | 2 +- .../{frontend => channels}/config.channels.json | 0 core/server/controllers/channels/index.js | 1 + .../channel-config.js => channels/loader.js} | 0 .../{frontend/channels.js => channels/router.js} | 8 ++++---- .../{frontend => channels}/custom_channels_spec.js | 12 ++++++------ .../loader_spec.js} | 6 +++--- .../channels_spec.js => channels/router_spec.js} | 2 +- core/test/utils/channelUtils.js | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) rename core/server/controllers/{frontend => channels}/config.channels.json (100%) create mode 100644 core/server/controllers/channels/index.js rename core/server/controllers/{frontend/channel-config.js => channels/loader.js} (100%) rename core/server/controllers/{frontend/channels.js => channels/router.js} (95%) rename core/test/unit/controllers/{frontend => channels}/custom_channels_spec.js (96%) rename core/test/unit/controllers/{frontend/channel-config_spec.js => channels/loader_spec.js} (75%) rename core/test/unit/controllers/{frontend/channels_spec.js => channels/router_spec.js} (99%) diff --git a/core/server/blog/routes.js b/core/server/blog/routes.js index 40c6f3ba7471..918af53f4c7c 100644 --- a/core/server/blog/routes.js +++ b/core/server/blog/routes.js @@ -2,7 +2,7 @@ var express = require('express'), path = require('path'), config = require('../config'), controllers = require('../controllers'), - channels = require('../controllers/frontend/channels'), + channels = require('../controllers/channels'), utils = require('../utils'); module.exports = function frontendRoutes() { diff --git a/core/server/controllers/frontend/config.channels.json b/core/server/controllers/channels/config.channels.json similarity index 100% rename from core/server/controllers/frontend/config.channels.json rename to core/server/controllers/channels/config.channels.json diff --git a/core/server/controllers/channels/index.js b/core/server/controllers/channels/index.js new file mode 100644 index 000000000000..370c476cf504 --- /dev/null +++ b/core/server/controllers/channels/index.js @@ -0,0 +1 @@ +module.exports.router = require('./router'); diff --git a/core/server/controllers/frontend/channel-config.js b/core/server/controllers/channels/loader.js similarity index 100% rename from core/server/controllers/frontend/channel-config.js rename to core/server/controllers/channels/loader.js diff --git a/core/server/controllers/frontend/channels.js b/core/server/controllers/channels/router.js similarity index 95% rename from core/server/controllers/frontend/channels.js rename to core/server/controllers/channels/router.js index 7b34660bb622..d6144f1b4f27 100644 --- a/core/server/controllers/frontend/channels.js +++ b/core/server/controllers/channels/router.js @@ -5,8 +5,8 @@ var express = require('express'), i18n = require('../../i18n'), rss = require('../../data/xml/rss'), utils = require('../../utils'), - channelConfig = require('./channel-config'), - renderChannel = require('./render-channel'), + channelLoader = require('./loader'), + renderChannel = require('../frontend/render-channel'), rssRouter, channelsRouter; @@ -95,7 +95,7 @@ function buildChannelRouter(channel) { channelsRouter = function router() { var channelsRouter = express.Router({mergeParams: true}); - _.each(channelConfig.list(), function (channel) { + _.each(channelLoader.list(), function (channel) { var channelRoute = channel.route.replace(/:rkw-([a-zA-Z]+)/, function (fullMatch, keyword) { return config.get('routeKeywords')[keyword]; }); @@ -107,4 +107,4 @@ channelsRouter = function router() { return channelsRouter; }; -module.exports.router = channelsRouter; +module.exports = channelsRouter; diff --git a/core/test/unit/controllers/frontend/custom_channels_spec.js b/core/test/unit/controllers/channels/custom_channels_spec.js similarity index 96% rename from core/test/unit/controllers/frontend/custom_channels_spec.js rename to core/test/unit/controllers/channels/custom_channels_spec.js index 0e3a75f49944..6c1343072f72 100644 --- a/core/test/unit/controllers/frontend/custom_channels_spec.js +++ b/core/test/unit/controllers/channels/custom_channels_spec.js @@ -3,8 +3,8 @@ var should = require('should'), // jshint ignore:line _ = require('lodash'), // Stuff we are testing - channelConfig = require('../../../../server/controllers/frontend/channel-config'), - channels = require('../../../../server/controllers/frontend/channels'), + channelLoader = require('../../../../server/controllers/channels/loader'), + channels = require('../../../../server/controllers/channels'), sandbox = sinon.sandbox.create(); @@ -135,7 +135,7 @@ describe('Custom Channels', function () { }); it('allows basic custom config', function () { - sandbox.stub(channelConfig, 'list').returns({ + sandbox.stub(channelLoader, 'list').returns({ home: { name: 'home', route: '/home/' @@ -182,7 +182,7 @@ describe('Custom Channels', function () { }); it('allow multiple channels to be defined', function () { - sandbox.stub(channelConfig, 'list').returns({ + sandbox.stub(channelLoader, 'list').returns({ home: { name: 'home', route: '/home/' @@ -247,7 +247,7 @@ describe('Custom Channels', function () { }); it('allows rss to be disabled', function () { - sandbox.stub(channelConfig, 'list').returns({ + sandbox.stub(channelLoader, 'list').returns({ home: { name: 'home', route: '/home/', @@ -295,7 +295,7 @@ describe('Custom Channels', function () { }); it('allows pagination to be disabled', function () { - sandbox.stub(channelConfig, 'list').returns({ + sandbox.stub(channelLoader, 'list').returns({ home: { name: 'home', route: '/home/', diff --git a/core/test/unit/controllers/frontend/channel-config_spec.js b/core/test/unit/controllers/channels/loader_spec.js similarity index 75% rename from core/test/unit/controllers/frontend/channel-config_spec.js rename to core/test/unit/controllers/channels/loader_spec.js index 5bc426e7f11b..0153082bf2bf 100644 --- a/core/test/unit/controllers/frontend/channel-config_spec.js +++ b/core/test/unit/controllers/channels/loader_spec.js @@ -2,13 +2,13 @@ var should = require('should'), // jshint ignore:line _ = require('lodash'), rewire = require('rewire'), channelUtils = require('../../../utils/channelUtils'), - channelConfig = rewire('../../../../server/controllers/frontend/channel-config'); + channelLoader = rewire('../../../../server/controllers/channels/loader'); describe('Channel Config', function () { var channelReset; before(function () { - channelReset = channelConfig.__set__('loadConfig', function () { + channelReset = channelLoader.__set__('loadConfig', function () { return channelUtils.getDefaultChannels(); }); }); @@ -18,7 +18,7 @@ describe('Channel Config', function () { }); it('should build a list of channels', function () { - var channels = channelConfig.list(); + var channels = channelLoader.list(); channels.should.be.an.Object(); _.map(channels, 'name').should.eql(['index', 'tag', 'author']); diff --git a/core/test/unit/controllers/frontend/channels_spec.js b/core/test/unit/controllers/channels/router_spec.js similarity index 99% rename from core/test/unit/controllers/frontend/channels_spec.js rename to core/test/unit/controllers/channels/router_spec.js index 2d0684250cfb..a421e2cabb6c 100644 --- a/core/test/unit/controllers/frontend/channels_spec.js +++ b/core/test/unit/controllers/channels/router_spec.js @@ -4,7 +4,7 @@ var should = require('should'), _ = require('lodash'), // Stuff we are testing - channels = require('../../../../server/controllers/frontend/channels'), + channels = require('../../../../server/controllers/channels'), api = require('../../../../server/api'), themes = require('../../../../server/themes'), sandbox = sinon.sandbox.create(); diff --git a/core/test/utils/channelUtils.js b/core/test/utils/channelUtils.js index b06c168dfb6c..84c91cad4e40 100644 --- a/core/test/utils/channelUtils.js +++ b/core/test/utils/channelUtils.js @@ -1,4 +1,4 @@ -var defaultChannels = require('../../server/controllers/frontend/config.channels.json'); +var defaultChannels = require('../../server/controllers/channels/config.channels.json'); // This is a function to get a fake or test channel // It's currently based on the default config in Ghost itself