Skip to content

Commit

Permalink
Group channel-handling code together
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ErisDS committed Oct 25, 2017
1 parent e659766 commit 05729d2
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/server/blog/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions core/server/controllers/channels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.router = require('./router');
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
});
Expand All @@ -107,4 +107,4 @@ channelsRouter = function router() {
return channelsRouter;
};

module.exports.router = channelsRouter;
module.exports = channelsRouter;
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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/'
Expand Down Expand Up @@ -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/'
Expand Down Expand Up @@ -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/',
Expand Down Expand Up @@ -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/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand All @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/test/utils/channelUtils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 05729d2

Please sign in to comment.