<?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: Simplifying your Ruby on Rails code: Presenter pattern, cells plugin</title>
	<atom:link href="http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/</link>
	<description>In my blog I'll try to describe about interesting technologies, my discovery in IT and some useful things about programming.</description>
	<lastBuildDate>Tue, 29 Dec 2009 10:34:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: joost</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-285383</link>
		<dc:creator>joost</dc:creator>
		<pubDate>Thu, 18 Mar 2010 13:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-285383</guid>
		<description>Replying to myself, here is how to add the presenter specs to autospec. Put the code below in a .autotest file in your project root.

[cc lang=&quot;ruby&quot;]Autotest.add_hook :initialize do &#124;at&#124;
  at.add_mapping(%r%^app/presenters/(.*)\.rb$%) { &#124;_, m&#124;
    [&quot;spec/presenters/#{m[1]}_spec.rb&quot;]
  }
end[/cc]</description>
		<content:encoded><![CDATA[<p>Replying to myself, here is how to add the presenter specs to autospec. Put the code below in a .autotest file in your project root.</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Autotest.<span style="color:#9900CC;">add_hook</span> <span style="color:#ff3333; font-weight:bold;">:initialize</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>at<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; at.<span style="color:#9900CC;">add_mapping</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">%</span>^app<span style="color:#006600; font-weight:bold;">/</span>presenters<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\.<span style="color:#9900CC;">rb</span>$<span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>_, m<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;spec/presenters/#{m[1]}_spec.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: joost</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-285380</link>
		<dc:creator>joost</dc:creator>
		<pubDate>Thu, 18 Mar 2010 11:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-285380</guid>
		<description>Nice writeup, I like the simplicity of this particular Presenter.

How would you go about adding its specs to autospec? It doesn&#039;t seem to include them automatically.</description>
		<content:encoded><![CDATA[<p>Nice writeup, I like the simplicity of this particular Presenter.</p>
<p>How would you go about adding its specs to autospec? It doesn&#8217;t seem to include them automatically.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rolly</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-284710</link>
		<dc:creator>Rolly</dc:creator>
		<pubDate>Thu, 18 Mar 2010 23:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-284710</guid>
		<description>Thanks for writing this up.

This technique is really invaluable as your app grows and you end up with small encapsulated bits of logic that are too big/messy for partials/helpers but are also kind of inappropriate for your models and controllers.

I&#039;m really hoping something like this, or a conversion of Merb Parts, finds its way into Rails 3.</description>
		<content:encoded><![CDATA[<p>Thanks for writing this up.</p>
<p>This technique is really invaluable as your app grows and you end up with small encapsulated bits of logic that are too big/messy for partials/helpers but are also kind of inappropriate for your models and controllers.</p>
<p>I&#8217;m really hoping something like this, or a conversion of Merb Parts, finds its way into Rails 3.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emmanuel Gomez</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-284680</link>
		<dc:creator>Emmanuel Gomez</dc:creator>
		<pubDate>Thu, 18 Mar 2010 03:26:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-284680</guid>
		<description>@alexey: one big advantage that Cells (and other &#039;heavier&#039; approaches) have over helpers/partials is inheritance. 

The example in this article may not be sufficiently complex to justify for inheritance between Cells, but believe me that this can tremendously simplify an app (compared with complex shared view partials).</description>
		<content:encoded><![CDATA[<p>@alexey: one big advantage that Cells (and other &#8216;heavier&#8217; approaches) have over helpers/partials is inheritance. </p>
<p>The example in this article may not be sufficiently complex to justify for inheritance between Cells, but believe me that this can tremendously simplify an app (compared with complex shared view partials).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ennuyer.net &#187; Blog Archive &#187; Rails Reading - November 1, 2009</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-284249</link>
		<dc:creator>Ennuyer.net &#187; Blog Archive &#187; Rails Reading - November 1, 2009</dc:creator>
		<pubDate>Thu, 18 Mar 2010 13:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-284249</guid>
		<description>[...]  Simplifying your Ruby on Rails code: Presenter pattern, cells plugin &#124; Dmytro Shteflyuk&#8217;s Hom... [...]</description>
		<content:encoded><![CDATA[<p>[...]  Simplifying your Ruby on Rails code: Presenter pattern, cells plugin | Dmytro Shteflyuk&#8217;s Hom&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexey Trofimenko</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-283364</link>
		<dc:creator>Alexey Trofimenko</dc:creator>
		<pubDate>Thu, 18 Mar 2010 03:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-283364</guid>
		<description>one thing I especially love in ruby, you don&#039;t have to think about &quot;patterns&quot; at all. You just write ruby code and use one of them almost intuitivelly, without even remembering it got a big chapter in some Big Java/C++ Book and a Captial Letter Starting Name. 

Representers, Proxies, Factories, whatever, sometimes what you&#039;ll get is just another level of abstraction, not really useful at all on a second thought. Please, don&#039;t bring that hell to ruby.

Back to subject:  Long time ago we had components, but then world was filled with rumours about them being &quot;slow&quot;, and suddenly they fell out of usage and rails core. I yet to see them reintroduced back, in core, lightweight and isolated, but meanwhile both representers and cells functionality could be easily achieved using helpers alone, and I do it all the time.

differences are:

1) you have the same namespace for @vars (but locals are just as good) and helper names. It&#039;s a bad thing because of possible nameclashes, but it&#039;s a good thing for ctags and grep users. [cci_ruby]&lt;%= video_link @video, :style =&gt; :brief %&gt;[/cci_ruby] is DRY enough

2) you&#039;ll get [cci_ruby]ActionView::TemplateError[/cci_ruby] with 500 status instead of 404 [cci_ruby]ActiveRecord::NotFound[/cci_ruby] if you trigger some faulty [cci_ruby]Model.find[/cci_ruby] in helper and not in controller, but it&#039;s not a big deal and it could be fixed by several plugins.

3) there&#039;s no default place for such helpers, so what i have to do is just to group &quot;presenter helpers&quot; and &quot;cell and decoration helpers&quot; in different helper modules or in different sections of same &quot;resource specific&quot; helper module.</description>
		<content:encoded><![CDATA[<p>one thing I especially love in ruby, you don&#8217;t have to think about &#8220;patterns&#8221; at all. You just write ruby code and use one of them almost intuitivelly, without even remembering it got a big chapter in some Big Java/C++ Book and a Captial Letter Starting Name. </p>
<p>Representers, Proxies, Factories, whatever, sometimes what you&#8217;ll get is just another level of abstraction, not really useful at all on a second thought. Please, don&#8217;t bring that hell to ruby.</p>
<p>Back to subject:  Long time ago we had components, but then world was filled with rumours about them being &#8220;slow&#8221;, and suddenly they fell out of usage and rails core. I yet to see them reintroduced back, in core, lightweight and isolated, but meanwhile both representers and cells functionality could be easily achieved using helpers alone, and I do it all the time.</p>
<p>differences are:</p>
<p>1) you have the same namespace for @vars (but locals are just as good) and helper names. It&#8217;s a bad thing because of possible nameclashes, but it&#8217;s a good thing for ctags and grep users. <code class="codecolorer ruby default"><span class="ruby"><span style="color:#006600; font-weight:bold;">&lt;%</span>= video_link <span style="color:#0066ff; font-weight:bold;">@video</span>, <span style="color:#ff3333; font-weight:bold;">:style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:brief</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></span></code> is DRY enough</p>
<p>2) you&#8217;ll get <code class="codecolorer ruby default"><span class="ruby"><span style="color:#6666ff; font-weight:bold;">ActionView::TemplateError</span></span></code> with 500 status instead of 404 <code class="codecolorer ruby default"><span class="ruby"><span style="color:#6666ff; font-weight:bold;">ActiveRecord::NotFound</span></span></code> if you trigger some faulty <code class="codecolorer ruby default"><span class="ruby">Model.<span style="color:#9900CC;">find</span></span></code> in helper and not in controller, but it&#8217;s not a big deal and it could be fixed by several plugins.</p>
<p>3) there&#8217;s no default place for such helpers, so what i have to do is just to group &#8220;presenter helpers&#8221; and &#8220;cell and decoration helpers&#8221; in different helper modules or in different sections of same &#8220;resource specific&#8221; helper module.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mislav</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-283026</link>
		<dc:creator>Mislav</dc:creator>
		<pubDate>Thu, 18 Mar 2010 20:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-283026</guid>
		<description>It seems to me that &quot;cells&quot; offer no compelling advantage over simply using presenters with Rails partials.</description>
		<content:encoded><![CDATA[<p>It seems to me that &#8220;cells&#8221; offer no compelling advantage over simply using presenters with Rails partials.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmytro Shteflyuk</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-282946</link>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		<pubDate>Thu, 18 Mar 2010 10:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-282946</guid>
		<description>You&#039;re welcome :-) Think, author will accept your pull request quickly.</description>
		<content:encoded><![CDATA[<p>You&#8217;re welcome :-) Think, author will accept your pull request quickly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Evgeniy Dolzhenko</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-282944</link>
		<dc:creator>Evgeniy Dolzhenko</dc:creator>
		<pubDate>Thu, 18 Mar 2010 09:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-282944</guid>
		<description>Doh :) sorry then, 
Btw. is there anything that prevents adding such a semantics? 

From a quick look at [cci_ruby]Cell::View#render[/cci_ruby] it seems  that it could be updated to match the Rails version, but can&#039;t be sure about that.</description>
		<content:encoded><![CDATA[<p>Doh :) sorry then,<br />
Btw. is there anything that prevents adding such a semantics? </p>
<p>From a quick look at <code class="codecolorer ruby default"><span class="ruby"><span style="color:#6666ff; font-weight:bold;">Cell::View</span><span style="color:#008000; font-style:italic;">#render</span></span></code> it seems  that it could be updated to match the Rails version, but can&#8217;t be sure about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmytro Shteflyuk</title>
		<link>http://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/#comment-282943</link>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		<pubDate>Thu, 18 Mar 2010 08:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/?p=937#comment-282943</guid>
		<description>In cells you should use old good [cci_ruby]render :partial[/cci_ruby]. In other places I use [cci_ruby]render &#039;partial&#039;[/cci_ruby]. Be careful.</description>
		<content:encoded><![CDATA[<p>In cells you should use old good <code class="codecolorer ruby default"><span class="ruby">render <span style="color:#ff3333; font-weight:bold;">:partial</span></span></code>. In other places I use <code class="codecolorer ruby default"><span class="ruby">render <span style="color:#996600;">'partial'</span></span></code>. Be careful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
