SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
How’s Haml?
Patrick Reagan
What is Haml?

• Templating language for creating XHTML
• Alternative to ERB in Rails
• Principle: “Markup should be beautiful”
What is Beauty?
What is Beauty?
Installation
$ sudo gem install --no-ri haml
Successfully installed haml-1.8.0
1 gem installed
Installing RDoc documentation for haml-1.8.0...




$ haml --rails ./my_rails_app
Haml plugin added to ./my_rails_app
Using Haml
 Rename views and layouts

app/views/posts: index.html.erb => index.html.haml
app/views/layouts: application.html.erb => application.haml




  Start deleting!
ERB / RHTML
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <title>Yet Another Rails Blog</title>
  </head>
  <body>
    <div id='container'>
      <div id='navigation'>
        <%= link_to 'Home', root_path %>
      </div>
      <div id='content'>
        <% @posts.each do |post| -%>
         <div class='post'>
           <h3><%= h post.title %></h3>
           <strong>by: <%= post.author %></strong>
           <p><%= post.body %></p>
         </div>
        <% end %>
      </div>
    </div>
  </body>
</html>
ERB / RHTML
<?xml version='1.0' encoding='utf-8' ?>
!!! XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
!!! Strict
%html{html_attrs}      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <title>Yet Another Rails Blog</title>
  </head>
  <body>
    <div id='container'>
      <div id='navigation'>
        <%= link_to 'Home', root_path %>
      </div>
      <div id='content'>
        <% @posts.each do |post| -%>
         <div class='post'>
           <h3><%= h post.title %></h3>
           <strong>by: <%= post.author %></strong>
           <p><%= post.body %></p>
         </div>
        <% end %>
      </div>
    </div>
  </body>
</html>
ERB / RHTML
<?xml version='1.0' encoding='utf-8' ?>
!!! XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
!!! Strict
%html{html_attrs}      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
  %head
  <head>
    %title Yet Another Rails Blog
    <title>Yet Another Rails Blog</title>
  %body
  </head>
  <body>
    <div id='container'>
      <div id='navigation'>
        <%= link_to 'Home', root_path %>
      </div>
      <div id='content'>
        <% @posts.each do |post| -%>
         <div class='post'>
           <h3><%= h post.title %></h3>
           <strong>by: <%= post.author %></strong>
           <p><%= post.body %></p>
         </div>
        <% end %>
      </div>
    </div>
  </body>
</html>
ERB / RHTML
<?xml version='1.0' encoding='utf-8' ?>
!!! XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
!!! Strict
%html{html_attrs}      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
  %head
  <head>
    %title Yet Another Rails Blog
    <title>Yet Another Rails Blog</title>
  %body
  </head>
  <body>
    #container
    <div id='container'>
      #navigation
      <div id='navigation'>
         = link_to('Home', root_path)
        <%= link_to 'Home', root_path %>
      </div>
      <div id='content'>
        <% @posts.each do |post| -%>
         <div class='post'>
           <h3><%= h post.title %></h3>
           <strong>by: <%= post.author %></strong>
           <p><%= post.body %></p>
         </div>
        <% end %>
      </div>
    </div>
  </body>
</html>
Hamlified!
<?xml version='1.0' encoding='utf-8' ?>
!!! XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
!!! Strict
%html{html_attrs}      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
  %head
  <head>
    %title Yet Another Rails Blog
    <title>Yet Another Rails Blog</title>
  %body
  </head>
  <body>
    #container
    <div id='container'>
      #navigation
      <div id='navigation'>
         = link_to('Home', root_path)
        <%= link_to 'Home', root_path %>
      </div>
      #content
      <div id='content'>
        <%@posts.each do |post| -%>
         - @posts.each do |post|
           .post
         <div class='post'>
           <h3><%=h(post.title) %></h3>
             %h3= h post.title
           <strong>by:"by: post.author %></strong>
             %strong= <%= #{h(post.author)}"
           <p><%=post.body %></p>
             %p= post.body
         </div>
        <% end %>
      </div>
    </div>
  </body>
</html>
Haml Deconstructed
    !!! XML
    !!! Strict

    %html{html_attrs}
      %head
        %title Yet Another Rails Blog
      %body
        #container
          #navigation
            = link_to('Home', root_path)
          #content
            - @posts.each do |post|
              .post
                %h3= h(post.title)
                %strong= "by: #{h(post.author)}"
                %p= post.body
Haml Deconstructed
XHTML document type
                      !!! XML
                      !!! Strict

                      %html{html_attrs}
                        %head
                          %title Yet Another Rails Blog
                        %body
                          #container
                            #navigation
                              = link_to('Home', root_path)
                            #content
                              - @posts.each do |post|
                                .post
                                  %h3= h(post.title)
                                  %strong= "by: #{h(post.author)}"
                                  %p= post.body
Haml Deconstructed
XHTML document type
                      !!! XML
  XHTML tag with      !!! Strict

   static content     %html{html_attrs}
                        %head
                          %title Yet Another Rails Blog
                        %body
                          #container
                            #navigation
                              = link_to('Home', root_path)
                            #content
                              - @posts.each do |post|
                                .post
                                  %h3= h(post.title)
                                  %strong= "by: #{h(post.author)}"
                                  %p= post.body
Haml Deconstructed
XHTML document type                    Haml helper method
                      !!! XML
  XHTML tag with      !!! Strict

   static content     %html{html_attrs}
                        %head
                          %title Yet Another Rails Blog
                        %body
                          #container
                            #navigation
                              = link_to('Home', root_path)
                            #content
                              - @posts.each do |post|
                                .post
                                  %h3= h(post.title)
                                  %strong= "by: #{h(post.author)}"
                                  %p= post.body
Haml Deconstructed
XHTML document type                    Haml helper method
                      !!! XML
  XHTML tag with      !!! Strict

   static content     %html{html_attrs}
                        %head
                          %title Yet Another Rails Blog
   DIV tag with ID      %body
                          #container
                            #navigation
                              = link_to('Home', root_path)
                            #content
                              - @posts.each do |post|
                                .post
                                  %h3= h(post.title)
                                  %strong= "by: #{h(post.author)}"
                                  %p= post.body
Haml Deconstructed
XHTML document type                    Haml helper method
                      !!! XML
  XHTML tag with      !!! Strict

   static content     %html{html_attrs}
                        %head
                          %title Yet Another Rails Blog
   DIV tag with ID      %body
                          #container
                            #navigation
                              = link_to('Home', root_path)
 Execute Ruby code          #content
                              - @posts.each do |post|
                                .post
                                  %h3= h(post.title)
                                  %strong= "by: #{h(post.author)}"
                                  %p= post.body
Haml Deconstructed
XHTML document type                    Haml helper method
                      !!! XML
  XHTML tag with      !!! Strict

   static content     %html{html_attrs}
                        %head
                          %title Yet Another Rails Blog
   DIV tag with ID      %body
                          #container
                            #navigation
                              = link_to('Home', root_path)
 Execute Ruby code          #content
                              - @posts.each do |post|
                                .post
                                  %h3= h(post.title)
  XHTML tag with                  %strong= "by: #{h(post.author)}"
                                  %p= post.body
  dynamic content
XHTML Output
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <title>Yet Another Rails Blog</title>
  </head>
  <body>
    <div id='container'>
      <div id='navigation'>
         <a href="/">Home</a>
      </div>
      <div id='content'>
         <div class='post'>
           <h3>January Refresh Recap</h3>
           <strong>by: Patrick</strong>
           <p>It was awesome!</p>
         </div>

        ...

      </div>
    </div>
  </body>
</html>
Off the Rails?

$ irb
>> require 'rubygems'
=> true
>> require 'haml'
=> true
>> Haml::Engine.new('%p Hello, World').render
=> "<p>Hello, World</p>n"
Why Use It?

• Creates well-formatted markup
• Automatic closing of tags
• Less “noise”
Why Not?

• Buildout must happen inside Rails
• XHTML is a widespread standard
• Performance
Resources
Other templating systems
 •   Erubis
 •   Markaby
 •   pHAML

Tutorial & Documentation
 •   http://haml.hamptoncatlin.com/tutorial/
 •   http://haml.hamptoncatlin.com/docs/

TextMate Bundle (via SVN)
 •   http://macromates.com/svn/Bundles/trunk

Mais conteúdo relacionado

Mais procurados

Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelComprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelvodQA
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme KickstartPeter
 
11 page-directive
11 page-directive11 page-directive
11 page-directivesnopteck
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web ServicesGreg Hines
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing scienceCharlie Love
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2RORLAB
 

Mais procurados (12)

Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelComprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme Kickstart
 
11 page-directive
11 page-directive11 page-directive
11 page-directive
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing science
 
HTML 5 & CSS 3
HTML 5 & CSS 3HTML 5 & CSS 3
HTML 5 & CSS 3
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
HTML5 Essentials
HTML5 EssentialsHTML5 Essentials
HTML5 Essentials
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2
 

Destaque

Coding With Confidence: Adding TDD to Your Toolset
Coding With Confidence: Adding TDD to Your ToolsetCoding With Confidence: Adding TDD to Your Toolset
Coding With Confidence: Adding TDD to Your ToolsetPatrick Reagan
 
Mockfight! FlexMock vs. Mocha
Mockfight! FlexMock vs. MochaMockfight! FlexMock vs. Mocha
Mockfight! FlexMock vs. MochaPatrick Reagan
 
Changing Your Mindset: Getting Started with Test-Driven Development
Changing Your Mindset: Getting Started with Test-Driven DevelopmentChanging Your Mindset: Getting Started with Test-Driven Development
Changing Your Mindset: Getting Started with Test-Driven DevelopmentPatrick Reagan
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingPatrick Reagan
 
Better Functional Design through TDD
Better Functional Design through TDDBetter Functional Design through TDD
Better Functional Design through TDDPhil Calçado
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

Destaque (6)

Coding With Confidence: Adding TDD to Your Toolset
Coding With Confidence: Adding TDD to Your ToolsetCoding With Confidence: Adding TDD to Your Toolset
Coding With Confidence: Adding TDD to Your Toolset
 
Mockfight! FlexMock vs. Mocha
Mockfight! FlexMock vs. MochaMockfight! FlexMock vs. Mocha
Mockfight! FlexMock vs. Mocha
 
Changing Your Mindset: Getting Started with Test-Driven Development
Changing Your Mindset: Getting Started with Test-Driven DevelopmentChanging Your Mindset: Getting Started with Test-Driven Development
Changing Your Mindset: Getting Started with Test-Driven Development
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
 
Better Functional Design through TDD
Better Functional Design through TDDBetter Functional Design through TDD
Better Functional Design through TDD
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Semelhante a Hows Haml?

How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic templatevathur
 
Zen codingcheatsheet
Zen codingcheatsheetZen codingcheatsheet
Zen codingcheatsheetgoldenveizer
 
Statische Websites in Rails 3.1
Statische Websites in Rails 3.1Statische Websites in Rails 3.1
Statische Websites in Rails 3.1RobinBrouwer
 
Simple Markdown with Ecto and Protocols
Simple Markdown with Ecto and ProtocolsSimple Markdown with Ecto and Protocols
Simple Markdown with Ecto and ProtocolsDavid Lucia
 
Django Templates
Django TemplatesDjango Templates
Django TemplatesWilly Liu
 
Noticias Ducez
Noticias DucezNoticias Ducez
Noticias Ducezmatheus
 
Introduction to xhtml
Introduction to xhtmlIntroduction to xhtml
Introduction to xhtmlDhairya Joshi
 
Getting to know perch — and perch runway!
Getting to know perch — and perch runway!Getting to know perch — and perch runway!
Getting to know perch — and perch runway!Abigail Larsen
 
AttributesL3.pptx
AttributesL3.pptxAttributesL3.pptx
AttributesL3.pptxKrishRaj48
 
WDIM268 Week 6 (Summer 2010)
WDIM268 Week 6 (Summer 2010)WDIM268 Week 6 (Summer 2010)
WDIM268 Week 6 (Summer 2010)Tyler Sticka
 
Introdução a CSS
Introdução a CSS Introdução a CSS
Introdução a CSS Tiago Santos
 
Html goodies
Html goodiesHtml goodies
Html goodiesAli Hasan
 

Semelhante a Hows Haml? (20)

Haml
HamlHaml
Haml
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
 
Zen codingcheatsheet
Zen codingcheatsheetZen codingcheatsheet
Zen codingcheatsheet
 
Statische Websites in Rails 3.1
Statische Websites in Rails 3.1Statische Websites in Rails 3.1
Statische Websites in Rails 3.1
 
Simple Markdown with Ecto and Protocols
Simple Markdown with Ecto and ProtocolsSimple Markdown with Ecto and Protocols
Simple Markdown with Ecto and Protocols
 
Lecture1and2
Lecture1and2Lecture1and2
Lecture1and2
 
Django Templates
Django TemplatesDjango Templates
Django Templates
 
Html.docx
Html.docxHtml.docx
Html.docx
 
Noticias Ducez
Noticias DucezNoticias Ducez
Noticias Ducez
 
Introduction to xhtml
Introduction to xhtmlIntroduction to xhtml
Introduction to xhtml
 
Frfrfrf
FrfrfrfFrfrfrf
Frfrfrf
 
Html Workshop
Html WorkshopHtml Workshop
Html Workshop
 
Getting to know perch — and perch runway!
Getting to know perch — and perch runway!Getting to know perch — and perch runway!
Getting to know perch — and perch runway!
 
AttributesL3.pptx
AttributesL3.pptxAttributesL3.pptx
AttributesL3.pptx
 
WDIM268 Week 6 (Summer 2010)
WDIM268 Week 6 (Summer 2010)WDIM268 Week 6 (Summer 2010)
WDIM268 Week 6 (Summer 2010)
 
Introdução a CSS
Introdução a CSS Introdução a CSS
Introdução a CSS
 
Html full
Html fullHtml full
Html full
 
Java script and html new
Java script and html newJava script and html new
Java script and html new
 
Java script and html
Java script and htmlJava script and html
Java script and html
 
Html goodies
Html goodiesHtml goodies
Html goodies
 

Último

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Hows Haml?

  • 2. What is Haml? • Templating language for creating XHTML • Alternative to ERB in Rails • Principle: “Markup should be beautiful”
  • 5. Installation $ sudo gem install --no-ri haml Successfully installed haml-1.8.0 1 gem installed Installing RDoc documentation for haml-1.8.0... $ haml --rails ./my_rails_app Haml plugin added to ./my_rails_app
  • 6. Using Haml Rename views and layouts app/views/posts: index.html.erb => index.html.haml app/views/layouts: application.html.erb => application.haml Start deleting!
  • 7. ERB / RHTML <?xml version='1.0' encoding='utf-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Yet Another Rails Blog</title> </head> <body> <div id='container'> <div id='navigation'> <%= link_to 'Home', root_path %> </div> <div id='content'> <% @posts.each do |post| -%> <div class='post'> <h3><%= h post.title %></h3> <strong>by: <%= post.author %></strong> <p><%= post.body %></p> </div> <% end %> </div> </div> </body> </html>
  • 8. ERB / RHTML <?xml version='1.0' encoding='utf-8' ?> !!! XML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" !!! Strict %html{html_attrs} "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Yet Another Rails Blog</title> </head> <body> <div id='container'> <div id='navigation'> <%= link_to 'Home', root_path %> </div> <div id='content'> <% @posts.each do |post| -%> <div class='post'> <h3><%= h post.title %></h3> <strong>by: <%= post.author %></strong> <p><%= post.body %></p> </div> <% end %> </div> </div> </body> </html>
  • 9. ERB / RHTML <?xml version='1.0' encoding='utf-8' ?> !!! XML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" !!! Strict %html{html_attrs} "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> %head <head> %title Yet Another Rails Blog <title>Yet Another Rails Blog</title> %body </head> <body> <div id='container'> <div id='navigation'> <%= link_to 'Home', root_path %> </div> <div id='content'> <% @posts.each do |post| -%> <div class='post'> <h3><%= h post.title %></h3> <strong>by: <%= post.author %></strong> <p><%= post.body %></p> </div> <% end %> </div> </div> </body> </html>
  • 10. ERB / RHTML <?xml version='1.0' encoding='utf-8' ?> !!! XML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" !!! Strict %html{html_attrs} "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> %head <head> %title Yet Another Rails Blog <title>Yet Another Rails Blog</title> %body </head> <body> #container <div id='container'> #navigation <div id='navigation'> = link_to('Home', root_path) <%= link_to 'Home', root_path %> </div> <div id='content'> <% @posts.each do |post| -%> <div class='post'> <h3><%= h post.title %></h3> <strong>by: <%= post.author %></strong> <p><%= post.body %></p> </div> <% end %> </div> </div> </body> </html>
  • 11. Hamlified! <?xml version='1.0' encoding='utf-8' ?> !!! XML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" !!! Strict %html{html_attrs} "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> %head <head> %title Yet Another Rails Blog <title>Yet Another Rails Blog</title> %body </head> <body> #container <div id='container'> #navigation <div id='navigation'> = link_to('Home', root_path) <%= link_to 'Home', root_path %> </div> #content <div id='content'> <%@posts.each do |post| -%> - @posts.each do |post| .post <div class='post'> <h3><%=h(post.title) %></h3> %h3= h post.title <strong>by:"by: post.author %></strong> %strong= <%= #{h(post.author)}" <p><%=post.body %></p> %p= post.body </div> <% end %> </div> </div> </body> </html>
  • 12. Haml Deconstructed !!! XML !!! Strict %html{html_attrs} %head %title Yet Another Rails Blog %body #container #navigation = link_to('Home', root_path) #content - @posts.each do |post| .post %h3= h(post.title) %strong= "by: #{h(post.author)}" %p= post.body
  • 13. Haml Deconstructed XHTML document type !!! XML !!! Strict %html{html_attrs} %head %title Yet Another Rails Blog %body #container #navigation = link_to('Home', root_path) #content - @posts.each do |post| .post %h3= h(post.title) %strong= "by: #{h(post.author)}" %p= post.body
  • 14. Haml Deconstructed XHTML document type !!! XML XHTML tag with !!! Strict static content %html{html_attrs} %head %title Yet Another Rails Blog %body #container #navigation = link_to('Home', root_path) #content - @posts.each do |post| .post %h3= h(post.title) %strong= "by: #{h(post.author)}" %p= post.body
  • 15. Haml Deconstructed XHTML document type Haml helper method !!! XML XHTML tag with !!! Strict static content %html{html_attrs} %head %title Yet Another Rails Blog %body #container #navigation = link_to('Home', root_path) #content - @posts.each do |post| .post %h3= h(post.title) %strong= "by: #{h(post.author)}" %p= post.body
  • 16. Haml Deconstructed XHTML document type Haml helper method !!! XML XHTML tag with !!! Strict static content %html{html_attrs} %head %title Yet Another Rails Blog DIV tag with ID %body #container #navigation = link_to('Home', root_path) #content - @posts.each do |post| .post %h3= h(post.title) %strong= "by: #{h(post.author)}" %p= post.body
  • 17. Haml Deconstructed XHTML document type Haml helper method !!! XML XHTML tag with !!! Strict static content %html{html_attrs} %head %title Yet Another Rails Blog DIV tag with ID %body #container #navigation = link_to('Home', root_path) Execute Ruby code #content - @posts.each do |post| .post %h3= h(post.title) %strong= "by: #{h(post.author)}" %p= post.body
  • 18. Haml Deconstructed XHTML document type Haml helper method !!! XML XHTML tag with !!! Strict static content %html{html_attrs} %head %title Yet Another Rails Blog DIV tag with ID %body #container #navigation = link_to('Home', root_path) Execute Ruby code #content - @posts.each do |post| .post %h3= h(post.title) XHTML tag with %strong= "by: #{h(post.author)}" %p= post.body dynamic content
  • 19. XHTML Output <?xml version='1.0' encoding='utf-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Yet Another Rails Blog</title> </head> <body> <div id='container'> <div id='navigation'> <a href="/">Home</a> </div> <div id='content'> <div class='post'> <h3>January Refresh Recap</h3> <strong>by: Patrick</strong> <p>It was awesome!</p> </div> ... </div> </div> </body> </html>
  • 20. Off the Rails? $ irb >> require 'rubygems' => true >> require 'haml' => true >> Haml::Engine.new('%p Hello, World').render => "<p>Hello, World</p>n"
  • 21. Why Use It? • Creates well-formatted markup • Automatic closing of tags • Less “noise”
  • 22. Why Not? • Buildout must happen inside Rails • XHTML is a widespread standard • Performance
  • 23. Resources Other templating systems • Erubis • Markaby • pHAML Tutorial & Documentation • http://haml.hamptoncatlin.com/tutorial/ • http://haml.hamptoncatlin.com/docs/ TextMate Bundle (via SVN) • http://macromates.com/svn/Bundles/trunk