<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: views code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 03:25:26 GMT</pubDate>
    <description>DZone Snippets: views code</description>
    <item>
      <title>Converting all ERb views to Haml</title>
      <link>http://snippets.dzone.com/posts/show/5449</link>
      <description>A little script to convert all your .erb views to .haml using html2haml, which is included with Haml installation.&lt;br /&gt;Just drop this in your rails root folder and run it.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class ToHaml&lt;br /&gt;  def initialize(path)&lt;br /&gt;    @path = path&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def convert!&lt;br /&gt;    Dir["#{@path}/**/*.erb"].each do |file|&lt;br /&gt;      `html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;path = File.join(File.dirname(__FILE__), 'app', 'views')&lt;br /&gt;ToHaml.new(path).convert!&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 01 May 2008 23:27:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5449</guid>
      <author>divoxx (Rodrigo Kochenburger)</author>
    </item>
    <item>
      <title>Block to Partial Rails Helper</title>
      <link>http://snippets.dzone.com/posts/show/2483</link>
      <description>From &lt;a href="http://errtheblog.com/post/13"&gt;http://errtheblog.com/post/13&lt;/a&gt;.&lt;br /&gt;Create a helper which takes a block and renders that block within the context of a partial.&lt;br /&gt;&lt;br /&gt;Create this helper:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def block_to_partial(partial_name, options = {}, &amp;block)&lt;br /&gt;  options.merge!(:body =&gt; capture(&amp;block))&lt;br /&gt;  concat(render(:partial =&gt; partial_name, :locals =&gt; options), block.binding)&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create this helper, too:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def sidebar_module(title, options = {}, &amp;block)&lt;br /&gt;  block_to_partial('shared/sidebar_module', options.merge(:title =&gt; title), &amp;block)&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create this partial (app/views/shared/_sidebar_module.rhtml):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div &lt;%= %[id="#{id}"] unless id.blank? %&gt; class="sidebar_module"&gt;&lt;br /&gt;  &lt;h2&gt;&lt;%= title %&gt;&lt;/h2&gt;&lt;br /&gt;  &lt;%= body %&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Use it in your views:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;% sidebar_module 'Recent Stories' do %&gt;&lt;br /&gt;  &lt;%= render :partial =&gt; 'recent_stories', :collection =&gt; @recent_stories %&gt;&lt;br /&gt;&lt;% end %&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 28 Aug 2006 05:49:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2483</guid>
      <author>err (Chris Wanstrath)</author>
    </item>
    <item>
      <title>My default layout in Rails projects</title>
      <link>http://snippets.dzone.com/posts/show/1488</link>
      <description>Writing a new layout from scratch gets boring, so I have a generic / default layout to use and extend from.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1-transitional.dtd"&gt;&lt;br /&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;	&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;&lt;br /&gt;	&lt;title&gt;&lt;%= @page_title %&gt;&lt;/title&gt;&lt;br /&gt;	&lt;%= stylesheet_link_tag "main" %&gt;&lt;br /&gt;	&lt;%= javascript_include_tag "prototype" %&gt;&lt;br /&gt;	&lt;%= javascript_include_tag "scriptaculous" %&gt;&lt;br /&gt;	&lt;%= javascript_include_tag "general" %&gt;&lt;br /&gt;	&lt;!--[if lt IE 7.]&gt;&lt;br /&gt;	&lt;script defer type="text/javascript" src="/javascripts/pngfix.js"&gt;&lt;/script&gt;&lt;br /&gt;	&lt;![endif]--&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;br /&gt;&lt;body class="&lt;%= @body_class %&gt;"&gt;&lt;br /&gt;	&lt;div id="container"&gt;&lt;br /&gt;			&lt;br /&gt;	&lt;%= @content_for_layout %&gt;&lt;br /&gt;&lt;br /&gt;	&lt;/div&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;pngfix.js is available &lt;a href="http://homepage.ntlworld.com/bobosola/pngfix.js"&gt;here.&lt;/a&gt;</description>
      <pubDate>Wed, 15 Feb 2006 01:40:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1488</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
