<?xml version="1.0" encoding="UTF-8"?>
<post>
  <alt>Andy WARHOL, Marylin Monroe</alt>
  <body>&lt;p&gt;Vous vous rappellez de &lt;a href=&quot;http://maxula.net/posts/haml&quot;&gt;haml&lt;/a&gt;? L&#224;, on va vous parler de son petit fr&#232;re SASS (Syntactically Awesome StyleSheets), inutile de vous expliquer son installation c'est d&#233;taill&#233; dans ce &lt;a href=&quot;http://maxula.net/posts/haml&quot; alt=&quot;haml css&quot;&gt;post&lt;/a&gt;. Il s'installe par d&#233;faut avec haml.&lt;/p&gt;
&lt;p&gt;Pour utiliser SASS dans vos CSS, cr&#233;ez un r&#233;pertoire SASS sous /public/stylesheets et placez y vos fichiers &quot;.SASS&quot; &lt;/p&gt;
&lt;p&gt;Quand on suit le principe du &quot;cascading&quot; (cascade) des feuilles de style, on se pose la question : Mais pourquoi les CSS n'ont pas eu l'id&#233;e d'utiliser la m&#234;me structure de SASS en arborescence, &#231;a aura &#233;tait plus facile &#224; &#233;diter et &#224; modifier ??, peut-&#234;tre que le prochain CSS4 appliquera la nomenclature de SASS.&lt;/p&gt;
&lt;p&gt;Voyons quelques exemples:&lt;br/&gt;
Comme avec haml le symbole &quot;#&quot; traduit un identificateur &quot;id&quot; et le &quot;.&quot; (point) une Classe &quot;class&quot;&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
#paragraphe p  :color red  :width 100%
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

ce qui nous donne:
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;co&quot;&gt;#paragraphe&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;p&lt;/span&gt; {  &lt;span class=&quot;ke&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;vl&quot;&gt;red&lt;/span&gt;;  &lt;span class=&quot;ke&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;fl&quot;&gt;100%&lt;/span&gt;; }
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;A premi&#232;re vue, on s'&#233;conomise l'&#233;criture des accolade &quot;{}&quot;  et des &quot;;&quot; qui causaient des probl&#232;mes par oubli.&lt;br/&gt;
Les &quot;:&quot; ont chang&#233; de fonction et d'emplacement, dans les exemples suivants on comprendra le pourquoi.&lt;/p&gt;
&lt;p&gt;Le deuxi&#232;me exemple est un cas concr&#233; qui justifie l'existence de SASS.&lt;br/&gt;
Tout comme haml, la structure en arborescence de sass utilise le d&#233;calage &#224; droite avec deux caract&#233;res &quot;espace&quot; pour d&#233;finir les noeuds de l'arbre.&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
#article  :width 100%
  p, div    :font-size 2em
    a    :font-weight bold
  pre    :font-size 3em
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

apr&#232;s compilation :
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;co&quot;&gt;#article&lt;/span&gt; {
  &lt;span class=&quot;ke&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;fl&quot;&gt;100%&lt;/span&gt;;
 }
  &lt;span class=&quot;co&quot;&gt;#article&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;p&lt;/span&gt;, &lt;span class=&quot;co&quot;&gt;#article&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;div&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;font-size&lt;/span&gt;: &lt;span class=&quot;fl&quot;&gt;2em&lt;/span&gt;;
 }
  &lt;span class=&quot;co&quot;&gt;#article&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;a&lt;/span&gt;, &lt;span class=&quot;co&quot;&gt;#article&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;a&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;font-weight&lt;/span&gt;: &lt;span class=&quot;vl&quot;&gt;bold&lt;/span&gt;;
 }
  &lt;span class=&quot;co&quot;&gt;#article&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;pre&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;font-size&lt;/span&gt;: &lt;span class=&quot;fl&quot;&gt;3em&lt;/span&gt;;
 }
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Dans cet exemple on n'a utilis&#233; que deux niveaux d'imbrication. En css classique, on se trouve oblig&#233; de r&#233;&#233;crire tout la structure de chaque branche jusqu'&#224; la racine pour chaque style. Le jour o&#195;&#185; on d&#233;cide de changer le nom de la classe ou de l'identification, &#231;a ne sera pas facile, sans parler d'une int&#233;gration d'un style parent tout pr&#233;s de la racine.&lt;/p&gt;
&lt;p&gt;Un autre exemple particulier pour les hyperliens&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;kw&quot;&gt;a&lt;/span&gt;
  &lt;span class=&quot;ps&quot;&gt;:font-weight&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;bold&lt;/span&gt;
  &lt;span class=&quot;ps&quot;&gt;:text-decoration&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;none&lt;/span&gt;
  &lt;span class=&quot;er&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ps&quot;&gt;:hover&lt;/span&gt;
    &lt;span class=&quot;ps&quot;&gt;:text-decoration&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;underline&lt;/span&gt;
  &lt;span class=&quot;er&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ps&quot;&gt;:visited&lt;/span&gt;
    &lt;span class=&quot;ps&quot;&gt;:color&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;black&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

apr&#232;s compilation :
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;kw&quot;&gt;a&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;font-weight&lt;/span&gt;: &lt;span class=&quot;vl&quot;&gt;bold&lt;/span&gt;;
    &lt;span class=&quot;ke&quot;&gt;text-decoration&lt;/span&gt;: &lt;span class=&quot;vl&quot;&gt;none&lt;/span&gt;;
 }
&lt;span class=&quot;kw&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;ps&quot;&gt;:hover&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;text-decoration&lt;/span&gt;: &lt;span class=&quot;vl&quot;&gt;underline&lt;/span&gt;;
 }
&lt;span class=&quot;kw&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;ps&quot;&gt;:visited&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;color&lt;/span&gt;:&lt;span class=&quot;vl&quot;&gt;black&lt;/span&gt;;
 }
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Pour de simples feuilles de style de quelques dizaines de lignes, on peut s'en pass&#233; de SASS. Mais pour des projets d'envergure avec des interfaces et templates complexes, SASS devient une necessit&#233;.&lt;br/&gt;De m&#234;me pour l'organisation de la structure; il est plus facile de retrouver le style &#224; changer. Sur des fichiers en CSS qui d&#233;passent les 50ko (j'en ai vu beaucoups), on &#224; tendance &#224; rajouter des styles imbriqu&#233;s &#224; la fin du fichier dans la pr&#233;cipitation. On se retrouve avec du code &#233;parpill&#233;. La roulette de la souris et l'ascenceur de l'&#233;diteur chauffent et nos yeux se fatiguent plus vite &#224; la recherche des relations de positionnement : absolute, relative,... et ce n'est qu'un simple cas parmi d'autre quand on commence &#224; se frotter la t&#234;te et ouvrir l'&#233;diteur en plein &#233;cran en r&#233;duisant la taille du caract&#232;re... D'ailleurs on a trouv&#233; comment charger encore plus les CSS par des commentaires utilis&#233;s comme rep&#232;res&lt;/p&gt;
&lt;p&gt;SASS nous r&#233;serve encore d'autres surprises, l'utilisation de constantes,  d'op&#233;rations arithm&#233;tiques dans une feuille de style, un sacr&#233; gain de temps &#224; la conception et &#224; la maintenance&lt;/p&gt;
&lt;p&gt;Voici un exemple tir&#233; directement du &lt;a href=&quot;http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html&quot; alt=&quot;sass documentation&quot;&gt;site officiel de haml-sass&lt;/a&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;main_width&lt;/span&gt; = &lt;span class=&quot;fl&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;unit1&lt;/span&gt; = &lt;span class=&quot;kw&quot;&gt;em&lt;/span&gt;
&lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;unit2&lt;/span&gt; = &lt;span class=&quot;kw&quot;&gt;px&lt;/span&gt;
&lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;bg_color&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;#a5f39e&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#main&lt;/span&gt;
  &lt;span class=&quot;ps&quot;&gt;:background-color&lt;/span&gt; = &lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;bg_color&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;p&lt;/span&gt;
  &lt;span class=&quot;ps&quot;&gt;:background-color&lt;/span&gt; = &lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;bg_color&lt;/span&gt; + &lt;span class=&quot;co&quot;&gt;#202020&lt;/span&gt;
  &lt;span class=&quot;ps&quot;&gt;:width&lt;/span&gt; = &lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;main_width&lt;/span&gt; + &lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;unit1&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;cl&quot;&gt;.thumb&lt;/span&gt;
  &lt;span class=&quot;ps&quot;&gt;:width&lt;/span&gt; = (&lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;main_width&lt;/span&gt; + &lt;span class=&quot;fl&quot;&gt;15&lt;/span&gt;) + &lt;span class=&quot;er&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;unit2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

ce qui donne
&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;
&lt;span class=&quot;co&quot;&gt;#main&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;cr&quot;&gt;#a5f39e&lt;/span&gt;;
 }
&lt;span class=&quot;co&quot;&gt;#main&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;p&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;background-color&lt;/span&gt;: &lt;span class=&quot;cr&quot;&gt;#c5ffbe&lt;/span&gt;;
    &lt;span class=&quot;ke&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;fl&quot;&gt;10em&lt;/span&gt;;
 }
&lt;span class=&quot;co&quot;&gt;#main&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;cl&quot;&gt;.thumb&lt;/span&gt; {
    &lt;span class=&quot;ke&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;fl&quot;&gt;25px&lt;/span&gt;;
 }
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Le jackpot !!!, on a l'impression d'avoir un tableur avec des formules arithm&#233;tiques dans les cellules en CSS pour calculer automatiquement une mise en page. Plus la peine de recr&#233;er un CSS pour l'impression ou d'autre supports m&#233;diatiques.&lt;/p&gt;
&lt;p&gt;Place &#224; votre imagination pour &#233;tendre des combinaisons inimaginables.&lt;br/&gt;D&#233;sormais, l'&#233;criture n'est plus un exercice fastidieux, mais une &#233;preuve d'intelligence et d'imagination&lt;/p&gt;
&lt;p&gt;Il reste encore d'autre fonctions tr&#232;s interessante que j'essayerais d'exposer dans un futur post&lt;/p&gt;&lt;br/&gt;&lt;br/&gt;</body>
  <cat-id type="integer">2</cat-id>
  <created-at type="datetime">2009-05-27T16:45:57Z</created-at>
  <id type="integer">3</id>
  <pagetitle>SASS au del&#224; du CSS</pagetitle>
  <photo-content-type>image/png</photo-content-type>
  <photo-file-name>marylin.png</photo-file-name>
  <photo-file-size type="integer">23528</photo-file-size>
  <short>Vous vous rappellez de haml? L&#224;, on va vous parler de son petit fr&#232;re SASS (Syntactically Awesome StyleSheets), inutile de vous expliquer son installation c'est d&#233;taill&#233; dans ...</short>
  <title>SASS, la r&#233;invention du CSS</title>
  <updated-at type="datetime">2009-08-24T22:06:05Z</updated-at>
  <url>sass</url>
</post>
