HOW I: Wrap content sections using blocks and then nest them


This is the type of code that I’m excited when it works but hopefully
get some suggestions on how to do it better. Last time, the code was a
to “ferocious” and I was missing out on a built in feature to rails that
didn’t know about.

This one is a bit more complex… to factor out all the markup for
sections of the site I have a bunch of view helpers (thanks to Ryan
Bates: that are setup to take blocks. Most
my views start off like this:

<% content_for :left do %>
<% conversations_area do %>

<% end %>
<% end %>

This makes is tremendously easy to DRY up repeated code that doesn’t
warrant its own layout bit is still fairly consistent.

To complicate this, however, we have different sections of the site that
scoped to a specifc group. For example, a group could have its own
conversations area. Using RESTful routes I’m reusing all the same
controllers and views for both. Now the problem is, if I’m at the group
level I need to use the group’s view helper. Using lambdas and blocks
is pretty easy:

<% content_for :left do %>

<!-- Define the content to pass to the view helper -->
<% content = lambda do %>
    <!-- main content here -->
<% end %>

<!-- Determine which view helper to pass the block to -->
<% if @group %>
    <% groups_area(@group) { } %>
<% else %>
    <% conversations_area(@forum,@group) { } %>
<% end %>

<% end %>

So far this is working great. Any ideas on how to improve it? Bonus

Why don’t here documents work in the helper files?