classical geek

Turning templates inside out

It was Microsoft’s classic ASP that first made the breakthrough, I think, of turning the CGI program inside out, so that snippets of code were embedded in the HTML, rather than the other way round. Nowadays, it seems so obvious, and every web programming system under the sun does it - PHP, ASP, JSP, Erb, etc. - so why revisit ancient history? We’re all so much more sophisticasted these days, and eschew directly embedding our scripts inside thje page in favour of templates, tag libraries and the like. It’s just second nature.

I mention it now, because my collaborator and general partner-in-crime Tom Locke has just performed a similar sort of inversion, one that looks so obvious in retrospect that I’m wondering why it hasn;’t been invented before. Hobo is a plugin for Ruby on Rails that Tom has developed. I dabble with Rails alongside various other languages such as PHP and umpteen different Java stacks, and I can’t help but think that what Tom’s done with Hobo is applicable to most of them.

Here’s the two-minute elevator pitch (two minutes? it’s a fairly tall building). Let’s suppose that you have a page consisting of several ‘components’ - say a navigation bar, a central content area and a header along the top. With an ordinary templating system, you’d write three template files to represent these regions of the screen, in three separate files, and then stitch them together at runtime. As the navigation system becomes more complicated, then you factor that out into several discrete entities, and break that template into several files, and similarly with any repeating elements in the content, and so on, reductio in absurdum. You end up with a very well-factored app, divided along all the natural joins, but you no longer have a clear picture of the whole.

Hobo turns that inside out, and allows you to retain a single template for the entire page, within which discrete regions are marked by name. It’s then possible to request a re-rendering of individual components within the page for your spiffy Ajax updates, and the system breaks the template into chunks for you. You retain your well-factored code, and you get a good overview of the page as a whole.

Ping. The elevator’s arrived now. If this sounds like something you might be interested in further, then take a look at Tom’s Hobo blog for more details.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by WordPress, Supported by SaveOnRefinance.com