Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced renderer to DRY up controllers #9235

Merged
merged 3 commits into from
Nov 10, 2017
Merged

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Nov 10, 2017

This PR reduces code duplication all over the codebase and introduces a couple of new concepts - I'm not 100% about them yet so they kind of have temporary names :) Over the next few commits hopefully the concepts will solidify and things will get real names.

To start, we now have a renderer. This has the job of handling everything that happens once we've got our data ready to render:

  • It figures out the context, stored in res.locals.context
  • It figures out which template to use, for now stored in res._template
  • It could do some data formatting, or filtering of res.locals
  • It could/should then offer an opportunity to filter/override that data
  • It does the call to res.render.

Most interestingly, 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.

I have a plan to move this forward into a more standardised concept of controllers. This changeset makes sense on its own for now tho...

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

refs TryGhost#5091, TryGhost#9192

- Renderer figures out templates, contexts, and does a render call
- Renderer will handle everything after data is fetched and semi-processed
- For now it only does the last 2 steps
- TODO: it will eventually do more steps!!
- Templating is now handled with a single function
- Introduces a res.locals.route object for config - not sure about this yet!
@ErisDS ErisDS merged commit 98f5ae0 into TryGhost:master Nov 10, 2017
@ErisDS ErisDS deleted the renderer branch November 10, 2017 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant