Haml Beautify Rails Code June 21st, 2007

Try Haml today if you use Rails. At first time, I feel reluctant. Isn’t rhtml is enough? But trying something with a little time is not a bad thing. So I jump to the boat. Here’s what I feel. It feels good.

Haml is alternative for rhtml. It is shorter. But what makes me using haml is it beatify Rails view. Usually using rhtml makes my html code (result of Rails view) cluttered.

<div id="header"></div>

  <div id="title">ROR Faq System<br />v1.0</div>

  <div id="container">

    <div class="content">

      <h3>ROR Faq System</h3>

<p><select id="category_name" name="category[name]"><option value="3" selected="selected">Music Rocks</option>
<option value="1">Dog</option>
<option value="2">Bla Thung</option>
<option value="4">Bubu</option></select></p>
<script type="text/javascript">
//<![CDATA[
new Form.Element.EventObserver('category_name', function(element, value) {new Ajax.Updater('questions_list', '/faq/questions_list', {asynchronous:true, evalScripts:true, parameters:'category=' + escape(value)})})
//]]>
</script>
<div id="questions_list">
But this my html code after using haml. It is indented properly. My html code looks like python code.
<div class='container'>
      <div class='header'>
        <div class='title'>
          <h1>litemedia</h1>
          <h4>alpha</h4>

        </div>
        <div class='navigation'>
          <a href="#">Awal</a>
          <a href="#">Tentang</a>
          <a href="#">Kontribusi</a>
          <a href="#">Komunitas</a>
          <a href="#">FAQ</a>

          <a href="#">Umpan Balik</a>
        </div>
        <div class='clearer'>
          <span>
          </span>
        </div>
        <p align='right'>
          <a href="#">Login</a>

          <span>
          </span>
          <a href="#">Register</a>
          <span>
          </span>
          <a href="#">Help</a>
        </p>
      </div>

      <div class='main'>
        <div class='content'>
          <h1>Apa itu Litemedia?</h1>
          <br>
          </br>
          <p>Litemedia adalah media buat:</p>
          <ul>
            <li>

              Kamu yang gak mau ketinggalan informasi acara terbaru yang sesuai dengan minatmu.
            </li>
            <li>
              Kamu punya komunitas atau pelanggan dan kamu pengen membagi mereka informasi yang kamu rasa penting bagi mereka.
            </li>
            <li>
              Buat komunitas dengan teman-teman atau kenalan baru yang punya minat sama.
            </li>
          </ul>
          <p>

            <a href="#">Pelajari lebih dalam</a>
            <span>&nbsp; | &nbsp;</span>
            <a href="#">Mulai</a>
          </p>
          <hr>
          </hr>
          <h1>Yang terbaru</h1>

          <div align='right'>
            <a href="#">terbaru</a>
            <span>|</span>
            <a href="#">paling banyak dilihat</a>
            <span>|</span>
            <a href="#">paling banyak dibicarakan</a>

            <span>|</span>
            <a href="#">paling favorit</a>
          </div>
          <h5>Seminar Bagaimana Cara Memangkas Terorisme</h5>
          <div class='descr'>
            Tue Jun 19 00:00:00 +0700 2007
            <span>oleh</span>

            vertigo
          </div>

Haml is ruby library. But somebody ports it to PHP. That’s good. I think beauty is important part of programming. Programming is an art and art should be beautiful. You should take programming to the level of art. You should treat your project as drawing. Your programming project should inspire people to seek more beauty in this world.

Leave a Reply