<?xml version="1.0" encoding="UTF-8"?>
<post>
  <alt>Klimt, Salom&#233;</alt>
  <body>Je suis encore au stade de test avec HAML. Il faut un d&#233;lais d'apprentissage pour penser et &#233;diter dans l'esprit de Haml.
Mais vous allez vous rendre compte suite aux exemples ci-dessous du pragmatisme pouss&#233; de ce moteur de template. Il est d&#233;ja &#224; sa version &quot;HAML 2.0&quot;. Il existe aussi des versions pour PHP et ASP (sans commentaire)
&lt;h3&gt;- Installation (RoR)&lt;/h3&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;gem install haml&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

pour ajouter HAML comme plugin &#224; votre application:
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;haml --rails /chemin/de/votre/application&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

J'ai oubli&#233; de vous dire qu'avec HAML vous venez aussi d'installer son compagnon SASS d&#233;taill&#233; dans &lt;a href=&quot;http://maxula.net/posts/sass&quot; alt=&quot;sass css&quot;&gt;cet article&lt;/a&gt;.&lt;p&gt;Une fois le plugin install&#233;, vous pouvez utiliser directement un template en Haml en changeant l'extension de la vue:&lt;br/&gt;&lt;/p&gt;/app/view/exemple/vue.html.erb -&gt; /app/view/exemple/vue.html.haml&lt;br/&gt;&lt;h3&gt;- Utilisation&lt;/h3&gt;
&lt;p&gt;Je mettrais des exemples qui sont plus parlant qu'une description technique&lt;/p&gt;
&lt;strong&gt;avant :&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;ta&quot;&gt;&amp;lt;strong&amp;gt;&lt;/span&gt;&lt;span class=&quot;c&quot;&gt;&amp;lt;%= item.title %&amp;gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/strong&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;strong&gt;apr&#232;s :&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;%strong= item.title&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Comme vous voyez le principe est simple, mais peut &#234;tre pas encore convainquant, le suivant !!! ...&lt;/p&gt;
&lt;strong&gt;avant :&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;ta&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@table&lt;/span&gt;.titre &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%=&lt;/span&gt; link_to &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Home&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, home_url &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;ta&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;paraf&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@table&lt;/span&gt;.contenu &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;strong&gt;apr&#232;s :&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;#content .title
   %h1= @table.title
   = link_to 'Home', home_url
   %p.paraf= @table.contenu&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Pause!..., bon, rien que l&#224;, je pense que vous &#234;tes entrain de penser aux kilom&#232;tres de balises html que vous avez tapez durant toute votre vie de d&#233;veloppement web, au temps pass&#233; &#224; chercher la balise de fermeture perdue dans le fleuve de codes.&lt;/p&gt;
&lt;p&gt;Continuons...&lt;/p&gt;
&lt;strong&gt;avant:&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;ta&quot;&gt;&amp;lt;ul&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;decomenu&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%-&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@tirets&lt;/span&gt;.each &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |i| &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;ta&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%=&lt;/span&gt; i.nom &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%-&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;strong&gt;apr&#232;s&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;%ul#menu.decomenu
  - @tirets.each do |i|
    %li= i.nom
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Comme vous voyez, pas besoin du &quot;end&quot; de la boucle, il est bien clair avec le d&#233;calage vers la droite (deux caract&#233;res espace) qui indique la structure de l'arborescence.&lt;/p&gt;
&lt;p&gt;Ainsi, pour commenter et d&#233;commenter du code, &#231;a devient plus simple et plus rapide&lt;/p&gt;
&lt;strong&gt;avant :&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;ta&quot;&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;sous-titre&lt;span class=&quot;ta&quot;&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class=&quot;ta&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- Une ligne &#224; commenter --&amp;gt;&lt;/span&gt;
  le reste du texte non-comment&#233;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!--
  &amp;lt;p&amp;gt;plus qu'une ligne &#224; commenter&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;il n'est pas &#224; sa place&amp;lt;/h2&amp;gt;
  &amp;lt;/div&amp;gt;
--&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;strong&gt;apr&#232;s :&lt;/strong&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
%h2 sous-titre
%div
  / Une ligne &#224; commenter
  le reste du texte non-comment&#233;
/
  %p plus qu'une ligne &#224; commenter
  %div
    %h1 il n'est pas &#224; sa place
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

Voyant des petits clins-d'oeil pour raccourcir les ent&#234;tes des templates
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
!!! 1.1&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

ca donne !!
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;dt&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

encore un autre
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
/[if IE]
  %a{ :href =&lt;span class=&quot;er&quot;&gt;&amp;gt;&lt;/span&gt; 'http://www.mozilla.com/en-US/firefox/' }
    %h1 Get Firefox
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&#231;a g&#233;n&#233;re
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!--[if IE]&amp;gt;
  &amp;lt;a href='http://www.mozilla.com/en-US/firefox/'&amp;gt;
    &amp;lt;h1&amp;gt;Get Firefox&amp;lt;/h1&amp;gt;
  &amp;lt;/a&amp;gt;&amp;lt;![endif]--&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Il me faut peut-&#234;tre encore 2 ans de pratique autour de Haml pour ne plus me rendre compte de la quantit&#233; de code &#233;conomis&#233;e, en m&#234;me temps haml nous oblige &#224; g&#233;n&#233;rer du code html bien structur&#233; &#224; la sortie</body>
  <cat-id type="integer">1</cat-id>
  <created-at type="datetime">2009-05-27T13:13:10Z</created-at>
  <id type="integer">1</id>
  <pagetitle>HAML, moteur de template Ruby on Rails</pagetitle>
  <photo-content-type>image/png</photo-content-type>
  <photo-file-name>klimt-salome.png</photo-file-name>
  <photo-file-size type="integer">21536</photo-file-size>
  <short>HAML est un moteur de template sous Rails assez particulier, on arrive &#224; &#233;crire moins de code dans la vue pour le m&#234;me r&#233;sultat, avec une claret&#233; de structure &#233;vidente.</short>
  <title>HAML. Prolongez la vie de votre clavier</title>
  <updated-at type="datetime">2009-09-29T19:31:08Z</updated-at>
  <url>haml</url>
</post>
