Announcing Nestive – Better Nested Layouts for Rails

Published 27 May 11 by Justin French

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:

  1. The current Rails best practice for nested layouts, as described in the Rails Guides is utterly flawed for anything except the most basic examples
  2. 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 yield)
  • extend (tell your layout or view to extend/inherit the another layout)
  • append (similar to content_for, add stuff onto an area)
  • prepend (the opposite of append, duh)
  • replace (set completely new content for an area)

You can read about all this in much more detail with a bunch of examples in the Nestive README on GitHub, or download the slides from my presentation (sorry there’s no presenter notes).

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!

Options

What is this?

portrait of Justin

This is the online home of Justin French, a designer & web application developer located in Melbourne, Australia. I like finding ways to make things work better. I like clarifying and simplifying. I like to understand how you understand things.

» read more

Subscribe to my feed

Follow me on Twitter

@justinfrench

More Notebook Articles

Show more notebook articles

Search