<?xml version="1.0" encoding="UTF-8"?> <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/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Ruby on Rails Notes &#187; haml</title> <atom:link href="http://railsnotes.com/tag/haml/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Javascript in Haml</title><link>http://railsnotes.com/474-javascript-haml/</link> <comments>http://railsnotes.com/474-javascript-haml/#comments</comments> <pubDate>Thu, 07 May 2009 00:43:20 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[haml]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=474</guid> <description><![CDATA[One thing that is not obvious with HAML is how to add javascript. In the past, haml didn't really like javascript that much but the latest version of haml on github makes it very simple. It's done using the :javascript filter and this post shows you how with an example.]]></description> <content:encoded><![CDATA[<p></p><p>One thing that is not obvious with HAML is how to add javascript. In the past, <a
href="http://b.lesseverything.com/2008/2/19/haml-doesn-t-like-javascript" target="_blank">haml didn&#8217;t really like javascript that much</a> but the latest version of haml on github makes it very simple. It&#8217;s done using the :javascript filter. Here&#8217;s an example:</p><pre>:javascript
  jQuery(function(){
    tog("#forgot_password_clicker", "#login_form");
    tog("#forgot_password_clicker", "#forgot_form", forgot_text);
  });</pre><p>You can also mix in ruby variables by using the standard way of interpolating ruby with strings through: #{ }. Here&#8217;s an example of how it all works in a full page with a ruby variable mixed in:</p><pre>!!! XML
!!!
%html{:xmlns =&gt; "http://www.w3.org/1999/xhtml", "xml:lang" =&gt; "en", :lang =&gt; "en"}
  %head
    %meta{'http-equiv' =&gt; "content-type", :content =&gt; "text/html;charset=UTF-8"}

  %body
    - @some_ruby_variable = "something goes here."
    :javascript
      #{@some_ruby_variable}
      jQuery(function(){
        tog("#forgot_password_clicker", "#login_form");
        tog("#forgot_password_clicker", "#forgot_form", forgot_text);
      });</pre><p>This makes this HTML:</p><pre>&lt;?xml version='1.0' encoding='utf-8' ?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'&gt;
  &lt;head&gt;
    &lt;meta content='text/html;charset=UTF-8' http-equiv='content-type' /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;script type='text/javascript'&gt;
      //&lt;![CDATA[
        something goes here.
        jQuery(function(){
          tog("#forgot_password_clicker", "#login_form");
          tog("#forgot_password_clicker", "#forgot_form", forgot_text);
        });
      //]]&gt;
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>]]></content:encoded> <wfw:commentRss>http://railsnotes.com/474-javascript-haml/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Response to &quot;Thoughts on Haml&quot;</title><link>http://railsnotes.com/395-response-to-thoughts-on-haml/</link> <comments>http://railsnotes.com/395-response-to-thoughts-on-haml/#comments</comments> <pubDate>Sat, 02 May 2009 01:32:53 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[haml]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=395</guid> <description><![CDATA[James Britt recently wrote about his experience with HAML, the alternative to ERB. His basic position was that HAML for noobies and he doesn't get why or how HAML makes real world code better. In this post, I show with code why HAML is awesome and how it kicks ERb-butt.]]></description> <content:encoded><![CDATA[<p></p><p><em>James Britt wrote up a <a
href="http://www.jamesbritt.com/2009/4/29/thoughts-on-haml" target="_blank">blog post talking about his experience with HAML</a></em><em>, the alternative to ERB. His basic position (from what I gathered) was that it&#8217;s for noobies and that no one has explained to him why or how HAML makes real world code better&#8230; either than saying &#8220;wait, it&#8217;ll start looking beautiful soon enough and you won&#8217;t go back.&#8221;  This is my detailed, somewhat-reasoned response.</em></p><p>I like HAML because it&#8217;s clean and easy to read. Cleaner &amp; easier to read than ERb&#8230; and yes, I&#8217;ll back that up with code:</p><p><a
href="http://pastie.org/private/n8ipfrkxlremo4jwtxiww">http://pastie.org/private/n8ipfrkxlremo4jwtxiww</a></p><p>Converting the ERB file to HAML took less than 4 minutes, mostly hitting the delete key.</p><p>A 39 line code becomes 31 lines&#8230; and that&#8217;s not even the big win. Now if  you don&#8217;t think the HAML code chuck is visually easier to digest than the ERB version, that&#8217;s fine. Stay with ERB.</p><p>I find HAML code is easier to maintain &amp; write&#8230; and it has nothing to do with a lack of knowledge of html or anything else.</p><h2>How is it easier to write and maintain?</h2><p>First, there is the overt clarity when it comes to sass (css) &amp; haml code.</p><pre>## haml file
.container
  .header
    %h1 Site Name
    %ul
      %li= link_to ...
      %li= link_to ...
      %li= link_to ...
  .content
    stuff
  .footer</pre><pre>## sass (css) file for this

.container
  background-color: black

  .header
    background-color: white

    h1
      font-family: Funky
      font-size: 3em
    ul
      li
        a:link, a:visited
        a:hover
  .content
  .footer</pre><p>Do you see the pairing? I <strong>LOVE</strong> that! I find it clean &amp; easy to read.</p><p>Secondly, it&#8217;s very ruby like.</p><p>This:</p><pre>&lt;% if @subscription.state == 'trial' %&gt;
  &lt;label&gt;Trial expiration date:&lt;/label&gt;
  &lt;%= @subscription.next_renewal_at.to_s(:long_day) %&gt;

&lt;% else %&gt;
  &lt;% if @subscription.amount &gt; 0 %&gt;
    &lt;label&gt;Next charge date:&lt;/label&gt;
    &lt;%= @subscription.next_renewal_at.to_s(:long_day) %&gt;
    &lt;br/&gt;
    &lt;label&gt;Next charge amount:&lt;/label&gt;
    &lt;%= number_to_currency @subscription.amount %&gt;
    &lt;br/&gt;
    &lt;label&gt;Current payment method:&lt;/label&gt;
    &lt;%= @subscription.paypal? ? 'PayPal' : "#{@subscription.card_number} / #{@subscription.card_expiration}" %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;</pre><p>becomes:</p><pre>- if @subscription.state == 'trial'
  %label Trial expiration date:
  = @subscription.next_renewal_at.to_s(:long_day)

- else
  - if @subscription.amount &gt; 0
    %label Next charge date:
    = @subscription.next_renewal_at.to_s(:long_day)
    %br/
    %label Next charge amount:
    = number_to_currency @subscription.amount
    %br/
    %label Current payment method:
    = @subscription.paypal? ? 'PayPal' : "#{@subscription.card_number} / #{@subscription.card_expiration}"</pre><p>Which looks &amp; feels more like ruby? For me, the choice is clearly the second one. It literally removes anything that doesn&#8217;t communicate what the code should do.</p><p>Anyway, to each his own.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/395-response-to-thoughts-on-haml/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Splitting HAML code into multiple lines</title><link>http://railsnotes.com/73-splitting-haml-code-into-multiple-lines/</link> <comments>http://railsnotes.com/73-splitting-haml-code-into-multiple-lines/#comments</comments> <pubDate>Fri, 23 Jan 2009 19:15:59 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[views]]></category> <category><![CDATA[haml]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=73</guid> <description><![CDATA[If you&#8217;re using HAML and have a really long piece of code, you probably want to split it into multiple lines so it looks clean. Here&#8217;s how you do it. Let&#8217;s say you have this code: %h1.logo= real_account? &#38;&#38; current_account.name ? current_account.name : AppConfig['app_name'] But you&#8217;d rather have: %h1.logo= real_account? &#38;&#38; current_account.name ?  current_account.name : AppConfig['app_name'] [...]]]></description> <content:encoded><![CDATA[<p></p><p>If you&#8217;re using HAML and have a really long piece of code, you probably want to split it into multiple lines so it looks clean. Here&#8217;s how you do it.</p><p><strong>Let&#8217;s say you have this code:</strong></p><pre>%h1.logo= real_account? &amp;&amp; current_account.name ? current_account.name : AppConfig['app_name']</pre><p><strong>But you&#8217;d rather have:</strong></p><pre>%h1.logo= real_account? &amp;&amp; current_account.name ? 
          current_account.name : AppConfig['app_name']</pre><p><strong>All you need is to pipe them using |, like this:</strong></p><pre>%h1.logo= real_account? &amp;&amp; current_account.name ? |
          current_account.name : AppConfig['app_name'] |</pre><p><span
style="color:red">Notice how the last line also has a |. That is required.</span></p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/73-splitting-haml-code-into-multiple-lines/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/16 queries in 0.028 seconds using disk

Served from: railsnotes.com @ 2010-09-09 07:16:36 -->