= Haml (XHTML Abstraction Markup Language) Haml is a markup language that's used to cleanly and simply describe the XHTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such PHP, RHTML, and ASP. However, Haml avoids the need for explicitly coding XHTML into the template, because it iself is a description of the XHTML, with some code to generate dynamic content. == Features * Whitespace active * Well-formatted markup * DRY * Follows CSS conventions * Interpolates Ruby code * Implements Rails templates with the .haml extension == Authors Haml was originally created by Hampton Catlin (hcatlin). Help with the Ruby On Rails implementation and much of the documentation by Jeff Hardy (packagethief). Nathan Weizenbaum (Nex3) contribued the buffered-engine code along with many other enhancements including the silent-line syntax ("-"). If you use this software, you must pay Hampton a compliment. Say something nice about it. Beyond that, the implementation is licensed under the MIT License. Ok, fine, I guess that means compliments aren't *required*. == Formatting Haml is sensitive to spacing and indentation; it uses nesting to convey structure. When you want an element to have children, indent the lines below it using two spaces. Remember, spaces are not the same as tabs. Example: #contact %h1 Eugene Mumbai %ul.info %li.login eugene %li.email eugene@example.com is compiled to:
The magical fruit
hello
/^^^\ |[] []| |_____|
Sign my guestbook
You can also specify the version and type of XHTML after the !!!. XHTML 1.0 Strict, Transitional, and Frameset and XHTML 1.1 are supported. The default version is 1.0 and the default type is Transitional. For example, !!! 1.1 is compiled to: and !!! Strict is compiled to: If you're not using the UTF-8 characterset for your document, you can specify which encoding should appear in the XML prolog in a similar way. For example, !!! XML iso-8859-1 is compiled to: ==== / The forward slash character, when placed at the beginning of a line, wraps all text after it in an HTML comment. For example: %billabong / This is the billabong element I like billabongs! is compiled to:hi there reader! yo
==== ~ The tilde character works the same as the equals character, but the output is modified in such a way that newlines in whitespace-sensitive elements work properly. For example: %foo = "Woahthis is \ncrazy" %foo2 ~ "Woah
this is \ncrazy" is compiled to:
this iscrazy
this iscrazy
hello there you!
===== Blocks Like XHTML tags, you don't need to explicity close your Ruby blocks in Haml. Rather, they're automatically closed based on spacing. A block begins whenever the indentation is increased after a silent script command, and ends when the indentation decreases (as long as it's not an +else+ clause or something similar). For example: - (42...47).each do |i| %p= i %p See, I can count! is compiled to:42
43
44
45
46
Another example: %p - case 2 - when 1 = "1!" - when 2 = "2?" - when 3 = "3." is compiled to:2?
== Using Haml as a Rails plugin Write Rails templates with the .haml extension. Example: # file: app/views/movies/teen_wolf.haml %html %head %title= "Teen Wolf (1985)" %body #contents %h1 "A highschooler discovers that he is a werewolf" %ul.cast %li "Scott Howard" %li "Rupert 'Stiles' Stilinski" %li "Lisa 'Boof' Marconi" %li "Lewis" is compiled to: