Haml
Developer(s) | Norman Clarke, Natalie Weizenbaum, Hampton Catlin |
---|---|
Stable release | 4.0.3 / May 21, 2013 |
Written in | Ruby |
Operating system | Cross-platform |
Type | Template engine |
License | MIT License |
Website |
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. It is 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.
Haml's equivalent for CSS is Sass.
Principles
HAML was created initially by Hampton Catlin as an experiment to satisfy the following core principles:[1]
- Markup should be beautiful
- Markup should be DRY
- Markup should be well-indented
- HTML structure should be clear
Example
Note: This is a simple preview example and may not reflect the current version of the language.
!!! %html{ :xmlns => "http://www.w3.org/1999/xhtml", :lang => "en", "xml:lang" => "en"} %head %title BoBlog %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"} %link{"rel" => "stylesheet", "href" => "main.css", "type" => "text/css"} %body #header %h1 BoBlog %h2 Bob's Blog #content - @entries.each do |entry| .entry %h3.title= entry.title %p.date= entry.posted.strftime("%A, %B %d, %Y") %p.body= entry.body #footer %p All content copyright © Bob
The above Haml would produce this XHTML:
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>BoBlog</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
<link href="/stylesheets/main.css" media="screen" rel="Stylesheet" type="text/css" />
</head>
<body>
<div id='header'>
<h1>BoBlog</h1>
<h2>Bob's Blog</h2>
</div>
<div id='content'>
<div class='entry'>
<h3 class='title'>Halloween</h3>
<p class='date'>Tuesday, October 31, 2006</p>
<p class='body'>
Happy Halloween, glorious readers! I'm going to a party this evening... I'm very excited.
</p>
</div>
<div class='entry'>
<h3 class='title'>New Rails Templating Engine</h3>
<p class='date'>Friday, August 11, 2006</p>
<p class='body'>
There's a very cool new Templating Engine out for Ruby on Rails. It's called Haml.
</p>
</div>
</div>
<div id='footer'>
<p>
All content copyright © Bob
</p>
</div>
</body>
</html>
Implementations
The official implementation of Haml has been built for Ruby with plugins for Ruby on Rails and Merb, but the Ruby implementation also functions independently.
There are also implementations in other languages:
- HamlPy (Python)
- LuaHaml (Lua)
- MonoRail NHaml (ASP.NET)
- NHaml (.NET)
- Fammel (PHP)
- HAML-TO-PHP (PHP5)
- pHAML (PHP)
- phamlp (PHP)
- phpHaml (PHP5)
- Multi target HAML (PHP5.3)
- haml-js (JavaScript)
- Text::Haml (Perl)
- Scalate (Scala)
- JHaml (Java)
- Hart (Dart)
- cl-haml (Common Lisp)
Development
Haml was created in May 2006 by Hampton Catlin. Shortly thereafter Natalie Weizenbaum became integral in the design of many of Haml's features and maintained the implementation for many years.
See also
- BBCode
- eRuby
- Markaby
- Ruby
- Ruby on Rails
- YAML
- Sass - A similar system for CSS, also designed by Catlin.
- Website Meta Language - Another template language with similar functionalities
- Web template - General concept of template to HTML expansion
References
External links
- Official Haml Website
- Haml source code repository (Git)
- phpHaml (Haml implementation for PHP 5)
- Haml Google Group
- Haml 1.0 announcement on official Ruby on Rails weblog
- Haml 2.0 announcement on Natalie Weizenbaum's blog
- Interview with Haml creator on official Rails podcast
- Interview with Natalie Weizenbaum and Chris Eppstein Haml, Sass and Compass maintainers on The Changelog podcast
- Rails Wiki: Using Haml with Ruby on Rails