<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Blocks and Helpers, a Lovely Combination</title>
	<atom:link href="http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/feed" rel="self" type="application/rss+xml" />
	<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 29 Jul 2010 17:19:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<item>
		<title>By: Adam</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-71</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Thu, 25 Jan 2007 12:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-71</guid>
		<description>That&#039;s an interesting solution as well; however, it has an unwanted side-effect: If you use the same @with_partial :sidebar@ in more than one place on your page, you end up with duplicate information.

The first time you call it, it works great.  The second time you call it, it prints out the data from the first block AND the second block.  The third time it renders the block information from the first call AND the second call AND the third; and so on and so on.</description>
		<content:encoded><![CDATA[<p>That&#8217;s an interesting solution as well; however, it has an unwanted side-effect: If you use the same @with_partial :sidebar@ in more than one place on your page, you end up with duplicate information.</p>
<p>The first time you call it, it works great.  The second time you call it, it prints out the data from the first block AND the second block.  The third time it renders the block information from the first call AND the second call AND the third; and so on and so on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ronie Uliana</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-70</link>
		<dc:creator>Ronie Uliana</dc:creator>
		<pubDate>Wed, 24 Jan 2007 15:09:26 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-70</guid>
		<description>You can use these 4 lines in your ApplicationHelper:

&lt;pre&gt;
def with_partial(name, options = nil, &amp;block)
  content_for(name.to_sym, &amp;block)
  concat(render(:partial =&gt; name.to_s, :locals =&gt; options), block.binding)
end
&lt;/pre&gt;

Then your partial could be:
&lt;pre&gt;
  &lt;% with_partial :sidebar, :title =&gt; &#039;Hello word&#039; do %&gt;
    &lt;p&gt;And now back to the way I was doing things before&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;Item&lt;/li&gt;
      &lt;li&gt;Item&lt;/li&gt;
      &lt;li&gt;Item&lt;/li&gt;
    &lt;/ul&gt;
  &lt;% end %&gt;
&lt;/pre&gt;

And the partial _sidebar.rhtml could be:

&lt;pre&gt;
  &lt;div class=&quot;sidebar&quot;&gt;
    &lt;div class=&quot;bottom&quot;&gt;
      &lt;h3&gt;&lt;%= title %&gt;&lt;/h3&gt;
      &lt;div class=&quot;body&quot;&gt;
        &lt;%= yield :sidebar %&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>You can use these 4 lines in your ApplicationHelper:</p>
<pre>
def with_partial(name, options = nil, &#038;block)
  content_for(name.to_sym, &#038;block)
  concat(render(:partial => name.to_s, :locals => options), block.binding)
end
</pre>
<p>Then your partial could be:</p>
<pre>
  < % with_partial :sidebar, :title => 'Hello word' do %>

And now back to the way I was doing things before
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>

  < % end %>
</pre>
<p>And the partial _sidebar.rhtml could be:</p>
<pre>
<div class="sidebar">
<div class="bottom">
<h3>< %= title %></h3>
<div class="body">
        < %= yield :sidebar %>
      </div>
</div>
</div>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ron Green</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-69</link>
		<dc:creator>Ron Green</dc:creator>
		<pubDate>Tue, 23 Jan 2007 17:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-69</guid>
		<description>Thanks for this post! I was just looking for a way to encapsulate the opening and closing div elements needed for a rounded box design. This keeps those elements coupled whle yielding for the div contents! Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks for this post! I was just looking for a way to encapsulate the opening and closing div elements needed for a rounded box design. This keeps those elements coupled whle yielding for the div contents! Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-65</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Tue, 23 Jan 2007 15:05:33 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-65</guid>
		<description>*Steve*:  Good point.  I will fix that up so I&#039;m not doing so many @concat@ calls

*Logan*:  You&#039;re right.  I had my terms mixed up.  Thanks for the heads up.</description>
		<content:encoded><![CDATA[<p>*Steve*:  Good point.  I will fix that up so I&#8217;m not doing so many @concat@ calls</p>
<p>*Logan*:  You&#8217;re right.  I had my terms mixed up.  Thanks for the heads up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-68</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Tue, 23 Jan 2007 12:43:22 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-68</guid>
		<description>*Branden*:  That would be a good idea to create a generic implementation, more or less.  With a little tweaking that could be awesome.

*Jules*: there is that, but it&#039;s not something that can be cached as a fragment.

*John*: Look at the &quot;@concat@ method&quot;:http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M000611.  It&#039;s more of a function of Binding than it is a String&#039;s concat.  I got this syntax from rails&#039; &quot;@form_for@ method&quot;:http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000491 and I&#039;m not 100% sure how Bindings work as of yet.</description>
		<content:encoded><![CDATA[<p>*Branden*:  That would be a good idea to create a generic implementation, more or less.  With a little tweaking that could be awesome.</p>
<p>*Jules*: there is that, but it&#8217;s not something that can be cached as a fragment.</p>
<p>*John*: Look at the &#8220;@concat@ method&#8221;:http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M000611.  It&#8217;s more of a function of Binding than it is a String&#8217;s concat.  I got this syntax from rails&#8217; &#8220;@form_for@ method&#8221;:http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000491 and I&#8217;m not 100% sure how Bindings work as of yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-67</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 23 Jan 2007 11:46:38 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-67</guid>
		<description>I&#039;m having trouble understanding:
concat(start, block.binding)

Wouldn&#039;t this append start after the block&#039;s text?  If it doesn&#039;t, then how is it possible that this works?
concat(end, block.binding)

wouldn&#039;t the end go at the front of it all?  sorry, somewhat confused by concat&#039;s and bindings.</description>
		<content:encoded><![CDATA[<p>I&#8217;m having trouble understanding:<br />
concat(start, block.binding)</p>
<p>Wouldn&#8217;t this append start after the block&#8217;s text?  If it doesn&#8217;t, then how is it possible that this works?<br />
concat(end, block.binding)</p>
<p>wouldn&#8217;t the end go at the front of it all?  sorry, somewhat confused by concat&#8217;s and bindings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jules</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-66</link>
		<dc:creator>Jules</dc:creator>
		<pubDate>Tue, 23 Jan 2007 11:18:28 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-66</guid>
		<description>Rails already supports this: @content_for :sidebar do ... end@</description>
		<content:encoded><![CDATA[<p>Rails already supports this: @content_for :sidebar do &#8230; end@</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Branden Timm</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-64</link>
		<dc:creator>Branden Timm</dc:creator>
		<pubDate>Tue, 23 Jan 2007 09:47:26 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-64</guid>
		<description>How about something like this, to really embrace the functionality :) ?  Where param html is an array of first-level div lines...&lt;br/&gt;

def create_sidebar(html, &amp;block)&lt;br/&gt;
&#160;&#160;raise ArgumentError, &quot;Missing block&quot; unless block_given?&lt;br/&gt;
&#160;&#160;case html.length&lt;br/&gt;
&#160;&#160;when 1&lt;br/&gt;
&#160;&#160;&#160;&#160;concat(html[0], block.binding)&lt;br/&gt;
&#160;&#160;&#160;&#160;block.call&lt;br/&gt;
&#160;&#160;&#160;&#160;concat(&#039;&lt;/div&gt;&#039;, block.binding)&lt;br/&gt;
&#160;&#160;else&lt;br/&gt;
&#160;&#160;&#160;&#160;concat(html[0], block.binding)&lt;br/&gt;
&#160;&#160;&#160;&#160;create_sidebar(html[1..html.length], block)&lt;br/&gt;
&#160;&#160;&#160;&#160;concat(&#039;&lt;/div&gt;&#039;, block.binding)&lt;br/&gt;
&#160;&#160;end&lt;br/&gt;
end&lt;br/&gt;

My ruby is a little rusty so this isnt the most elegant implementation im sure...but the point remains that it feels natural to write nested div elements using a recursive algorithm.</description>
		<content:encoded><![CDATA[<p>How about something like this, to really embrace the functionality :) ?  Where param html is an array of first-level div lines&#8230;</p>
<p>def create_sidebar(html, &#038;block)<br />
&nbsp;&nbsp;raise ArgumentError, &#8220;Missing block&#8221; unless block_given?<br />
&nbsp;&nbsp;case html.length<br />
&nbsp;&nbsp;when 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;concat(html[0], block.binding)<br />
&nbsp;&nbsp;&nbsp;&nbsp;block.call<br />
&nbsp;&nbsp;&nbsp;&nbsp;concat(&#8216;&lt;/div&gt;&#8217;, block.binding)<br />
&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;concat(html[0], block.binding)<br />
&nbsp;&nbsp;&nbsp;&nbsp;create_sidebar(html[1..html.length], block)<br />
&nbsp;&nbsp;&nbsp;&nbsp;concat(&#8216;&lt;/div&gt;&#8217;, block.binding)<br />
&nbsp;&nbsp;end<br />
end</p>
<p>My ruby is a little rusty so this isnt the most elegant implementation im sure&#8230;but the point remains that it feels natural to write nested div elements using a recursive algorithm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Logan Capaldo</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-63</link>
		<dc:creator>Logan Capaldo</dc:creator>
		<pubDate>Tue, 23 Jan 2007 09:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-63</guid>
		<description>Pretty sure you mean &quot;interface&quot; when you say &quot;implementation&quot;. (The implementation would be the code in def sidebar ...)</description>
		<content:encoded><![CDATA[<p>Pretty sure you mean &#8220;interface&#8221; when you say &#8220;implementation&#8221;. (The implementation would be the code in def sidebar &#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://shifteleven.com/articles/2007/01/22/blocks-and-helpers-a-lovely-combination/comment-page-1#comment-62</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 23 Jan 2007 08:27:31 +0000</pubDate>
		<guid isPermaLink="false">http://dev.fecalrod.com/?p=25#comment-62</guid>
		<description>This is really nice.  Thanks for the tutorial.  The only thing that it would be nice to clean up is the html inside the helper.  Having to concatenate strings of html together is kind of tough to read.</description>
		<content:encoded><![CDATA[<p>This is really nice.  Thanks for the tutorial.  The only thing that it would be nice to clean up is the html inside the helper.  Having to concatenate strings of html together is kind of tough to read.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
