Live data from Hacker News

Simplify templating with node.js, jsdom 0.2.0 and weld

blog.nodejitsu.com

1–10 of 20 posts

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#4
DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on.

The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own.

If your templating code works by performing manipulations against a DOM, even minor changes to your page structure require to to completely rewrite both the templates and the code that manipulates them. I'd much rather leave my "view" code alone and just alter the template.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#5
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

I'd argue that this isn't really that dissimilar from most simple template engines. It's basically substituting class names for placeholder syntax, though with a bit less flexibility for things like repetitions or conditionals. Though I'd agree that I'd rather just use something like Mustache than this.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#6
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

How do you rationalize including logic in the markup?

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#7
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

I think he just wants to separate the presentation from the logic, which might be good when you don't trust designers re-jiggling things, and you want clean code. Plus, if you're working with a lot of AJAX, it's nice to be able to reproduce the presentation on the server the same way you do it on the client. I suppose keeping the two in sync can be difficult, which is why you probably would only want to render on the server on the initial page request.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#8
http://www.yuiblog.com/blog/2010/09/29/video-glass-node/ This video from David Glass shows why this can be very powerful when code on the front end and the backend. It's pretty straight forward. Check for content. If not generate content. Attach behavior (skipped on the server). render out put (the branch between the server and the front end).

There is an example using express and all kinds of cool business.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#9
http://www.yuiblog.com/blog/2010/09/29/video-glass-node/ This video from David Glass shows why this can be very powerful when code on the front end and the backend. It's pretty straight forward. Check for content. If not generate content. Attach behavior (skipped on the server). render out put (the branch between the server and the front end).

There is an example using express and all kinds of cool business.

Re: Simplify templating with node.js, jsdom 0.2.0 and weld

#10
post #6
post #4

DOM-based templating is a horrible idea, at least for the majority of projects I've ever worked on. The whole point of using templates is to separate your presentation logic from the rest of your application - ideally, you can hand the templates over to a client-side developer/designer and they can re-jiggle everything on their own. If your templating code works by performing manipulations against a DOM, even minor c…

How do you rationalize including logic in the markup?

Presentation logic requires logic. If a designer decides to display a bunch of items as three columns rather than two columns, or to switch the display for a single item vs a number of different items, that's presentation logic. Ideally it should go in the template, if that's where you've chosen to keep it.

With Django, I often find myself writing view logic to support specific presentation tasks (regrouping items in a manner more complicated than Django's {% regroup %} template tag allows, for example). This used to bother me, but then I decided that pragmatism beats purity if you actually want to ship anything.

Post reply on HN