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
52
votes
9 answers

Convert existing html.erb to Haml

I have a rails project, the views only consist with HTML.ERB files, my client wants to convert ERB to HAML. I have too many views file. It's taking a huge amount of time to convert file by file. So that any simply way I can convert HTML to haml? I…
palani
  • 4,661
  • 8
  • 31
  • 36
50
votes
3 answers

Empty attribute with Ruby HAML

I'm implementing Schema microformats on a Ruby project using HAML and can't figure out how to set an empty attribute on a tag. I tried nil and false, but they simply do not shown. Example:
I'm tring to set an empty itemscope…
StrangeElement
  • 2,282
  • 2
  • 16
  • 20
49
votes
6 answers

haml by default

Is there a way to configure rails to use haml by default, i.e. when a scaffold is generated the according scaffold_name/index.html.haml is generated instead of scaffold_name/index.html.erb. Similar to how you are able to add…
rudolph9
  • 8,021
  • 9
  • 50
  • 80
48
votes
3 answers

put haml tags inside link_to helper

is it possible to add html-content inside a link_to helper in HAML? i tried this, but all i get is a syntax error: = link_to "Other page", "path/to/page.html" %span.icon Arrow expected output: Other Page
flavaflo
  • 908
  • 1
  • 8
  • 13
47
votes
7 answers

Should I use haml or erb or erubis for potentially high traffic site?

I have been playing with Haml recently and really like the way the resulting code looks to me...the developer. I'm also not too worried about a designer being able to consume or change it...we're a small team. That said, beginning work on a project…
John Wells
46
votes
2 answers

Inline ruby in :javascript haml tag?

Hey is there a way I can do this in haml? :javascript var Tab = <%= @tab %> I could just add a helper I guess like: But it'd be nice to use HAML!
Alex Fox
  • 1,175
  • 2
  • 15
  • 27
46
votes
1 answer

Removing whitespaces in HAML

Is there a way to achieve this in HAML?

Lorem ipsumdolor

I used this online tool conversor (http://html2haml.heroku.com/) %h1 Lorem ip %span.red sum %span.subtitle dolor and…
xbelanch
  • 844
  • 1
  • 12
  • 21
45
votes
7 answers

How to insert special HTML-symbols with HAML

When I'm saying: %p= item.price + " dollars" I'm getting 50  ;dollars instead of having non-breakable space symbol. How to insert this and another special symbols using HAML ?
AntonAL
  • 16,692
  • 21
  • 80
  • 114
40
votes
6 answers

Using Haml & Sass with Eclipse

Are there any plugins for eclipse that add syntax highlighting and other niceties for editing Haml and Sass? Google searches only seem to point to a dead project on lucky-dip.net. Note: it's Sass I'm most interested in. A solution for using just…
Sam Hasler
  • 12,344
  • 10
  • 72
  • 106
39
votes
2 answers

How can I conditionally wrap some HAML content in a tag?

How can I use a condition to decide whether to output a surrounding tag in HAML? I'm trying to create the DRY version of the code below. - if i_should_link %a{:href => url} .foo .block .of .code - else .foo .block …
Sean Ahrens
  • 1,025
  • 1
  • 9
  • 18
39
votes
5 answers

inline tag in haml

In html, you can do something like this

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget aliquet odio. Fusce id quam eu augue sollicitudin imperdiet eu ac eros. Etiam nec nisi lorem, ac venenatis ipsum. In…

Matt Briggs
  • 41,224
  • 16
  • 95
  • 126
39
votes
4 answers

How to send back js.haml in rails

I have a rails create action which send back some jquery in a file: create.js.erb var appearance = $("<%= escape_javascript(render(:partial => @appearance)) %>").effect("highlight", {color: '#E6ff00'},…
Cameron
  • 4,181
  • 9
  • 36
  • 40
38
votes
8 answers

Best strategy to use HAML template with Backbone.js

Im getting into Backbone.js to structure the javascript code for my project and I love HAML for templating on the backend(rails), so Id like to use it for Backbone Views templating. I know there is several HAML ports to Javascript,…
Vlad Gurovich
  • 8,463
  • 2
  • 27
  • 28
38
votes
6 answers

2 Spaces or 1 Tab, what's the standard for indentation in the Rails Community?

I've noticed that most of the HTML/XML/HAML that gets generated from plugins uses 2 spaces instead of 1 tab. I use textmate and have tabs set to 4 spaces for HAML/HTML/XML and 2 spaces for Javascript/Ruby, but I only have to press the tab key once…
Lance
  • 75,200
  • 93
  • 289
  • 503
37
votes
2 answers

Using layouts in HAML files independently of Rails

My end goal is to create several static HTML files for hand-off to other folks. But for my workflow, I'd like to have HAML as the basic source files. In doing so, I'd hope to DRY up the process at least on my side. Now I have a lot of pages that…
Steven
  • 17,796
  • 13
  • 66
  • 118