<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>ruby on rails haml erb conversion on random thoughts</title><link>https://awesomeprogrammer.com/categories/ruby-on-rails-haml-erb-conversion/</link><description>Recent content in ruby on rails haml erb conversion on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 03 Sep 2012 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/ruby-on-rails-haml-erb-conversion/index.xml" rel="self" type="application/rss+xml"/><item><title>Batch ERB to HAML conversion</title><link>https://awesomeprogrammer.com/blog/2012/09/03/batch-erb-to-haml-conversion/</link><pubDate>Mon, 03 Sep 2012 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2012/09/03/batch-erb-to-haml-conversion/</guid><description><![CDATA[<p>Quick and useful code snippet that you may want to use eg. while upgrading some old Rails projects. That HAML awesomeness you should use, Luke!</p>
<p>Depending on your configuration (I&rsquo;m using RVM for example) you may want to add those gems to your Gemfile:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>gem <span style="color:#e6db74">&#39;haml&#39;</span> <span style="color:#75715e"># obviously</span>
</span></span><span style="display:flex;"><span>gem <span style="color:#e6db74">&#39;hpricot&#39;</span>
</span></span><span style="display:flex;"><span>gem <span style="color:#e6db74">&#39;ruby_parser&#39;</span>
</span></span></code></pre></div><p>Here&rsquo;s the code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#75715e"># erb_to_haml.rb</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">Dir</span><span style="color:#f92672">[</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">#{</span><span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>join(<span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>dirname(__FILE__), <span style="color:#e6db74">&#39;app&#39;</span>, <span style="color:#e6db74">&#39;views&#39;</span>)<span style="color:#e6db74">}</span><span style="color:#e6db74">/**/*.erb&#34;</span><span style="color:#f92672">].</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>file<span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span>  puts <span style="color:#e6db74">&#34;Working on: </span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74"> ...&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">`html2haml -rx </span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74"> </span><span style="color:#e6db74">#{</span>file<span style="color:#f92672">.</span>gsub(<span style="color:#e6db74">/\.erb$/</span>, <span style="color:#e6db74">&#39;.haml&#39;</span>)<span style="color:#e6db74">}</span><span style="color:#e6db74">`</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span></code></pre></div><p>Description of html2haml options:</p>
<p><code>-e, --erb</code>
Parse ERb tags.</p>
<p><code>-x, --xhtml</code>
Parse the input using the more strict XHTML parser.</p>
<p>Drop this file into your rails root directory and just run it. You may want to review the code of you new HAML files and delete those old nasty erbs. Have fun!</p>]]></description><content:encoded><![CDATA[<p>Quick and useful code snippet that you may want to use eg. while upgrading some old Rails projects. That HAML awesomeness you should use, Luke!</p>
<p>Depending on your configuration (I&rsquo;m using RVM for example) you may want to add those gems to your Gemfile:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>gem <span style="color:#e6db74">&#39;haml&#39;</span> <span style="color:#75715e"># obviously</span>
</span></span><span style="display:flex;"><span>gem <span style="color:#e6db74">&#39;hpricot&#39;</span>
</span></span><span style="display:flex;"><span>gem <span style="color:#e6db74">&#39;ruby_parser&#39;</span>
</span></span></code></pre></div><p>Here&rsquo;s the code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#75715e"># erb_to_haml.rb</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">Dir</span><span style="color:#f92672">[</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">#{</span><span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>join(<span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>dirname(__FILE__), <span style="color:#e6db74">&#39;app&#39;</span>, <span style="color:#e6db74">&#39;views&#39;</span>)<span style="color:#e6db74">}</span><span style="color:#e6db74">/**/*.erb&#34;</span><span style="color:#f92672">].</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>file<span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span>  puts <span style="color:#e6db74">&#34;Working on: </span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74"> ...&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">`html2haml -rx </span><span style="color:#e6db74">#{</span>file<span style="color:#e6db74">}</span><span style="color:#e6db74"> </span><span style="color:#e6db74">#{</span>file<span style="color:#f92672">.</span>gsub(<span style="color:#e6db74">/\.erb$/</span>, <span style="color:#e6db74">&#39;.haml&#39;</span>)<span style="color:#e6db74">}</span><span style="color:#e6db74">`</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span></code></pre></div><p>Description of html2haml options:</p>
<p><code>-e, --erb</code>
Parse ERb tags.</p>
<p><code>-x, --xhtml</code>
Parse the input using the more strict XHTML parser.</p>
<p>Drop this file into your rails root directory and just run it. You may want to review the code of you new HAML files and delete those old nasty erbs. Have fun!</p>]]></content:encoded></item></channel></rss>