Skip to content

Commit

Permalink
Renamed single / post -> entry
Browse files Browse the repository at this point in the history
refs #9192

- an entry is a post or a page, represented by a post model
  • Loading branch information
ErisDS committed Nov 8, 2017
1 parent 187c389 commit f0f0735
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ var utils = require('../utils'),
filters = require('../filters'),
handleError = require('./frontend/error'),
postLookup = require('./frontend/post-lookup'),
renderPost = require('./frontend/render-post'),
renderEntry = require('./frontend/render-entry'),
setRequestIsSecure = require('./frontend/secure');

// This here is a controller.
// It renders entries = individual posts or pages
// The "route" is handled in site/routes.js
module.exports = function singleController(req, res, next) {
module.exports = function entryController(req, res, next) {
// Query database to find post
return postLookup(req.path).then(function then(lookup) {
// Format data 1
Expand Down Expand Up @@ -35,6 +36,6 @@ module.exports = function singleController(req, res, next) {
setRequestIsSecure(req, post);

filters.doFilter('prePostsRender', post, res.locals)
.then(renderPost(req, res));
.then(renderEntry(req, res));
}).catch(handleError(next));
};
4 changes: 2 additions & 2 deletions core/server/controllers/frontend/format-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function formatPageResponse(result) {
}

/**
* similar to formatPageResponse, but for single post pages
* similar to formatPageResponse, but for entries (post or page)
* @return {Object} containing page variables
*/
function formatResponse(post) {
Expand All @@ -38,5 +38,5 @@ function formatResponse(post) {

module.exports = {
channel: formatPageResponse,
single: formatResponse
entry: formatResponse
};
28 changes: 28 additions & 0 deletions core/server/controllers/frontend/render-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var debug = require('ghost-ignition').debug('channels:render-post'),
templates = require('./templates'),
formatResponse = require('./format-response'),
setResponseContext = require('./context');
/*
* Sets the response context around an entry (post or page)
* and renders it with the correct template.
* Used by post preview and entry methods.
* Returns a function that takes the entry to be rendered.
*/
module.exports = function renderEntry(req, res) {
debug('renderEntry called');
return function renderEntry(entry) {
// Renderer begin
// Format data 2 - 1 is in preview/entry
var response = formatResponse.entry(entry);

// Context
setResponseContext(req, res, response);

// Template
res.template = templates.entry(entry);

// Render Call
debug('Rendering view: ' + res.template);
res.render(res.template, response);
};
};
29 changes: 0 additions & 29 deletions core/server/controllers/frontend/render-post.js

This file was deleted.

10 changes: 5 additions & 5 deletions core/server/controllers/frontend/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function getChannelTemplateHierarchy(channelOpts) {
}

/**
* ## Get Single Template Hierarchy
* ## Get Entry Template Hierarchy
*
* Fetch the ordered list of templates that can be used to render this request.
* 'post' is the default / fallback
Expand All @@ -72,7 +72,7 @@ function getChannelTemplateHierarchy(channelOpts) {
* @param {Object} postObject
* @returns {String[]}
*/
function getSingleTemplateHierarchy(postObject) {
function getEntryTemplateHierarchy(postObject) {
var templateList = ['post'],
slugTemplate = 'post-' + postObject.slug;

Expand Down Expand Up @@ -121,8 +121,8 @@ function pickTemplate(templateList, fallback) {
return template;
}

function getTemplateForSingle(postObject) {
var templateList = getSingleTemplateHierarchy(postObject),
function getTemplateForEntry(postObject) {
var templateList = getEntryTemplateHierarchy(postObject),
fallback = templateList[templateList.length - 1];
return pickTemplate(templateList, fallback);
}
Expand All @@ -141,7 +141,7 @@ function getTemplateForError(statusCode) {

module.exports = {
channel: getTemplateForChannel,
single: getTemplateForSingle,
entry: getTemplateForEntry,
error: getTemplateForError,
pickTemplate: pickTemplate
};
2 changes: 1 addition & 1 deletion core/server/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preview: require('./preview'),
single: require('./single')
entry: require('./entry')
};
4 changes: 2 additions & 2 deletions core/server/controllers/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var api = require('../api'),
utils = require('../utils'),
filters = require('../filters'),
handleError = require('./frontend/error'),
renderPost = require('./frontend/render-post'),
renderEntry = require('./frontend/render-entry'),
setRequestIsSecure = require('./frontend/secure');

// This here is a controller.
Expand Down Expand Up @@ -37,6 +37,6 @@ module.exports = function previewController(req, res, next) {
setRequestIsSecure(req, post);

filters.doFilter('prePostsRender', post, res.locals)
.then(renderPost(req, res));
.then(renderEntry(req, res));
}).catch(handleError(next));
};
4 changes: 2 additions & 2 deletions core/server/site/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = function siteRouter() {
// Apps - register sub-router
router.use(apps.router);

// Default - register single controller as route
router.get('*', controllers.single);
// Default - register entry controller as route
router.get('*', controllers.entry);

return router;
};
Loading

0 comments on commit f0f0735

Please sign in to comment.