Questions tagged [haml]

HAML is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. It can be used as a standalone HTML generation tool or as a template rendering engine in a web framework such as Ruby on Rails or Ramaze. HAML templates are pre-compiled into plain HTML templates which is consumed by a client's web browser to render information sent by the server as a HTML web page.

HAML (HTML Abstraction Markup Language) is an indentation based, terse page description markup. It features among other things autoclosing of tags and convenient shorthands to set class and id attributes.


Example

page and its conversion :

erb

<div id='content'>
  <div class='left column'>
    <h2>Welcome to our site!</h2>
    <p><%= print_information %></p>
  </div>
  <div class="right column">
    <%= render :partial => "sidebar" %>
  </div>
</div>

HAML

#content
  .left.column
    %h2 Welcome to our site!
    %p= print_information
  .right.column
    = render :partial => "sidebar"

Where to start:

  1. Getting Started Tutorial

  2. Html2haml converter

3540 questions
28
votes
3 answers

Dynamic class name in HAML

Is there a better way to convert the following to HAML? <% flash.each do |key, value| %>
<%= value %>
<% end %> Best I can do is: - flash.each do |key, value| %div{:class => "flash " + key.to_s}=…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
27
votes
3 answers

Is it worth to learn haml & sass?

In your professional experience have haml & sass proved to be useful? In which way?
Victor
  • 23,172
  • 30
  • 86
  • 125
27
votes
2 answers

Producing single-line comments with HAML?

I'm trying to generate a comment on a single line at the end of an HTML file: I have tried / generated by #{@server_name} But this outputs it over 3 lines - I've tried /…
Marklar
  • 1,056
  • 2
  • 13
  • 31
25
votes
5 answers

How do I wrap multiline Ruby arguments in HAML?

How can I use multiple lines for a single Ruby statement in HAML? For example, I'd like to write something like the following: - entries = [{ - :title => "The Fellowship of the Ring", - :body => "We should walk instead of fly" - }] !!!…
jhchen
  • 14,355
  • 14
  • 63
  • 91
25
votes
4 answers

How do I make a simple dot "." in HAML?

In my Ruby on Rails Project I use HAML, I need to translate something like this
foo bar.
into HAML. It should look like: .divclass foo %a bar . The period at start is not working because its used by HAML. So how can I…
Calmon
  • 583
  • 5
  • 18
24
votes
7 answers

Ruby best practice : if not empty each do else in one operator

1.I can't find an elegant way to write this code: if array.empty? # process empty array else array.each do |el| # process el end end I'd like to have one loop, without writing array twice. I read this, but there is no solution good…
Augustin Riedinger
  • 20,909
  • 29
  • 133
  • 206
24
votes
1 answer

How to add an image to the contents using HAML?

New to this tagging language, and I'm having trouble finding documentation mentioning how to work with images. An example or two would be fantastic. Btw, I did refer to this discussion, but not sure if that's what I need.
stanigator
  • 10,768
  • 34
  • 94
  • 129
23
votes
2 answers

HAML - add type=text/css to