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

Move view logic out of templates #56

Closed
jnordberg opened this issue Sep 29, 2012 · 4 comments
Closed

Move view logic out of templates #56

jnordberg opened this issue Sep 29, 2012 · 4 comments
Milestone

Comments

@jnordberg
Copy link
Owner

There needs to be a better way to process the content tree before rendering it. Currently it has to be done in templates. This works well with templating languages like jade that support inline javascript, but for something like mustache you can only create very simple sites without creating a custom plugin.

I propose to introduce a new plugin type, a view plugin. The view takes over the responsibility of rendering from the content plugin. It will basically be the ContentPlugin's current render method.

Quick outline of the new structure:

  • ContentPlugin
    loads and preprocesses content
    provides a 'view' property to tell ws what view to pass it to
  • ViewPlugin
    called with a content plugin instance to render
    should call back with a read stream and a filename to write to
  • TemplatePlugin
    helper plugin passed to the view plugin when rendering

A helper will load all js/coffeescript files in ./views as view plugins but you should also be able to register global view plugins.

And to provide backwards compatibility a default "template" view is available that just renders with the template defined by the content.

It would be great to get some input from you awesome people writing plugins for wintersmith: @smebberson @joefiorini @sfrdmn @mnmly @imothee @jnwng @lhagan @ajpiano @stephenallred @vitch (i hope i didn't miss anyone :)

@stephenallred
Copy link

Sounds good. I guess the view plugin's render method would have the same parameters as the render method on the content plugin currently?
How would the processed content be exposed to the templates?

Having to encode data processing logic like date ordering in templates has been the only negative I've had using Wintersmith (otherwise it's been brilliant, great work!).

@jnordberg
Copy link
Owner Author

Yeah, the processed content would be exposed to the templates by the view, the default view plugin could just be something like:

pageView = (plugin, locals, contents, templates, callback) ->
  template = templates[plugin.template]

  locals.page = plugin
  locals.contents = contents

  template.render locals, callback

@gmaclennan
Copy link

Would this allow a view plugin to be written to expose processed data in the content tree? If a template could access "pre-processed" data in the content tree, like in Jekyll, it would simplify template logic and lower the barrier for getting started with Wintersmith.

Would it be possible to develop a paginator with a pageView? Or would this need a different effort?

jnordberg added a commit that referenced this issue May 22, 2013
Fixes #93, #89, #84, #86, #79, #78, #83, #56, #34, #45, #46
@jnordberg
Copy link
Owner Author

Boom

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

No branches or pull requests

3 participants