Haml
Haml | |
---|---|
File extension : |
.haml
|
Developed by: | Nathan Weizenbaum, Hampton Catlin |
Current version: | 4.1.0.beta.1 (as of June 7, 2015) |
Type: | Markup language |
Website : | haml.info |
Haml ( HTML Abstraction Markup Language ) is a under the MIT license published simplified markup language that is used to carry a clear and simple way XHTML to describe a web document without having to enter mix using inline encoding executable program code. It was developed to avoid many of the weaknesses of traditional template mechanisms and to make markup language as elegant as possible. Haml acts as a replacement for inline template mechanisms such as those used in PHP , JSP , RHTML or ASPare common. Haml avoids the need to explicitly code XHTML in templates because it is a description for XHTML itself with some code for dynamic content.
The scope of Haml also included Sass , an analogue to CSS . Today, however, Sass and Haml are developed, versioned and delivered separately.
Principles
- Markup languages should be nice
- Markup languages should not be used simply as a tool to get web browsers to display a page the way the author wants it to be displayed. That representation isn't the only thing people need to see. You need to see, change, and understand the markup language. Therefore, the markup language should be just as user-friendly and pleasant as the result displayed in the web browser.
- Should markup languages DRY be
- XHTML contains a lot of repetitions. Most elements must be specified twice, once before and once after their content. ERB adds even more repetition and unnecessary characters. Haml avoids all of this by relying on indentation, not text, to determine where elements and blocks of code start and end. This not only leads to smaller templates, it also makes the code more readable and “cleaner”.
- Markup languages should be indented correctly
- One of the major difficulties with traditional template languages is that not only do they forego encouraging the use of consistent and consistent indentation, but they often get in the way of it. It is often difficult or impossible to apply a usable indentation. This often leads to confusing and illegible XHTML. Haml formats the tags so that they are always neatly indented and reflect the underlying structure of the document.
- The XHTML structure should be clear
- XML and XHTML are formats that were created for the idea of the structured document. This structure is reproduced in these markup languages and should also be seen in the same way in a meta markup language like Haml. Because Haml's logic is based on the indentation of the sub-elements, this structure is naturally preserved, making it much easier and more logical for human readers to grasp.
disadvantage
- Empty space is essential in Haml . Haml relies on consistent indentation. Tabs and spaces must be used consistently throughout the entire document.
- There are (yet) no WYSIWYG editors for Haml, while there are a large number of those for XHTML and HTML. But the growing community of Haml users has produced a bunch of add-ons to many common integrated development environments , such as Eclipse (including popular tools derived therefrom such as RadRails or Aptana ), jEdit , NetBeans and editors such as TextMate , Emacs or Vim . These allow developers to edit Haml in an environment that takes indentation and syntax into account.
example
Note: Please note that this example does not necessarily reflect the current state of development of Haml.
!!! %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"} = stylesheet_link_tag 'main' %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 Haml text above should result in the following XHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 Haml implementation was developed for Ruby with plugins for Ruby on Rails and Merb, but the Ruby implementation also works independently (without Rails and without Merb).
There are also implementations in other programming languages:
- GHRML (Python)
- HamlPy (Python)
- LuaHaml (Lua)
- MonoRail NHaml (ASP.NET)
- NHaml (.NET)
- Fammel (PHP)
- pHAML (PHP)
- phamlp (PHP)
- phpHaml (PHP5)
- haml-js (JavaScript)
- Text :: Haml (Perl)
- Scalate (Scala)
- JHaml (Java)
development
Haml was invented by Hampton Catlin in May 2006. Together with Nathan Weizenbaum, he continues to develop the code base .
See also
Web links
- official Haml-WWW-Page (English)
- Haml source code repository (Git)
- phpHaml Haml implementation for PHP 5 (English)
- Introductory article for Haml on unspace.ca (English)
- Haml Google Group (English)
- Haml 1.0 announcement in the official Ruby on Rails weblog (English)
- Haml 2.0 announcement on Nathan Weizenbaum Blog (English)
- Interview with Haml-inventor on an official Rails podcast (English)
- Interview with Nathan Weizenbaum and Chris Eppstein, the Haml, Sass and Compass maintainers at The Changelog podcast (English)
- Rails Wiki: using Haml with Ruby on Rails (English)
Individual evidence
- ^ Haml and Sass are Split. (No longer available online.) In: Posts about Haml. Archived from the original on December 27, 2011 ; Retrieved January 7, 2012 . Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.