-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced renderer to DRY up controllers (#9235)
refs #5091, #9192 - Renderer figures out templates, contexts, and does a render call - Templating is now handled with a single function - Context call is made in the renderer Note: to make this work, all controllers now define a little bit of config, currently stored in res._route. (That's a totally temporary location, as is res._template... when a sensible naming convention reveals itself I'll get rid of the weird _). This exposes a type and for custom routes a template name & default.
- Loading branch information
Showing
12 changed files
with
353 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
var debug = require('ghost-ignition').debug('channels:render'), | ||
formatResponse = require('./format-response'), | ||
setResponseContext = require('./context'), | ||
templates = require('./templates'); | ||
renderer = require('./renderer'); | ||
|
||
module.exports = function renderChannel(req, res) { | ||
debug('renderChannel called'); | ||
return function renderChannel(result) { | ||
// Renderer begin | ||
// Format data 2 | ||
// Do final data formatting and then render | ||
result = formatResponse.channel(result); | ||
|
||
// Context | ||
setResponseContext(req, res); | ||
|
||
// Template | ||
res.template = templates.channel(res.locals.channel); | ||
var data = formatResponse.channel(result); | ||
|
||
// Render Call | ||
debug('Rendering view: ' + res.template); | ||
res.render(res.template, result); | ||
return renderer(req, res, data); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var debug = require('ghost-ignition').debug('renderer'), | ||
setContext = require('./context'), | ||
templates = require('./templates'); | ||
|
||
module.exports = function renderer(req, res, data) { | ||
// Context | ||
setContext(req, res, data); | ||
|
||
// Template | ||
templates.setTemplate(req, res, data); | ||
|
||
// Render Call | ||
debug('Rendering template: ' + res._template + ' for: ' + req.originalUrl); | ||
debug('res.locals', res.locals); | ||
res.render(res._template, data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.