<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>partials &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/partials/</link>
	<description>Feed of posts on WordPress.com tagged "partials"</description>
	<pubDate>Wed, 20 Aug 2008 17:33:32 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Partials, reutilização de código no Rails]]></title>
<link>http://railsgirl.wordpress.com/?p=43</link>
<pubDate>Tue, 05 Aug 2008 20:10:22 +0000</pubDate>
<dc:creator>amandavarella</dc:creator>
<guid>http://railsgirl.wordpress.com/?p=43</guid>
<description><![CDATA[Partials são pedaços de página que podem ser reutilizados pra evitar replicação de código. Pra]]></description>
<content:encoded><![CDATA[<p>Partials são pedaços de página que podem ser reutilizados pra evitar replicação de código. Pra quem vem do mundo Java, as Partials fazem algo semelhante ao Tiles, vc vai juntando os "pedaços" conforme a sua necessidade. Então vai um simples, mas muito útil exemplo de Partials em Rails.</p>
<p>Vou utilizar o exemplo que eu tenho aqui, onde eu fiz o scaffold* para o modelo "reading".<br />
Na view index.html.erb foi gerado o seguinte trecho de código:</p>
<p>[sourcecode language='ruby']<br />
#index.html.erb</p>
<p><% for reading in @readings %></p>
<tr>
<td><%=h reading.url %></td>
<td><%=h reading.text %></td>
<td><%=h reading.page %></td>
<td><%=h reading.time %></td>
<td><%= link_to ‘Show’, reading %></td>
<td><%= link_to ‘Edit’, edit_reading_path(reading) %></td>
<td><%= link_to ‘Destroy’, reading, :confirm => ‘Are you sure?’, :method => :delete %></td>
</tr>
<p><% end %><br />
[/sourcecode]<br />
Eu gostaria de reutilizar o trecho que está exibindo cada "reading", então, eu vou retirar e colocar este trecho de código em uma Partial, assim eu posso chamá-la em qualquer outro lugar da minha aplicação, onde eu queira exibir as informações da mesma maneira.</p>
<p>Uma partial é um arquivo que começa com um "_", underscore, underline.... então vou criar um arquivo _reading.html.erb (dentro da pasta de views de readings), e vou pegar todo o código que estava dentro do meu for. Este será o conteúdo da partial:<br />
#_reading.html.erb<br />
[sourcecode language='ruby']</p>
<tr>
<td><%=h reading.url %></td>
<td><%=h reading.text %></td>
<td><%=h reading.page %></td>
<td><%=h reading.time %></td>
<td><%= link_to ‘Show’, reading %></td>
<td><%= link_to ‘Edit’, edit_reading_path(reading) %></td>
<td><%= link_to ‘Destroy’, reading, :confirm => ‘Are you sure?’, :method => :delete %></td>
</tr>
<p>[/sourcecode] </p>
<p>E finalmente vou alterar o meu index.html.erb, substituindo:</p>
<p>[sourcecode language='ruby']<br />
#index.html.erb</p>
<tr>
<td><%=h reading.url %></td>
<td><%=h reading.text %></td>
<td><%=h reading.page %></td>
<td><%=h reading.time %></td>
<td><%= link_to ‘Show’, reading %></td>
<td><%= link_to ‘Edit’, edit_reading_path(reading) %></td>
<td><%= link_to ‘Destroy’, reading, :confirm => ‘Are you sure?’, :method => :delete %></td>
</tr>
<p>[/sourcecode]</p>
<p>Por uma única linha:</p>
<p>[sourcecode language='ruby']<br />
#index.html.erb</p>
<p><%= render :partial => 'reading', :collection => @readings%><br />
[/sourcecode]</p>
<p>A partial receberá a collection "readings" como parâmetro.</p>
<p>Simples, bonito, e limpo!</p>
<p><em>Newbies Corner:</em><br />
Scaffold é uma operação do Rails onde vc passa um nome de modelo e os campos, e ele gera uma aplicação CRUD (Create, Retrieve, Update e Delete) completa.<br />
Ex: o comando "script/generate scaffold person name:string tel:number" vai gerar um cadastro completo de pessoas com nome e telefone, permitindo listar, excluir e alterar cada registro.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Requests]]></title>
<link>http://tezmilleroz.wordpress.com/2007/10/19/requests/</link>
<pubDate>Fri, 19 Oct 2007 00:53:00 +0000</pubDate>
<dc:creator>Tez Miller</dc:creator>
<guid>http://tezmilleroz.wordpress.com/2007/10/19/requests/</guid>
<description><![CDATA[Have received my second-ever agent request for a full. This is good, but I think I need to research ]]></description>
<content:encoded><![CDATA[<p>Have received my second-ever agent request for a full. This is good, but I think I need to research the agent more, maybe question her clients, because I have some concerns.</p>
<p>Also received an editor request for a partial.</p>
<p><b>Remember:</b> The Hives' <i>The Black and White Album</i> is released tomorrow (Saturday). Be good and go buy it - I know I will! ;-)
<div class="blogger-post-footer">© 2007 by Tez Miller</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Modular Page Layouts in Ruby on Rails]]></title>
<link>http://gregwillits.wordpress.com/2007/10/16/modular-page-layouts-in-ruby-on-rails/</link>
<pubDate>Tue, 16 Oct 2007 11:23:47 +0000</pubDate>
<dc:creator>gregwillits</dc:creator>
<guid>http://gregwillits.wordpress.com/2007/10/16/modular-page-layouts-in-ruby-on-rails/</guid>
<description><![CDATA[Oct 27 Update: I&#8217;ve moved this blog to a permanent home on my own domain at http://www.railsde]]></description>
<content:encoded><![CDATA[<p>Oct 27 Update: I've moved this blog to a permanent home on my own domain at <a href="http://www.railsdev.ws/">http://www.railsdev.ws/</a></p>
<p><strong>Downloads:</strong><br />
<a href='http://www.railsdev.ws/blog/wp-content/uploads/2007/10/modular_page_assembly_in_rails.pdf' title='Modular Page Assembly Article (pdf)'>10 page pdf article only</a>, or <a href='http://www.railsdev.ws/blog/wp-content/uploads/2007/10/railsdev_modular_page_assy.zip' title='Modular Page Assembly Article and Code (zip)'>article and sample code</a>.</p>
<p>So, you've read <a href="http://www.bookpool.com/sm/0977616630" title="link to book">&#8220;Agile Web Development with Rails&#8221;</a>, and you've started to tinker with some pages on your own, but you just can't figure out how you're supposed to use that view file to create your 3 column layout? So far I’ve found every tutorial on Rails talks about the default chain of controller to view to layout and stops. 3 files, done. Well, then what?</p>
<p>I felt your pain. So, I've prepared an article and sample code set (links up top) intended to pick up where AWDWR leaves off in explaining how to organize files for a modular page assemby approach with layouts and partials.</p>
<p><!--more--></p>
<p>If you’ve come from a template-driven web application framework, the way Rails builds pages can feel a bit backwards. For me, I was accustomed to the exact opposite fo how Rails works. I'm used to the layout being the starting point, and its structure determining which view fragments the framework would include (based on dynamic file name conventions).</p>
<p>By the time I get to writing code for a site I have a pretty solid idea of how it will look, and how it needs to be structured. While AWDWR is a good intro, it left me feeling like I still had no idea how I was going to build typical modular web pages using layouts with reusable panels. Only after I figured this out was my brain going to feel free to work on the logical side of Rails.</p>
<p>So, I focused on solving that puzzle before I went much further. Out of that process, you get my first blog, and my first article about Rails. (I've written quite a bit about another language called Lasso).</p>
<p>I'll use your feedback to shape the article's updates. If you think I should address some particular idioms, let me know. My objective is to provide material that's more complete than the gloss-overs we usually get treated to in web articles.</p>
<p>Oct 22 Update: I have expanded the article to include the passing of data into the various display components. Indeed, solving this task to meet several goals required that I change how I was doing some things in the first version of the article.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[How-To Make a Rails Partial With Optional Locals (Parameters)]]></title>
<link>http://hackd.wordpress.com/2007/08/25/how-to-make-a-rails-partial-with-optional-locals-parameters/</link>
<pubDate>Sun, 26 Aug 2007 05:57:00 +0000</pubDate>
<dc:creator>Matt</dc:creator>
<guid>http://hackd.wordpress.com/2007/08/25/how-to-make-a-rails-partial-with-optional-locals-parameters/</guid>
<description><![CDATA[Just a quick post today!  In an effort to help our ThriveSmart code stay DRY, I have been treating m]]></description>
<content:encoded><![CDATA[<p>Just a quick post today!  In an effort to help our <a href="http://www.thrivesmart.com">ThriveSmart</a> code stay <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a>, I have been treating my partials a lot like methods that can output varying HTML based on the parameters passed in.  Let me give an example:</p>
<pre style="border:1px solid #eeeeee;">&#60;% <span style="color:#9b2e80;"># Parameters: upload_path, unique_name,</span>
<span style="color:#9b2e80;">   #         title = nil, other = nil %&#62;</span>

This outputs the &#60;%= upload_path %&#62;

&#60;% if title then %&#62;
  Output the title &#60;%= title %&#62; only if there was one.
&#60;% end %&#62;</pre>
<p>The problem with this is that every time you call the partial, you have to send in nils for the optional locals regardless (e.g. :title =&#62; nil, :other =&#62; nil) with your render call, as shown  below</p>
<pre style="border:1px solid #eeeeee;">&#60;%= render <span style="color:#005aff;">:partial</span> =&#62; 'shared/my_partial',
    <span style="color:#005aff;">:locals</span> =&#62; {
        <span style="color:#005aff;">:upload_path</span> =&#62; 'dumdeedum',
        <span style="color:#005aff;">:unique_name</span> =&#62; "slideshow",
        <span style="background-color:#feffdb;"><span style="color:#005aff;">:title</span> =&#62; nil,<span style="color:#005aff;">
        :other</span> =&#62; nil</span>
    } %&#62;</pre>
<p>Knowing this wasn't particularly elegant, I  wanted a better solution.   Here's how you make the title and other local variable optional.</p>
<p><em>UPDATE: for a reason I still don't understand, unless defined?(x) doesn't always perform as you'd expect in a partial.  I've switched to using local_assigns[:x].nil? (.nil? to get around if x == false).  This solution currently doesn't seem work with HAML, but works like a charm in RHTML.</em></p>
<pre style="border:1px solid #eeeeee;">&#60;%
<span style="color:#9b2e80;">  # Parameters: upload_path, unique_name, title = nil, other = nil</span><strike>
  title = nil unless defined?(title)
  other = nil unless defined?(other)</strike>

<span style="background-color:#feffdb;">  title = nil if local_assigns[:title].nil?</span>
  <span style="background-color:#feffdb;">other = nil if local_assigns[:other].nil?</span>
%&#62;

This outputs the &#60;%= upload_path %&#62;

&#60;% if title then %&#62;
  Output the title &#60;%= title %&#62; only if there was one.
&#60;% end %&#62;</pre>
<p>Now you can call it and leave off the optional parameters as you please!</p>
<pre style="border:1px solid #eeeeee;">&#60;%= render <span style="color:#005aff;">:partial</span> =&#62; 'shared/my_partial',
    <span style="color:#005aff;">:locals</span> =&#62; {
        <span style="color:#005aff;">:upload_path</span> =&#62; 'dumdeedum',
        <span style="color:#005aff;">:unique_name</span> =&#62; "slideshow"
    } %&#62;</pre>
<p>Well, I hope this make your code DRY as it's helped make ours!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[DRY - Partials, Components, Slots e Component Slots do symfony]]></title>
<link>http://andreiabohner.wordpress.com/2007/08/12/dry-partials-components-slots-e-component-slots-do-symfony/</link>
<pubDate>Sun, 12 Aug 2007 03:28:24 +0000</pubDate>
<dc:creator>Andréia Bohner</dc:creator>
<guid>http://andreiabohner.wordpress.com/2007/08/12/dry-partials-components-slots-e-component-slots-do-symfony/</guid>
<description><![CDATA[ 
Um dos princípios do symfony é o DRY (Don&#8217;t Repeat Yourself ou &#8220;Não se repita]]></description>
<content:encoded><![CDATA[<p> <img src="http://andreiabohner.wordpress.com/files/2007/08/view11.gif" alt="view11.gif" /></p>
<p>Um dos princípios do <a href="http://www.symfony-project.com" title="symfony framework" target="_blank">symfony</a> é o <a href="http://en.wikipedia.org/wiki/DRY" title="DRY - Don't Repeat Yourself" target="_blank">DRY</a> (<em>Don't Repeat Yourself </em>ou "Não se repita"). Para nos ajudar com esta tarefa, o <em>framework </em>disponibiliza quatro <em>helpers </em>que podem ser utilizados conforme a necessidade.</p>
<p>Esta segunda <em>cheat-sheet  </em>sobre a camada de visão (<em>View</em>) do symfony, trata justamente destes <em>helpers </em>para trabalhar com:</p>
<ul>
<li>Partials: <em>include_partial()</em></li>
<li>Components: <em>include_component()</em></li>
<li>Slots: <em>include_slot()</em></li>
<li>Component Slots: <em>include_component_slot()</em></li>
</ul>
<p>Idiomas disponíveis:</p>
<ul>
<li>English - <a href="http://andreiabohner.wordpress.com/files/2007/08/sfviewsecondpartrefcard.pdf" title="PDF">PDF</a></li>
<li>Português - em breve</li>
</ul>
]]></content:encoded>
</item>

</channel>
</rss>
