background preloader

Haml

Facebook Twitter

Haml. Haml (HTML Abstraction Markup Language) is a lightweight markup language that is used to describe the XHTML of any web document without the use of traditional inline coding.

Haml

It’s designed to address many of the flaws in traditional templating engines, as well as making markup as elegant as it can be. Haml functions as a replacement for inline page templating systems such as PHP, RHTML, and ASP. However, Haml avoids the need for explicitly coding XHTML into the template, because it is itself a description of the XHTML, with some code to generate dynamic content.

Principles[edit] Markup should be beautiful Markup should not be used merely as a tool to get browsers to render a page the way its author wants it rendered. Markup should be DRY XHTML involves major repetition. Markup should be well-indented One of the major problems with traditional templating languages is that not only do they not encourage well-indented code, they actively make it challenging, or even impossible, to write.

<! Haml/haml. Tutorial. Before we start this tutorial, I want to make one thing clear.

Tutorial

After you look at this, go and convert one of your ERB files to Haml. Just try it. Just take the file and start hitting delete. You don’t have to keep the file if you don’t like it, but after you’re done with this tutorial, just try one file. Haml feels odd for the first 20 minutes, but then after that you will be faster. Getting Started First, get Haml and install the gem (this tutorial assumes you’re using Rails — it should apply to other frameworks and standalone Haml just as well, though). App/views/account/login.html.erb → app/views/account/login.html.haml Now, when you view that page, instead of ERB getting its hands on the template, it’s handled by Haml instead.

How to Convert Let’s start off with some basic ERB that we want to convert. Haml %strong= item.title In Haml, we write a tag by using the percent sign and then the name of the tag. Adding Attributes <strong class="code" id="message">Hello, World! .content Hello, World! Editors. Various text editors have different levels of support for Haml.

Editors

Here’s a list of all known packages — if you create or learn of a more updated version, please email haml@googlegroups.com. Haml’s syntax is updated from time to time, meaning some of these modes might not be as current as possible. If anyone wants to take on the task of updating an old mode, that would be greatly appreciated. Coda/SubEthaEdit by Gianni Chiappetta. Eclipse by Brad Wilson. Haml.