SlideShare ist ein Scribd-Unternehmen logo
1 von 18
HAML in 5 minutes

     Cameron Hill
markup should be beautiful
HTML:
<div id="article">
  <h2>OxiClean tackles household stains</h2>
  <span class="author">Billy Mays</span>

  <p>It boosts your detergent power</p>
  <a href="oxiclean.com">Read more</a>
</div>




HAML:
#article
  %h2 OxiClean tackles household stains
  %span.author Billy Mays

 %p It boots your detergent power
 %a{:href => "oxiclean.com"} Read more
Four Simple Rules
•   %tag creates a <tag></tag> element
•   HTML attributes as Ruby hashes
•   CSS selector shortcuts & implicit divs
•   Nested elements: Indentation matters
%tag creates a <tag></tag> element

%div Some content         <div>Some content</div>

%h2 Breaking News         <h2>Breaking News</h2>

%br                       <br/>



%widget                   <widget></widget>
HTML attributes as hashes
%a{ :href => “/article/4”, :target=> “_blank” } Read more

<a href=“/article/4” target=“_blank”>Read more</a>




%ul{ :id => "projects", :class => "secondary" }

<ul id=“projects” class=“secondary”></ul>
CSS id and class shortcuts
%h2#title Rails in Action

<h2 id=“title”>Rails in Action</h2>




%span.author Steve Klabnik

<span class="author">Steve Klabnik</span>
Implicit DIV tags
#content This is my content

<div id="content">This is my content</div>




.article This is my content

<div class=”article">This is my content</div>
Nested elements: Indentation matters

HAML:
%ul
  %li Mayonnaise
  %li Mustard
  %li
    %a{ :href => “ketchup.com” } Ketchup



HTML:
<ul>
  <li>Mayonnaise</li>
  <li>Mustard</li>
  <li><a href=“ketchup.com”>Ketchup</a></li>
Evaluating Ruby with HAML
= evaluates a Ruby expression (like <%= %>)
ERB:
<h2><%= @ticket.title %></h2>

HAML:
%h2= @ticket.title




ERB:
<span>Created by <%= @ticket.user.email %></span>

HAML:
%span= “Created by #{@ticket.user.email}”

%span Created by #{@ticket.user.email}
Blocks in HAML
        -or-
Death to <% end %>
- Indicates a conditional or block
ERB:
<% if @ticket.comments.exists? %>
  <%= render @ticket.comments.select(&:persisted?) %>
<% else %>
  <p>There are no comments for this ticket.</p>
<% end %>




HAML:
- if @ticket.comments.exists?
  = render @ticket.comments.select(&:persisted?)
- else
  %p There are no comments for this ticket.
ERB:
<% @ticket.assets.each do |asset| %>
  <p>
     <%= link_to File.basename(asset.file_name), asset.url %>
  </p>
<% end %>




HAML:
- @ticket.assets.each do |asset|
  %p= link_to File.basename(asset.file_name), asset.url
I’m sold!
How do I use it in Rails?
gem “haml”
http://haml.info
Thanks!

    cameronhill.net
github.com/cameronbot
     @cameronbot

Weitere ähnliche Inhalte

Was ist angesagt?

Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011rivierarb
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
Copycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBCopycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBbostonrb
 
Intro to java script
Intro to java scriptIntro to java script
Intro to java scriptlondiem
 
Telling Stories With RSpec
Telling Stories With RSpecTelling Stories With RSpec
Telling Stories With RSpecrahoulb
 
You're Doing It Wrong
You're Doing It WrongYou're Doing It Wrong
You're Doing It Wrongbostonrb
 
Entry-level PHP for WordPress
Entry-level PHP for WordPressEntry-level PHP for WordPress
Entry-level PHP for WordPresssprclldr
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS ApplicationMd. Ziaul Haq
 
URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5jakemallory
 
Experience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsExperience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsCédric Hüsler
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le WagonAlex Benoit
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?brynary
 

Was ist angesagt? (19)

Why Django for Web Development
Why Django for Web DevelopmentWhy Django for Web Development
Why Django for Web Development
 
programming
programmingprogramming
programming
 
Shell
ShellShell
Shell
 
Function calling in js
Function calling in jsFunction calling in js
Function calling in js
 
7. copy2 in Symfony 4
7. copy2 in Symfony 47. copy2 in Symfony 4
7. copy2 in Symfony 4
 
Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
Built in filters
Built in filtersBuilt in filters
Built in filters
 
Copycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBCopycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRB
 
Intro to java script
Intro to java scriptIntro to java script
Intro to java script
 
HTML 5 Basics Part One
HTML 5 Basics Part OneHTML 5 Basics Part One
HTML 5 Basics Part One
 
Telling Stories With RSpec
Telling Stories With RSpecTelling Stories With RSpec
Telling Stories With RSpec
 
You're Doing It Wrong
You're Doing It WrongYou're Doing It Wrong
You're Doing It Wrong
 
Entry-level PHP for WordPress
Entry-level PHP for WordPressEntry-level PHP for WordPress
Entry-level PHP for WordPress
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS Application
 
URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5
 
Experience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsExperience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - Highlights
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 

Andere mochten auch

Virus y vacunas informã¡ticas laura
Virus y vacunas informã¡ticas lauraVirus y vacunas informã¡ticas laura
Virus y vacunas informã¡ticas lauraLaura Mejia
 
G te c sesion4b-complejidad y tpa
G te c sesion4b-complejidad y tpaG te c sesion4b-complejidad y tpa
G te c sesion4b-complejidad y tpaVictoria López
 
Trastornos del aprendizaje
Trastornos del aprendizajeTrastornos del aprendizaje
Trastornos del aprendizajeMartin Hinojosa
 
Miniquest.Informática, 2013.
Miniquest.Informática, 2013.Miniquest.Informática, 2013.
Miniquest.Informática, 2013.Silvia0202
 
Submissão à autoridad1
Submissão à autoridad1Submissão à autoridad1
Submissão à autoridad1mgno42
 
Financial densities in emerging markets
Financial densities in emerging marketsFinancial densities in emerging markets
Financial densities in emerging marketsimauleecon
 
The Four Stage Link Building Cycle: Page One Power Webinar
The Four Stage Link Building Cycle: Page One Power WebinarThe Four Stage Link Building Cycle: Page One Power Webinar
The Four Stage Link Building Cycle: Page One Power WebinarSearch Engine Journal
 
Los cinco sentidos
Los cinco sentidosLos cinco sentidos
Los cinco sentidosminesgg
 
proyecto de integración de las tics en la educación inicial.
proyecto de integración de las tics en la educación inicial.proyecto de integración de las tics en la educación inicial.
proyecto de integración de las tics en la educación inicial.marleny Brito de lo Santo
 
Mateo Valero - Big data: de la investigación científica a la gestión empresarial
Mateo Valero - Big data: de la investigación científica a la gestión empresarialMateo Valero - Big data: de la investigación científica a la gestión empresarial
Mateo Valero - Big data: de la investigación científica a la gestión empresarialFundación Ramón Areces
 
Plan Nacional de Riego en Argentina
Plan Nacional de Riego en ArgentinaPlan Nacional de Riego en Argentina
Plan Nacional de Riego en ArgentinaFAO
 

Andere mochten auch (20)

Ensenyament 2012
Ensenyament 2012Ensenyament 2012
Ensenyament 2012
 
Virus y vacunas informã¡ticas laura
Virus y vacunas informã¡ticas lauraVirus y vacunas informã¡ticas laura
Virus y vacunas informã¡ticas laura
 
Jahir Hussain
Jahir HussainJahir Hussain
Jahir Hussain
 
Workcube CRM Fonksiyon Föyü
Workcube CRM Fonksiyon FöyüWorkcube CRM Fonksiyon Föyü
Workcube CRM Fonksiyon Föyü
 
Rsvp
RsvpRsvp
Rsvp
 
G te c sesion4b-complejidad y tpa
G te c sesion4b-complejidad y tpaG te c sesion4b-complejidad y tpa
G te c sesion4b-complejidad y tpa
 
Trastornos del aprendizaje
Trastornos del aprendizajeTrastornos del aprendizaje
Trastornos del aprendizaje
 
Miniquest.Informática, 2013.
Miniquest.Informática, 2013.Miniquest.Informática, 2013.
Miniquest.Informática, 2013.
 
Submissão à autoridad1
Submissão à autoridad1Submissão à autoridad1
Submissão à autoridad1
 
Financial densities in emerging markets
Financial densities in emerging marketsFinancial densities in emerging markets
Financial densities in emerging markets
 
Cross-promotion of iPad apps
Cross-promotion of iPad appsCross-promotion of iPad apps
Cross-promotion of iPad apps
 
Flormar 7-8
Flormar 7-8Flormar 7-8
Flormar 7-8
 
The Four Stage Link Building Cycle: Page One Power Webinar
The Four Stage Link Building Cycle: Page One Power WebinarThe Four Stage Link Building Cycle: Page One Power Webinar
The Four Stage Link Building Cycle: Page One Power Webinar
 
Los cinco sentidos
Los cinco sentidosLos cinco sentidos
Los cinco sentidos
 
proyecto de integración de las tics en la educación inicial.
proyecto de integración de las tics en la educación inicial.proyecto de integración de las tics en la educación inicial.
proyecto de integración de las tics en la educación inicial.
 
Agenda Escolar de Diabetes
Agenda Escolar de DiabetesAgenda Escolar de Diabetes
Agenda Escolar de Diabetes
 
Mateo Valero - Big data: de la investigación científica a la gestión empresarial
Mateo Valero - Big data: de la investigación científica a la gestión empresarialMateo Valero - Big data: de la investigación científica a la gestión empresarial
Mateo Valero - Big data: de la investigación científica a la gestión empresarial
 
El Agua
El AguaEl Agua
El Agua
 
8683476 assimil-njemacki-bez-muke-1974
8683476 assimil-njemacki-bez-muke-19748683476 assimil-njemacki-bez-muke-1974
8683476 assimil-njemacki-bez-muke-1974
 
Plan Nacional de Riego en Argentina
Plan Nacional de Riego en ArgentinaPlan Nacional de Riego en Argentina
Plan Nacional de Riego en Argentina
 

Ähnlich wie Haml in 5 minutes

HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!Ana Cidre
 
Advanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & EfficiencyAdvanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & EfficiencyDenise Jacobs
 
HTML CSS and Web Development
HTML CSS and Web DevelopmentHTML CSS and Web Development
HTML CSS and Web DevelopmentRahul Mishra
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developersHernan Mammana
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Terry Ryan
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS TroubleshootingDenise Jacobs
 
SharePointfest Denver - A jQuery Primer for SharePoint
SharePointfest Denver -  A jQuery Primer for SharePointSharePointfest Denver -  A jQuery Primer for SharePoint
SharePointfest Denver - A jQuery Primer for SharePointMarc D Anderson
 
Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)Jazkarta, Inc.
 
HTML Coding #01 : Don't Fear the Code
HTML Coding #01 : Don't Fear the CodeHTML Coding #01 : Don't Fear the Code
HTML Coding #01 : Don't Fear the CodeMichael Sturgeon
 
TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單偉格 高
 
What is HTML - An Introduction to HTML (Hypertext Markup Language)
What is HTML - An Introduction to HTML (Hypertext Markup Language)What is HTML - An Introduction to HTML (Hypertext Markup Language)
What is HTML - An Introduction to HTML (Hypertext Markup Language)Ahsan Rahim
 
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8spierre
 
3 1-html-fundamentals-110302100520-phpapp02
3 1-html-fundamentals-110302100520-phpapp023 1-html-fundamentals-110302100520-phpapp02
3 1-html-fundamentals-110302100520-phpapp02Aditya Varma
 
Intro to HTML and CSS
Intro to HTML and CSSIntro to HTML and CSS
Intro to HTML and CSSlexinamer
 

Ähnlich wie Haml in 5 minutes (20)

HTML5 & CSS3 Flag
HTML5 & CSS3 FlagHTML5 & CSS3 Flag
HTML5 & CSS3 Flag
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
Advanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & EfficiencyAdvanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & Efficiency
 
HTML CSS and Web Development
HTML CSS and Web DevelopmentHTML CSS and Web Development
HTML CSS and Web Development
 
Html intro
Html introHtml intro
Html intro
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developers
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS Troubleshooting
 
SharePointfest Denver - A jQuery Primer for SharePoint
SharePointfest Denver -  A jQuery Primer for SharePointSharePointfest Denver -  A jQuery Primer for SharePoint
SharePointfest Denver - A jQuery Primer for SharePoint
 
Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)
 
HTML Coding #01 : Don't Fear the Code
HTML Coding #01 : Don't Fear the CodeHTML Coding #01 : Don't Fear the Code
HTML Coding #01 : Don't Fear the Code
 
TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單
 
What is HTML - An Introduction to HTML (Hypertext Markup Language)
What is HTML - An Introduction to HTML (Hypertext Markup Language)What is HTML - An Introduction to HTML (Hypertext Markup Language)
What is HTML - An Introduction to HTML (Hypertext Markup Language)
 
Seo Cheat Sheet
Seo Cheat SheetSeo Cheat Sheet
Seo Cheat Sheet
 
Seo cheat-sheet
Seo cheat-sheetSeo cheat-sheet
Seo cheat-sheet
 
Html5
Html5Html5
Html5
 
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
Pamela - Brining back the pleasure of hand-written HTML - Montréal Python 8
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
3 1-html-fundamentals-110302100520-phpapp02
3 1-html-fundamentals-110302100520-phpapp023 1-html-fundamentals-110302100520-phpapp02
3 1-html-fundamentals-110302100520-phpapp02
 
Intro to HTML and CSS
Intro to HTML and CSSIntro to HTML and CSS
Intro to HTML and CSS
 

Kürzlich hochgeladen

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 

Kürzlich hochgeladen (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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.
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
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
 

Haml in 5 minutes

  • 1. HAML in 5 minutes Cameron Hill
  • 2. markup should be beautiful
  • 3. HTML: <div id="article"> <h2>OxiClean tackles household stains</h2> <span class="author">Billy Mays</span> <p>It boosts your detergent power</p> <a href="oxiclean.com">Read more</a> </div> HAML: #article %h2 OxiClean tackles household stains %span.author Billy Mays %p It boots your detergent power %a{:href => "oxiclean.com"} Read more
  • 4. Four Simple Rules • %tag creates a <tag></tag> element • HTML attributes as Ruby hashes • CSS selector shortcuts & implicit divs • Nested elements: Indentation matters
  • 5. %tag creates a <tag></tag> element %div Some content <div>Some content</div> %h2 Breaking News <h2>Breaking News</h2> %br <br/> %widget <widget></widget>
  • 6. HTML attributes as hashes %a{ :href => “/article/4”, :target=> “_blank” } Read more <a href=“/article/4” target=“_blank”>Read more</a> %ul{ :id => "projects", :class => "secondary" } <ul id=“projects” class=“secondary”></ul>
  • 7. CSS id and class shortcuts %h2#title Rails in Action <h2 id=“title”>Rails in Action</h2> %span.author Steve Klabnik <span class="author">Steve Klabnik</span>
  • 8. Implicit DIV tags #content This is my content <div id="content">This is my content</div> .article This is my content <div class=”article">This is my content</div>
  • 9. Nested elements: Indentation matters HAML: %ul %li Mayonnaise %li Mustard %li %a{ :href => “ketchup.com” } Ketchup HTML: <ul> <li>Mayonnaise</li> <li>Mustard</li> <li><a href=“ketchup.com”>Ketchup</a></li>
  • 11. = evaluates a Ruby expression (like <%= %>) ERB: <h2><%= @ticket.title %></h2> HAML: %h2= @ticket.title ERB: <span>Created by <%= @ticket.user.email %></span> HAML: %span= “Created by #{@ticket.user.email}” %span Created by #{@ticket.user.email}
  • 12. Blocks in HAML -or- Death to <% end %>
  • 13. - Indicates a conditional or block ERB: <% if @ticket.comments.exists? %> <%= render @ticket.comments.select(&:persisted?) %> <% else %> <p>There are no comments for this ticket.</p> <% end %> HAML: - if @ticket.comments.exists? = render @ticket.comments.select(&:persisted?) - else %p There are no comments for this ticket.
  • 14. ERB: <% @ticket.assets.each do |asset| %> <p> <%= link_to File.basename(asset.file_name), asset.url %> </p> <% end %> HAML: - @ticket.assets.each do |asset| %p= link_to File.basename(asset.file_name), asset.url
  • 15. I’m sold! How do I use it in Rails?
  • 18. Thanks! cameronhill.net github.com/cameronbot @cameronbot

Hinweis der Redaktion

  1. IntroductionMy talk today is HAML in 5 minutesHow many of you know what haml is?Haml is a templating markup language similar to Ruby ERB that you can use to code the views in your Rails Apps.Unlike ERB which basically just evaluates Ruby in between whatever text is around it – whether it’s HTML or CSS or JSON or whatever, HAML is abstracted out a little more actually replaces how you even write your html tags.Just like you have SASS or LESS for CSS, HAML has a syntax that ultimately compiles into HTML. It’s designed to make your life as a Rails developer easier.
  2. The makers of HAML decided that markup should be beautiful.They wanted something that was concise, elegant, and clear. What they came up with was something that borrowed a lot of style from Ruby code.For those of you that don’t like the context switch between Ruby code in your models and controllers and HTML and ERB in your views, you might really welcome HAMLSo what does HAML look like?
  3. Here is an HTML snippet at the top and how this would be written in HAML.Designed to be very easy to read. Almost intuitive to understand.Just looking at it you can probably pick out some patterns that make HAML work.#article something, looks like an h2, span, maybe that’s a css class name, paragraph, anchor tag with an href attribute
  4. No closing tags.Whatever is to the right of the %tagname becomes the content of that tagCan even create custom tags if you were marking up an XML document or were using a custom namespace
  5. Just like Ruby, pass in the attributes for your HTML tags as hashes
  6. Since css id and class are used so frequently there’s even a shortcut for them.You can even combine them and apply both at the same time or put a hash on the end and pass in even more attributes.
  7. Also since DIV tags are used so frequently in HTML, they are the default tag.Rather than writing %div#content, simply write #content
  8. Another really important aspect of HAML is that indentation matters!This is how you get around having to write closing tags.To add a child element, indent two spaces, just like Ruby. Here’s an example of how that looks --- notice there’s an anchor tag on the last list-item so it is indented another line
  9. Okay so this looks great, but those are the basics, lets get to some more complicated stuff....Evaluating Ruby with HAML
  10. For the next few slides I’m going to compare ERB to HAML so you can see the similarities and how you might go about converting your views to HAML.TIP for converting to HAML: keep hitting the delete key.So here is how we can evaluate ruby in HAML – use the equals sign after a tag to tell HAML to evaluate what is to the right.Here are some examples from our Ticketee project.In the second example, you can do string interpolation without the equals sign.
  11. And to get even more complicated, lets go over how to do blocks in HAML – and how to get rid of all those ERB end tags cluttering your code.
  12. Another example from Ticketee.Use a hypen at the beginning of the line to indicate it’s a block.Notice the equals sign all by itself for the render statement. You can do that without preceding it with a tag name.And of course the best thing is no &lt;% end %&gt; statements. I’m sure all of you have questioned why anyone would ever think a 9 character closing tag with no less than 4 special characters that require hitting the shift key was a good idea. Well suffer no more.
  13. Here’s an example with a loop.Simple!
  14. Well it wouldn’t be Rails worthy if it wasn’t extremely easy to add to your project.
  15. Add gem haml to your gemfile.And boom, you’re up and running.Anything in your views that have a .html.haml file extension will be compiled into HTML.
  16. That’s HAML.For more info, check out haml.info.