Introduction to the Haml gem

Installation

gem install haml

Output

Fetching: haml-4.0.3.gem (100%)

HEADS UP! Haml 4.0 has many improvements, but also has changes that may break your application:

For more info see:

http://rubydoc.info/github/haml/haml/file/CHANGELOG.md

Successfully installed haml-4.0.3 Parsing documentation for tilt-1.4.1 Installing ri documentation for tilt-1.4.1 Parsing documentation for haml-4.0.3 Installing ri documentation for haml-4.0.3 Done installing documentation for tilt, haml after 64 seconds 2 gems installed

Example

require 'haml'

template =<<HTML
%html
  %head
    %title Haml Example
  %body
    #content
      %p
        This is an example of using Haml on Sinatra.
        You can use Haml in all your projeccts now, instead
        of Erb. I'm sure you'll find it much easier!
HTML

haml_engine = Haml::Engine.new(template)
output = haml_engine.render
puts output

Output

&l

t;html>

<head>
    <title>Haml Example</title>
  </head>
  <body>
    <div id='content'>
      <p>
        This is an example of using Haml on Sinatra.
        You can use Haml in all your projeccts now, instead
        of Erb. I'm sure you'll find it much easier!
      </p>
    </div>
  </body>
</html>

Resources

Tags:
Source:
2300hrs.txt
Published:
16-08-2013 23:00