rendrjs / rendr

Render your Backbone.js apps on the client and the server, using Node.js.
MIT License
4.09k stars 312 forks source link

Support another templating solution #9

Open hurrymaplelad opened 11 years ago

hurrymaplelad commented 11 years ago

Nabbed from the TODOs.

I'd love to integrate Teacup for more CoffeeScript bliss. It's hardly the most popular solution but integration should be simple, so I think it's a sensible first step. Including templates directly in the View modules could be fun, since they're already one to one.

Alternatively, we could go big and add pluggable support for the Consolidate.js signature.

Looks like I'll need to hook into view.getTemplate() and maybe write a templateFinder and some helpers.

Biggest questions are where and how to choose a template engine. App smells about right. We could borrow Express's app.engine(extension, function (path, options, callback)) signature. Requiring templates to map to paths seems limiting to me but I might be the minority.

spikebrehm commented 11 years ago

I like this! We should look into consolidate.js more and figure out the API. I'll think about it a bit this week, but glad to see a PR!

hurrymaplelad commented 11 years ago

Great! I'll cobble something together.

ajacksified commented 11 years ago

I've used consolidate.js quite a bit; it can be a little hamfisted in dealing with differences between rendering APIs, but it's also really easy to hack on should we find something wanting. :+1:

hurrymaplelad commented 11 years ago

Got enough together to start a discussion by forking the app-template: https://github.com/hurrymaplelad/rendr-app-template/tree/teacup

Tried to keep glue code contained in /rendr-teacup. There's some configuration for stitch and watch in the Gruntfile.

The custom templateFinder is wired up in my app's BaseView and the custom viewEngine is setup in server/server.js.

Open questions include:

  1. Should custom template adapters be wrapped up in something like /rendr-teacup? If so, can we distill choosing an adapter to 1 line by default, maybe app/app.js, maybe in a config file? Probably tricky to simplify Gruntfile integration without overly strict conventions, but per adapter example configuration might be enough.
  2. The viewEngine is mostly copied from the rendr default. Should we pull out a baseViewEngine or somesuch? It'd need to export all its methods instead of hiding them within the module scope as it does now.
  3. What are the conventions around the layout template? Seems like we could safely assume there will be some layout level template that wraps the app, but keep the name configurable. viewEngine.getLayoutTemplate seems to duplicate some of templateFinder's work. We could have viewEngine hold the name of the layout template ('layout' by default) and delegate to templateFinder for the actual loading, but that risks bloating client code by either sending __layout to the client or asking templateFinder to handle shared and server-only templates differently.

Still exploring Consolidate.js integration.

hurrymaplelad commented 11 years ago

Getting closer. Migrated the whole app-template to teacup + coffeescript. Centralizing configuration in app.coffee. Looks like there's a pretty clear path to choosing a template adapter from a config/ file.

Next step is a pull request on Rendr with rendr-handlebars extracted into a separate node module and configured by default.

spikebrehm commented 11 years ago

Sweet! Thanks Adam. I haven't had a chance to go through this yet but I'll try today or tomorrow.

On Wed, Apr 17, 2013 at 1:06 AM, Adam Hull notifications@github.com wrote:

Getting closer. Migrated the whole app-template to teacup + coffeescripthttps://github.com/hurrymaplelad/rendr-app-template/tree/teacup. Centralizing configuration in app.coffeehttps://github.com/hurrymaplelad/rendr-app-template/blob/teacup/app/app.coffee. Looks like there's a pretty clear path to choosing a template adapter from a config/ file.

Next step is a pull request on Rendr with rendr-handlebars extracted into a separate node module and configured by default.

— Reply to this email directly or view it on GitHubhttps://github.com/airbnb/rendr/issues/9#issuecomment-16492282 .

Spike Brehm Software Engineer www.airbnb.com

San Francisco, CA, USA C: (602) 828-2358 See how Airbnb works https://www.airbnb.com/info/how_it_works

spikebrehm commented 11 years ago

Dang, sorry for the long delay on this. I WILL merge something in in the next few days.

hurrymaplelad commented 11 years ago

Thanks for checkin in, hope its not stressin ya. No real rush on my end. Just don't want to lose momentum.

On May 28, 2013, at 5:23 PM, Spike Brehm notifications@github.com wrote:

Dang, sorry for the long delay on this. I WILL merge something in in the next few days.

— Reply to this email directly or view it on GitHub.

hurrymaplelad commented 11 years ago

56 has been done for a while... I'll knock out a teacup adapter post haste. Thanks @spikebrehm!

spikebrehm commented 11 years ago

Cool! I'd love to sync back up to see how you guys are using it. I'm in the process of prepping a 0.5.0 release which has a number of breaking changes.