SlideShare uma empresa Scribd logo
1 de 20
HAML For The Win! An introduction to HAML Oct. 13, 2011 1 Created for Magma Rails 2011 - www.magmarails.com Slides posted at http://tinyurl.com/magma-haml-sass Sample code from this presentation can be found in the following sample app: https://github.com/jonathandean/SASS-and-HAML-FTW
What is HAML? A more concise syntax for coding HTML in your Rails app Uses indentation for nesting markup Reduces code (no closing tags) Fixes the messy markup problem that often clutters views Uses a CSS-like syntax that is easier to read and compare to your style rules Makes coding your View layer faster Note: doesn’t affect render time or client-side performance, simply reduces coding efforts and makes the developer more efficient Easy to learn! Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 2
Using HAML in Rails Use it as a replacement for ERB files If you use Bundler, add this to your Gemfile: gem "haml” Files named filename.html.haml (instead of filename.html.erb) will be interpreted by HAML instead of ERB Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 3
A comparison HTML <body>   <div id=“wrapper”>     <div class=“stuff”>      <a href=“#”>Top</a>     </div>  </div> </body> HAML %body  #wrapper     .stuff       %a{:href => “#”} Top Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 4 7 lines 78 characters 4 lines 36 characters Note: Some examples compile using different formatting, I changed them for the slides for readability
Tag names Use % and then the name of the tag Examples: Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 5 HTML <body></body> <div></div> HAML %body %div
ID’s ID’s are just like they are in CSS #id_name Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 6 HTML <div id=“mine”></div> <p id=“yours”></p> HAML %div#mine %p#yours
Classes Classes are also just like they are in CSS .class_name Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 7 HTML <div class=“mine”></div> <p class=“yours”></p> HAML %div.mine %p.yours One way for multiple classes (more later) HTML <div class=“mine yours”></div> HAML %div.mine.yours
div is the default tag name If you want to leave out the tag name and just put classes and/or ID’s, %div is assumed Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 8 HTML <div id=“mine”></div> HAML %div#mine (or just) #mine
ID’s and Classes together Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 9 You can put ID’s and classes together as well HTML <div class=“yours” id=“mine”> </div> <div class=“yours his”id=“mine”> </div> HAML #mine.yours #mine.yours.his
Nesting Tags are nested by indentation only No closing tags! Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 10 HAML #mine  %p.yours hi! HTML <div id=“mine”> <p class=“yours”>hi!</p> </div>
Text content Text can go at the end of the line if there’s no other content to nest Can also be nested itself (required with other nested content) Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 11 HAML #mine  %p.yours hi! (or) #mine %p.yours    hi! #mine %p.yours    hi!    %span dude HTML <div id=“mine”>   <p class=“yours”>hi!</p> </div> <div id=“mine”>   <p class=“yours”>  hi! <span>dude</span>   </p> </div> #mine   %p.yourshi!     %span dude
Attributes Use a Ruby style hash for attributes Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 12 HTML <a href=“http://hi.com”>hi</a> <input type=“submit”> HAML %a{:href => ”http://hi.com”} hi %input{:type => "submit”} Or a more HTML-like syntax with () HAML %a(href=”http://hi.com”) hi %input(type="submit”) HTML <a href=“http://hi.com”>hi</a> <input type=“submit”>
Boolean Attributes Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 13 Use boolean values for attributes such as “selected” HTML <input selected> <input> HAML %input{:selected => true} (or) %input(selected=true) (or) %input(selected) %input{:selected => false} (or) %input(selected=false)
Using an array for ID’s and Classes For the ID attribute it will separate the values by an _ For the Class attribute it will add them as separate classes Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 14 HTML <p class=“one two”>hi</p> <p id=“one_two”>hi</p> HAML %p{:class => [‘one’,’two’]} hi %p{:id=> [‘one’,’two’]} hi
HTML?? You can also use regular HTML Converting a file over time Copy/paste a tracking code or something complicated and hard to write as HAML Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 15 HTML <div id=“myParagraph”>   <p>Hello there!</p> </div> HAML #myParagraph   <p>Hello there!</p>
Adding Ruby code Use – and = for Ruby code = for when you want to output the result – for when the code has no output Use of this should be rare, as this type of Ruby code shouldn’t often be in the view layer Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 16 HTML <p>hi hi hi hi hi</p> <p>hi</p> <p>hi</p> <p>hi</p> <p>hi</p> <p>hi</p> HAML %p= “hi “*5 ,[object Object],%p= “hi” No end required
Ruby Interpolation Use #{} to interpolate Ruby code Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 17 HTML <p>Hi Jon</p> HAML - awesome_guy = “Jon” %p Hi #{awesome_guy} (same as) ,[object Object],%p= “Hi #{awesome_guy}”
Filters Filters start with a : and let you put in indented content to be interpreted in a special way :javascriptfilter wraps some JavaScript in <script> and CDATA tags for inline JavaScript Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 18 HTML <script> //<![CDATA[ alert(‘Hello there!’); //]]> </script> HAML :javascript  alert(‘Hello there!’);
Filters :cssfilter wraps some CSS in <style> and CDATA tags for inline CSS Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 19 HTML <style> /*<![CDATA[*/ .mine{     color: red;   } /*]]>*/ </style> HAML :css  .mine{    color: red;  }
Other filters :plain – does not parse the content :escaped – same as plain but HTML-escapes the text :ruby – pass the content to the normal Ruby interpreter :sass – parse the content with SASS to produce CSS output and more! (see the docs) You can also make custom filters if you have special needs Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 20

Mais conteúdo relacionado

Mais procurados

Joomla security nuggets
Joomla security nuggetsJoomla security nuggets
Joomla security nuggets
guestbd1cdca
 
LESS is More
LESS is MoreLESS is More
LESS is More
jsmith92
 

Mais procurados (19)

The Skinny on Slim
The Skinny on SlimThe Skinny on Slim
The Skinny on Slim
 
05 RD PoSD Tutorial_xhtml_to_html5_2016
05 RD PoSD Tutorial_xhtml_to_html5_201605 RD PoSD Tutorial_xhtml_to_html5_2016
05 RD PoSD Tutorial_xhtml_to_html5_2016
 
-Haml Presentation
-Haml Presentation-Haml Presentation
-Haml Presentation
 
Html in a box
Html in a boxHtml in a box
Html in a box
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners HTML all tags .........its to much helpful for beginners
HTML all tags .........its to much helpful for beginners
 
HTML Introduction
HTML IntroductionHTML Introduction
HTML Introduction
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
HTML 5 Simple Tutorial Part 3
HTML 5 Simple Tutorial Part 3HTML 5 Simple Tutorial Part 3
HTML 5 Simple Tutorial Part 3
 
9. lower in Symfony 4
9. lower in Symfony 49. lower in Symfony 4
9. lower in Symfony 4
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Joomla security nuggets
Joomla security nuggetsJoomla security nuggets
Joomla security nuggets
 
Php 3 1
Php 3 1Php 3 1
Php 3 1
 
Haml & sass
Haml & sassHaml & sass
Haml & sass
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
 
LESS is More
LESS is MoreLESS is More
LESS is More
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
 
Html 101
Html 101Html 101
Html 101
 

Semelhante a Introduction to HAML

Semelhante a Introduction to HAML (20)

Xhtml Css Presentation
Xhtml Css PresentationXhtml Css Presentation
Xhtml Css Presentation
 
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
 
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
 
Diva
DivaDiva
Diva
 
Html1
Html1Html1
Html1
 
Html
HtmlHtml
Html
 
Learning HTML
Learning HTMLLearning HTML
Learning HTML
 
Introduction To Xml
Introduction To XmlIntroduction To Xml
Introduction To Xml
 
Web designing using html
Web designing using htmlWeb designing using html
Web designing using html
 
Xml Zoe
Xml ZoeXml Zoe
Xml Zoe
 
Xml Zoe
Xml ZoeXml Zoe
Xml Zoe
 
1.1 xhtml basics
1.1 xhtml basics1.1 xhtml basics
1.1 xhtml basics
 
Html
HtmlHtml
Html
 
Introduction to Web Design
Introduction to Web DesignIntroduction to Web Design
Introduction to Web Design
 
Html guide
Html guideHtml guide
Html guide
 
Class2
Class2Class2
Class2
 
Html For Beginners 2
Html For Beginners 2Html For Beginners 2
Html For Beginners 2
 
Block2 Session2 Presentation
Block2 Session2 PresentationBlock2 Session2 Presentation
Block2 Session2 Presentation
 
Lecture1 B Frames&Forms
Lecture1 B  Frames&FormsLecture1 B  Frames&Forms
Lecture1 B Frames&Forms
 
AK html
AK  htmlAK  html
AK html
 

Último

Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
Call Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls GoaCall Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls Goa
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
sexy call girls service in goa
 
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goaGoa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
russian goa call girl and escorts service
 
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Apsara Of India
 

Último (20)

Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
Call Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls GoaCall Girls In Goa  9316020077 Goa  Call Girl By Indian Call Girls Goa
Call Girls In Goa 9316020077 Goa Call Girl By Indian Call Girls Goa
 
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
 
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
 
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
 
College Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls Service
College Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls ServiceCollege Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls Service
College Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls Service
 
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
 
Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...
Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...
Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...
 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
 
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goaGoa Call Girls 9316020077 Call Girls  In Goa By Russian Call Girl in goa
Goa Call Girls 9316020077 Call Girls In Goa By Russian Call Girl in goa
 
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Kolkata Call Girls Khardah ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
 
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
↑Top Model (Kolkata) Call Girls Behala ⟟ 8250192130 ⟟ High Class Call Girl In...
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
 
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Sonagachi Call Girls In All Kolkata 24/7 Provide Call W...
 
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
Karnal Call Girls 8860008073 Dyal Singh Colony Call Girls Service in Karnal E...
 
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
↑Top Model (Kolkata) Call Girls Sonagachi ⟟ 8250192130 ⟟ High Class Call Girl...
 
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
 
Almora call girls 📞 8617697112 At Low Cost Cash Payment Booking
Almora call girls 📞 8617697112 At Low Cost Cash Payment BookingAlmora call girls 📞 8617697112 At Low Cost Cash Payment Booking
Almora call girls 📞 8617697112 At Low Cost Cash Payment Booking
 

Introduction to HAML

  • 1. HAML For The Win! An introduction to HAML Oct. 13, 2011 1 Created for Magma Rails 2011 - www.magmarails.com Slides posted at http://tinyurl.com/magma-haml-sass Sample code from this presentation can be found in the following sample app: https://github.com/jonathandean/SASS-and-HAML-FTW
  • 2. What is HAML? A more concise syntax for coding HTML in your Rails app Uses indentation for nesting markup Reduces code (no closing tags) Fixes the messy markup problem that often clutters views Uses a CSS-like syntax that is easier to read and compare to your style rules Makes coding your View layer faster Note: doesn’t affect render time or client-side performance, simply reduces coding efforts and makes the developer more efficient Easy to learn! Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 2
  • 3. Using HAML in Rails Use it as a replacement for ERB files If you use Bundler, add this to your Gemfile: gem "haml” Files named filename.html.haml (instead of filename.html.erb) will be interpreted by HAML instead of ERB Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 3
  • 4. A comparison HTML <body> <div id=“wrapper”> <div class=“stuff”> <a href=“#”>Top</a> </div> </div> </body> HAML %body #wrapper .stuff %a{:href => “#”} Top Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 4 7 lines 78 characters 4 lines 36 characters Note: Some examples compile using different formatting, I changed them for the slides for readability
  • 5. Tag names Use % and then the name of the tag Examples: Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 5 HTML <body></body> <div></div> HAML %body %div
  • 6. ID’s ID’s are just like they are in CSS #id_name Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 6 HTML <div id=“mine”></div> <p id=“yours”></p> HAML %div#mine %p#yours
  • 7. Classes Classes are also just like they are in CSS .class_name Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 7 HTML <div class=“mine”></div> <p class=“yours”></p> HAML %div.mine %p.yours One way for multiple classes (more later) HTML <div class=“mine yours”></div> HAML %div.mine.yours
  • 8. div is the default tag name If you want to leave out the tag name and just put classes and/or ID’s, %div is assumed Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 8 HTML <div id=“mine”></div> HAML %div#mine (or just) #mine
  • 9. ID’s and Classes together Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 9 You can put ID’s and classes together as well HTML <div class=“yours” id=“mine”> </div> <div class=“yours his”id=“mine”> </div> HAML #mine.yours #mine.yours.his
  • 10. Nesting Tags are nested by indentation only No closing tags! Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 10 HAML #mine %p.yours hi! HTML <div id=“mine”> <p class=“yours”>hi!</p> </div>
  • 11. Text content Text can go at the end of the line if there’s no other content to nest Can also be nested itself (required with other nested content) Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 11 HAML #mine %p.yours hi! (or) #mine %p.yours hi! #mine %p.yours hi! %span dude HTML <div id=“mine”> <p class=“yours”>hi!</p> </div> <div id=“mine”> <p class=“yours”> hi! <span>dude</span> </p> </div> #mine %p.yourshi! %span dude
  • 12. Attributes Use a Ruby style hash for attributes Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 12 HTML <a href=“http://hi.com”>hi</a> <input type=“submit”> HAML %a{:href => ”http://hi.com”} hi %input{:type => "submit”} Or a more HTML-like syntax with () HAML %a(href=”http://hi.com”) hi %input(type="submit”) HTML <a href=“http://hi.com”>hi</a> <input type=“submit”>
  • 13. Boolean Attributes Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 13 Use boolean values for attributes such as “selected” HTML <input selected> <input> HAML %input{:selected => true} (or) %input(selected=true) (or) %input(selected) %input{:selected => false} (or) %input(selected=false)
  • 14. Using an array for ID’s and Classes For the ID attribute it will separate the values by an _ For the Class attribute it will add them as separate classes Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 14 HTML <p class=“one two”>hi</p> <p id=“one_two”>hi</p> HAML %p{:class => [‘one’,’two’]} hi %p{:id=> [‘one’,’two’]} hi
  • 15. HTML?? You can also use regular HTML Converting a file over time Copy/paste a tracking code or something complicated and hard to write as HAML Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 15 HTML <div id=“myParagraph”> <p>Hello there!</p> </div> HAML #myParagraph <p>Hello there!</p>
  • 16.
  • 17.
  • 18. Filters Filters start with a : and let you put in indented content to be interpreted in a special way :javascriptfilter wraps some JavaScript in <script> and CDATA tags for inline JavaScript Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 18 HTML <script> //<![CDATA[ alert(‘Hello there!’); //]]> </script> HAML :javascript alert(‘Hello there!’);
  • 19. Filters :cssfilter wraps some CSS in <style> and CDATA tags for inline CSS Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 19 HTML <style> /*<![CDATA[*/ .mine{ color: red; } /*]]>*/ </style> HAML :css .mine{ color: red; }
  • 20. Other filters :plain – does not parse the content :escaped – same as plain but HTML-escapes the text :ruby – pass the content to the normal Ruby interpreter :sass – parse the content with SASS to produce CSS output and more! (see the docs) You can also make custom filters if you have special needs Oct. 13, 2011 An Introduction to HAML by Jonathan Dean - www.jonathandean.com 20