Don't use api to lookup theme in frontend controller
no issue - small fix, we already have the info, no need to look it up again
This commit is contained in:
parent
6474bba64e
commit
d6fb21fa28
@ -34,13 +34,12 @@ var _ = require('lodash'),
|
||||
*/
|
||||
function renderPost(req, res) {
|
||||
return function renderPost(post) {
|
||||
return getActiveThemePaths().then(function then(paths) {
|
||||
var view = template.getThemeViewForPost(paths, post),
|
||||
response = formatResponse.single(post);
|
||||
var paths = getActiveThemePaths(req),
|
||||
view = template.getThemeViewForPost(paths, post),
|
||||
response = formatResponse.single(post);
|
||||
|
||||
setResponseContext(req, res, response);
|
||||
res.render(view, response);
|
||||
});
|
||||
setResponseContext(req, res, response);
|
||||
res.render(view, response);
|
||||
};
|
||||
}
|
||||
|
||||
@ -91,23 +90,23 @@ function renderChannel(channelOpts) {
|
||||
|
||||
// @TODO: properly design these filters
|
||||
filters.doFilter('prePostsRender', result.posts, res.locals).then(function then(posts) {
|
||||
getActiveThemePaths().then(function then(paths) {
|
||||
// Calculate which template to use to render the data
|
||||
var view = 'index';
|
||||
if (channelOpts.firstPageTemplate && paths.hasOwnProperty(channelOpts.firstPageTemplate + '.hbs')) {
|
||||
view = (pageParam > 1) ? 'index' : channelOpts.firstPageTemplate;
|
||||
} else if (channelOpts.slugTemplate) {
|
||||
view = template.getThemeViewForChannel(paths, channelOpts.name, slugParam);
|
||||
} else if (paths.hasOwnProperty(channelOpts.name + '.hbs')) {
|
||||
view = channelOpts.name;
|
||||
}
|
||||
var paths = getActiveThemePaths(req),
|
||||
view = 'index';
|
||||
|
||||
// Do final data formatting and then render
|
||||
result.posts = posts;
|
||||
result = formatResponse.channel(result);
|
||||
setResponseContext(req, res);
|
||||
res.render(view, result);
|
||||
});
|
||||
// Calculate which template to use to render the data
|
||||
if (channelOpts.firstPageTemplate && paths.hasOwnProperty(channelOpts.firstPageTemplate + '.hbs')) {
|
||||
view = (pageParam > 1) ? 'index' : channelOpts.firstPageTemplate;
|
||||
} else if (channelOpts.slugTemplate) {
|
||||
view = template.getThemeViewForChannel(paths, channelOpts.name, slugParam);
|
||||
} else if (paths.hasOwnProperty(channelOpts.name + '.hbs')) {
|
||||
view = channelOpts.name;
|
||||
}
|
||||
|
||||
// Do final data formatting and then render
|
||||
result.posts = posts;
|
||||
result = formatResponse.channel(result);
|
||||
setResponseContext(req, res);
|
||||
res.render(view, result);
|
||||
});
|
||||
}).catch(handleError(next));
|
||||
};
|
||||
@ -248,20 +247,20 @@ frontendControllers = {
|
||||
}).catch(handleError(next));
|
||||
},
|
||||
private: function private(req, res) {
|
||||
var defaultPage = path.resolve(config.paths.adminViews, 'private.hbs');
|
||||
return getActiveThemePaths().then(function then(paths) {
|
||||
var data = {};
|
||||
if (res.error) {
|
||||
data.error = res.error;
|
||||
}
|
||||
var defaultPage = path.resolve(config.paths.adminViews, 'private.hbs'),
|
||||
paths = getActiveThemePaths(req),
|
||||
data = {};
|
||||
|
||||
setResponseContext(req, res);
|
||||
if (paths.hasOwnProperty('private.hbs')) {
|
||||
return res.render('private', data);
|
||||
} else {
|
||||
return res.render(defaultPage, data);
|
||||
}
|
||||
});
|
||||
if (res.error) {
|
||||
data.error = res.error;
|
||||
}
|
||||
|
||||
setResponseContext(req, res);
|
||||
if (paths.hasOwnProperty('private.hbs')) {
|
||||
return res.render('private', data);
|
||||
} else {
|
||||
return res.render(defaultPage, data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,22 +1,14 @@
|
||||
var api = require('../../api'),
|
||||
config = require('../../config');
|
||||
var config = require('../../config');
|
||||
|
||||
/**
|
||||
* Returns the paths object of the active theme via way of a promise.
|
||||
* @return {Promise} The promise resolves with the value of the paths.
|
||||
*/
|
||||
function getActiveThemePaths() {
|
||||
return api.settings.read({
|
||||
key: 'activeTheme',
|
||||
context: {
|
||||
internal: true
|
||||
}
|
||||
}).then(function then(response) {
|
||||
var activeTheme = response.settings[0],
|
||||
paths = config.paths.availableThemes[activeTheme.value];
|
||||
function getActiveThemePaths(req) {
|
||||
var activeTheme = req.app.get('activeTheme'),
|
||||
paths = config.paths.availableThemes[activeTheme];
|
||||
|
||||
return paths;
|
||||
});
|
||||
return paths;
|
||||
}
|
||||
|
||||
module.exports = getActiveThemePaths;
|
||||
|
@ -84,7 +84,6 @@ describe('Public API', function () {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
console.log('tags:', res.body.tags);
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
var jsonResponse = res.body;
|
||||
jsonResponse.tags.should.exist;
|
||||
|
@ -167,12 +167,6 @@ describe('Frontend Controller', function () {
|
||||
});
|
||||
|
||||
apiSettingsStub = sandbox.stub(api.settings, 'read');
|
||||
apiSettingsStub.withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'activeTheme',
|
||||
value: 'casper'
|
||||
}]
|
||||
}));
|
||||
apiSettingsStub.withArgs('postsPerPage').returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'postsPerPage',
|
||||
@ -181,6 +175,7 @@ describe('Frontend Controller', function () {
|
||||
}));
|
||||
|
||||
req = {
|
||||
app: {get: function () { return 'casper';}},
|
||||
path: '/', params: {}, route: {}
|
||||
};
|
||||
|
||||
@ -257,13 +252,6 @@ describe('Frontend Controller', function () {
|
||||
|
||||
apiSettingsStub = sandbox.stub(api.settings, 'read');
|
||||
|
||||
apiSettingsStub.withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'activeTheme',
|
||||
value: 'casper'
|
||||
}]
|
||||
}));
|
||||
|
||||
apiSettingsStub.withArgs('postsPerPage').returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'postsPerPage',
|
||||
@ -278,6 +266,7 @@ describe('Frontend Controller', function () {
|
||||
}));
|
||||
|
||||
req = {
|
||||
app: {get: function () { return 'casper';}},
|
||||
path: '/', params: {}, route: {}
|
||||
};
|
||||
|
||||
@ -507,12 +496,6 @@ describe('Frontend Controller', function () {
|
||||
});
|
||||
|
||||
apiSettingsStub = sandbox.stub(api.settings, 'read');
|
||||
apiSettingsStub.withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'activeTheme',
|
||||
value: 'casper'
|
||||
}]
|
||||
}));
|
||||
|
||||
casper = {
|
||||
assets: null,
|
||||
@ -524,6 +507,7 @@ describe('Frontend Controller', function () {
|
||||
};
|
||||
|
||||
req = {
|
||||
app: {get: function () { return 'casper'; }},
|
||||
path: '/', params: {}, route: {}
|
||||
};
|
||||
|
||||
@ -1008,23 +992,20 @@ describe('Frontend Controller', function () {
|
||||
});
|
||||
|
||||
it('will render post via /:year/:slug/', function (done) {
|
||||
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY'),
|
||||
req = {
|
||||
path: '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/',
|
||||
route: {
|
||||
path: '*'
|
||||
},
|
||||
params: {}
|
||||
},
|
||||
res = {
|
||||
locals: {},
|
||||
render: function (view, context) {
|
||||
view.should.equal('post');
|
||||
should.exist(context.post);
|
||||
context.post.should.equal(mockPosts[1].posts[0]);
|
||||
done();
|
||||
}
|
||||
};
|
||||
var date = moment(mockPosts[1].posts[0].published_at).format('YYYY');
|
||||
|
||||
req.path = '/' + [date, mockPosts[1].posts[0].slug].join('/') + '/';
|
||||
req.route = {path: '*'};
|
||||
|
||||
res = {
|
||||
locals: {},
|
||||
render: function (view, context) {
|
||||
view.should.equal('post');
|
||||
should.exist(context.post);
|
||||
context.post.should.equal(mockPosts[1].posts[0]);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
frontend.single(req, res, failTest(done));
|
||||
});
|
||||
@ -1271,6 +1252,7 @@ describe('Frontend Controller', function () {
|
||||
};
|
||||
|
||||
req = {
|
||||
app: {get: function () { return 'casper'; }},
|
||||
route: {path: '/private/?r=/'},
|
||||
query: {r: ''},
|
||||
params: {}
|
||||
@ -1279,12 +1261,6 @@ describe('Frontend Controller', function () {
|
||||
defaultPath = path.join(config.paths.appRoot, '/core/server/views/private.hbs');
|
||||
|
||||
apiSettingsStub = sandbox.stub(api.settings, 'read');
|
||||
apiSettingsStub.withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'activeTheme',
|
||||
value: 'casper'
|
||||
}]
|
||||
}));
|
||||
});
|
||||
|
||||
it('Should render default password page when theme has no password template', function (done) {
|
||||
@ -1389,14 +1365,8 @@ describe('Frontend Controller', function () {
|
||||
|
||||
apiSettingsStub = sandbox.stub(api.settings, 'read');
|
||||
|
||||
apiSettingsStub.withArgs(sinon.match.has('key', 'activeTheme')).returns(Promise.resolve({
|
||||
settings: [{
|
||||
key: 'activeTheme',
|
||||
value: 'casper'
|
||||
}]
|
||||
}));
|
||||
|
||||
req = {
|
||||
app: {get: function () {return 'casper'; }},
|
||||
path: '/', params: {}, route: {}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user