Halloween
Tuesday, October 31, 2006
Happy Halloween, glorious readers! I'm going to a party this evening... I'm very excited.
Haml ( HTML Abstraction Markup Language) is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Similar to other template systems like eRuby, Haml also embeds some code that gets executed during runtime and generates HTML code in order to provide some dynamic content. In order to run Haml code, files need to have a extension. These files are similar to .erb or .eRuby files, which also help embed Ruby code while developing a web application.
While parsing code comments, Haml uses the same rules as Ruby 1.9 or later. Haml understands only ASCII-compatible encodings, like UTF-8, but not UTF-16, or UTF-32, because these are not compatible with ASCII.
Haml can be used at the command line, as a separate Ruby module, or in a Ruby on Rails application.
Version 2.2.0 was released in July 2009 with support for Ruby 1.9 and Rails 2.0 or above. Version 3.0.0 was released in May 2010, adding support for Rails 3 and some performance improvements. The fourth major version broke compatibility with previous versions, only supporting Rails 3 and Ruby 1.8.7 or above, and marked the switch to semantic versioning. Several amendments like increasing the performance, fixing a few warnings, compatibility with latest versions of Rails, fixes in the documentation, and many more were made in the Haml 4 series. Version 5.0.0 was released in April 2017. It supports Ruby 2.0.0 or above and drops compatibility with Rails 3. A 'trace' option, which helps users to perform tracing on Haml template, has been added.
These render to the following HTML code:
Hello, World!
def index @message = "Hello, World!" endend
%p= @message
This renders to:
Hello, World!
Hello, World!
Haml::Engine is a Haml class.
%div.recipes %h1= recipe.name %h3= recipe.category %div %h4= recipe.description |
|
|
Key differences are:
%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:
Tuesday, October 31, 2006
Happy Halloween, glorious readers! I'm going to a party this evening... I'm very excited.
Friday, August 11, 2006
There's a new Templating Engine out for Ruby on Rails. It's called Haml.
BoBlog
Bob's Blog
Halloween
New Rails Templating Engine
|
|