SlideShare a Scribd company logo
HAML
Web Templating for Human Beings
Introduction

HAML is Markup language

 Its purpose is to describe
HTML in a clean, simple way
Introduction

    Lets face it, HTML is
    pretty annoying
Introduction


HAML aims to solve problems
with ordinary HTML coding
Introduction
• Markup should be beautiful
• Markup should be DRY
 • Too much repetition in HTML and
    templating engines like ERB
• Markup should be well-indented
• Markup structure should be clear
The problems with HTML
          Programmers don’t speak
          HTML

          The whole concept of
          markup is foreign as
          there’s no logic involved.
The problems with HTML
        The mix of markup and
        logic seems a bit odd, if not
        ugly.

        Markup should be beautiful,
        not just code
The problems with HTML
There’s just too much repetition in HTML.
All those open and close tags are redundant
The problems with HTML

          Keeping track of open
          and close HTML and
          template tags is tedious.
HAML to the rescue
<ul id=”navigation”>
 <li class=”menu_item”>
   <a href=”/home” title=”Home”>Home</a>
 </li>
</ul>

%ul#navigation
 %li.menu_item
   %a({:href => “/home”,
       :title => “Home”
      })
      Home
HAML Basics
!!! 5
%html
  %head
    %title Haml Test
  %body
    #header
      %h1 Welcome to my blog
      %nav#navigation
    #content
      = yield
HAML Basics

• HTML Tags are prefixed with %
• ID attribute is prefixed with #
• Class attribute is prefixed with .
• Default HTML tag is <div>
HAML Basics

• Additional attributes are passed as
 • space-separated attr./value pairs
    •   %a(title=@title href=href) Stuff

  • attr./value hash
    •   %a{:title => @title, :href => href} Stuff
HAML Formatting
Remove whitespace using < and > characters

%img
%img>
%img

Compiles into

<img /><img /><img />
HAML Formatting

%p<= “FoonBar”

Compiles into

<p>Foo
Bar</p>
HAML Formatting

Escape HTML entities using the & sign

&= “I like Cheese & Crackers”

Compiles into

I like Cheese &amp; Crackers
HAML Formatting

Disable HTML unescaping using the ! sign

!= “<strong>Foo</strong>”

Compiles into

<strong>Foo</strong>
Dynamic HAML

HAML supports dynamic content as well as
static content.

(let the real fun begin)
Dynamic HAML

• We use the “=” sign to evaluate dynamic
  code and assign the value to the desired tag
• We use the “-” sign to run code without
  appending a value to any tag
• We use Ruby interpolation to mix static
  and dynamic strings
Dynamic HAML
%h2= “Posts for #{Time.now}”

%ul#posts

- @posts.each do |post|

 %li.post_item
   %h3= post.title
   %p= post.post
   %p=
Dynamic HAML
HAML doesn’t limit us to just plain old code
running and evaluation.

Since markup documents may contain a mix
of other languages (like Javascript or CSS),
we can use Filters to parse those languages
into HAML
HAML Filters
HAML Filters
:javascript
  document.getElementById(‘content’);

:css
  body{
    font:normal normal 14px Arial,sans-serif;
  }

:sass
li
   font:
     family: serif
HAML Filters

:markdown
  Textile
  =======
  Hello, *World*

:textile
  I *really* prefer _#{h flavor}_ jam.
HAML Filters
:zohar

module Haml::Filters::Zohar
  include Haml::Filters::Base

  def render(text)
    # run some snazzy logic
    text
  end
end
HAML interoperability
• Python - HamlPy & DAML (Django)
• PHP - Fammel, pHAML, phpHAML
• .NET - NHaml, MonoRail NHaml
• Javascript - HAML-js
• Perl - Text::Haml
• Java - JHaml
HAML


Questions ?

More Related Content

PDF
Haml. New HTML? (RU)
PPTX
Haml in 5 minutes
PPTX
Presentation
PPT
php 1
PPT
html
DOC
Handout1 intro to html
PPTX
Introduction to xhtml
PDF
Hows Haml?
Haml. New HTML? (RU)
Haml in 5 minutes
Presentation
php 1
html
Handout1 intro to html
Introduction to xhtml
Hows Haml?

What's hot (19)

PPT
PPT
LEARN HTML IN A DAY
DOC
Handout2 formatting tags
PPTX
HTML 5 Basics Part One
PDF
-Haml Presentation
PPTX
HTML/CSS/java Script/Jquery
PPT
Make Css easy : easy tips for css
PDF
HTML 5 Step By Step - Ebook
PPTX
Html and Xhtml
PPT
Introduction to Cascading Style Sheets
PDF
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
PPT
2. html attributes
PPTX
Elements of html powerpoint
PPT
A quick guide to Css and java script
PPTX
Html basic
PPT
Origins and evolution of HTML and XHTML
PDF
Web I - 02 - XHTML Introduction
PDF
Cucumber - use it to describe user stories and acceptance criterias
DOCX
Html example
LEARN HTML IN A DAY
Handout2 formatting tags
HTML 5 Basics Part One
-Haml Presentation
HTML/CSS/java Script/Jquery
Make Css easy : easy tips for css
HTML 5 Step By Step - Ebook
Html and Xhtml
Introduction to Cascading Style Sheets
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
2. html attributes
Elements of html powerpoint
A quick guide to Css and java script
Html basic
Origins and evolution of HTML and XHTML
Web I - 02 - XHTML Introduction
Cucumber - use it to describe user stories and acceptance criterias
Html example
Ad

Viewers also liked (8)

PDF
Haml
PDF
Rolling Your Own CSS Methodology
KEY
Architecting single-page front-end apps
KEY
Message in a Bottle
PPT
CSS Methodology
PPT
Javascript Design Patterns
PDF
Performance front end language
PDF
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
Haml
Rolling Your Own CSS Methodology
Architecting single-page front-end apps
Message in a Bottle
CSS Methodology
Javascript Design Patterns
Performance front end language
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
Ad

Similar to Introduction to HAML (20)

PPTX
Learning html. (Part- 1)
PPTX
HTML Bootcamp
PPTX
215077679 introduction to HTML
PPTX
2. HTML Basic unit2 fundamentals of computer
PPTX
week 3 slides.pptx
PPTX
INTRODUCTION CODING - THE HTML AND CSS.pptx
PPTX
Untitled presentation (8) (1)
PPTX
Html Workshop
PPTX
Html starting
PDF
Web Development 1 (HTML & CSS)
PDF
Basic Html Notes
PPTX
Chapter 2 - Introduction to HTML (Basic Structures and Syntax).pptx
PPT
Web forms and html (lect 1)
PPT
Html presentation
PDF
web development.pdf
PPTX
Computer fundamentals-internet p2
PPTX
Basic HTML
PDF
Html xhtml tag-sheet
Learning html. (Part- 1)
HTML Bootcamp
215077679 introduction to HTML
2. HTML Basic unit2 fundamentals of computer
week 3 slides.pptx
INTRODUCTION CODING - THE HTML AND CSS.pptx
Untitled presentation (8) (1)
Html Workshop
Html starting
Web Development 1 (HTML & CSS)
Basic Html Notes
Chapter 2 - Introduction to HTML (Basic Structures and Syntax).pptx
Web forms and html (lect 1)
Html presentation
web development.pdf
Computer fundamentals-internet p2
Basic HTML
Html xhtml tag-sheet

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I

Introduction to HAML

  • 1. HAML Web Templating for Human Beings
  • 2. Introduction HAML is Markup language Its purpose is to describe HTML in a clean, simple way
  • 3. Introduction Lets face it, HTML is pretty annoying
  • 4. Introduction HAML aims to solve problems with ordinary HTML coding
  • 5. Introduction • Markup should be beautiful • Markup should be DRY • Too much repetition in HTML and templating engines like ERB • Markup should be well-indented • Markup structure should be clear
  • 6. The problems with HTML Programmers don’t speak HTML The whole concept of markup is foreign as there’s no logic involved.
  • 7. The problems with HTML The mix of markup and logic seems a bit odd, if not ugly. Markup should be beautiful, not just code
  • 8. The problems with HTML There’s just too much repetition in HTML. All those open and close tags are redundant
  • 9. The problems with HTML Keeping track of open and close HTML and template tags is tedious.
  • 10. HAML to the rescue <ul id=”navigation”> <li class=”menu_item”> <a href=”/home” title=”Home”>Home</a> </li> </ul> %ul#navigation %li.menu_item %a({:href => “/home”, :title => “Home” }) Home
  • 11. HAML Basics !!! 5 %html %head %title Haml Test %body #header %h1 Welcome to my blog %nav#navigation #content = yield
  • 12. HAML Basics • HTML Tags are prefixed with % • ID attribute is prefixed with # • Class attribute is prefixed with . • Default HTML tag is <div>
  • 13. HAML Basics • Additional attributes are passed as • space-separated attr./value pairs • %a(title=@title href=href) Stuff • attr./value hash • %a{:title => @title, :href => href} Stuff
  • 14. HAML Formatting Remove whitespace using < and > characters %img %img> %img Compiles into <img /><img /><img />
  • 16. HAML Formatting Escape HTML entities using the & sign &= “I like Cheese & Crackers” Compiles into I like Cheese &amp; Crackers
  • 17. HAML Formatting Disable HTML unescaping using the ! sign != “<strong>Foo</strong>” Compiles into <strong>Foo</strong>
  • 18. Dynamic HAML HAML supports dynamic content as well as static content. (let the real fun begin)
  • 19. Dynamic HAML • We use the “=” sign to evaluate dynamic code and assign the value to the desired tag • We use the “-” sign to run code without appending a value to any tag • We use Ruby interpolation to mix static and dynamic strings
  • 20. Dynamic HAML %h2= “Posts for #{Time.now}” %ul#posts - @posts.each do |post| %li.post_item %h3= post.title %p= post.post %p=
  • 21. Dynamic HAML HAML doesn’t limit us to just plain old code running and evaluation. Since markup documents may contain a mix of other languages (like Javascript or CSS), we can use Filters to parse those languages into HAML
  • 23. HAML Filters :javascript document.getElementById(‘content’); :css body{ font:normal normal 14px Arial,sans-serif; } :sass li font: family: serif
  • 24. HAML Filters :markdown Textile ======= Hello, *World* :textile I *really* prefer _#{h flavor}_ jam.
  • 25. HAML Filters :zohar module Haml::Filters::Zohar include Haml::Filters::Base def render(text) # run some snazzy logic text end end
  • 26. HAML interoperability • Python - HamlPy & DAML (Django) • PHP - Fammel, pHAML, phpHAML • .NET - NHaml, MonoRail NHaml • Javascript - HAML-js • Perl - Text::Haml • Java - JHaml

Editor's Notes