

HTML and CSS Preprocessors - shay-howe
http://learn.shayhowe.com/advanced-html-css/preprocessors

======
crazygringo
I've never heard of HAML before. From the website, is it literally just
"markup should be beautiful"?

I mean, LESS/SASS add real functionality. Even CoffeeScript adds functionality
to JavaScript, beyond just changing the syntax. But is there any functional
advantage to use HAML? Is it actually worth half a chapter of an "advanced
guide to HTML & CSS"?

(Totally my opinion, but it doesn't even look clearer or "more beautiful" to
me, but maybe that's just because I'm used to HTML.)

~~~
danneu
Oh, come on. You got hung up on an adjective used in a hero unit.

<http://haml.info/docs/yardoc/file.REFERENCE.html>

Filters, passing Ruby objects into it to generate classes, hell, even markup
comments that don't show up in html.

------
jmduke
I love this series.

Can anyone give an example of when HAML would be used in the 'real world'? I
can't imagine it filling a niche that isn't covered by any of the other
templating languages: what would seem most ideal is a combination of say,
Jinja and HAML.

~~~
AlwaysBCoding
I'm finding that it's a lot cleaner to use with Javascript. For example, say
you have an array of items and you want to create a fieldset for each item,
and add an attribute of "data-id", and "data-category" to each fieldset so you
can grab them with jQuery later on.

In HAML all you have to do is this...

\- @items.each do |item|

    
    
      %fieldset{:data => {:id => item.id, :category => item.category}}
    

===

In ERB the equivalent would be...

<% @items.each do |item| %>

    
    
      <fieldset data-id="<%= item.id %>" data-category="<%= item.category %>">
    
      </fieldset>
    

<% end %>

===

It's a lot cleaner in HAML, especially extrapolated out over larger views.

~~~
rhizome
Look into `tag`:
[http://api.rubyonrails.org/classes/ActionView/Helpers/TagHel...](http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-
i-tag)

ERB view:

    
    
        <%= render @items %>
    

items/_item.html.erb:

    
    
        <%= tag "fieldset", data: { id: item.id, category: item.category } %>

------
nbashaw
Quick nitpick: HAML is not a pre-processor for HTML, it is a templating
language.

~~~
liquidise
Anything that is self-described as an "abstraction markup language" and must
be compiled into the language it abstracts is really a pre-processor.

Regardless of intended use cases, i cant think of a better definition.

~~~
cpleppert
I disagree. A preprocessor doesn't 1) transform the entire document 2) doesn't
fully parse the input document that is exactly why the c family on languages
has such difficulty with modules: they are hacked on with a preprocessor and
aren't part of the language.

