Last night at the monthly Melbourne Ruby meet-up I gave a quick presentation on Nested Layouts (aka Inheritable Layouts, Extensible Layouts, etc). I stepped through a bunch of the options, plugins and strategies available today, then finally showed off a new plugin I’ve been working on called Nestive.
Nestive is a partial answer to two things that have been really bugging me:
- The current Rails best practice for nested layouts, as described in the Rails Guides is utterly flawed for anything except the most basic examples
- I’ve had serious framework envy ever since Jeff Croft’s Django Templates: The Power of Inheritance was published back in 2006
We’re going to have trouble replicating Django’s DSL in ERB/ActionView (with keywords like `block` and `super`), but I think I’ve come up with a pretty tidy DSL involving just four simple methods.
area(declare an area in the layout, similar to
extend(tell your layout or view to extend/inherit the another layout)
content_for, add stuff onto an area)
prepend(the opposite of
replace(set completely new content for an area)
Right now, I’d love help from the community validating the entire concept. Try it out in a small project or a small part of a big project (it doesn’t mess with any of the Rails internals), try it with Haml, report issues, give me feedback on the DSL, etc.
I’m also wondering if it could be wired into Sinatra and other Ruby frameworks, and how it will impact things like Rails 3.1’s content streaming.
Fork it, patch it, break it, create issues, help me write some tests!