SlideShare a Scribd company logo
Haml, Sass and Compass for Sane Web Development Jeremy Weiskotten @doctorzaius
(We’re hiring.)
Haml
 
 
Mark Hamill may not be beautiful, but…
“ Markup should be beautiful.” http://haml-lang.com
Is  this  beautiful?
No.
 
 
 
 
HTML Tags %p My paragraph. %span= @user.first_name %ul %li Item 1 %li Item 2
Tags with IDs and Classes %p#summary %span.hint %p#summary.magnificent.bastard
Tags with Attributes %img{:src => ‘images/tree.jpg’, :alt => ‘My favorite tree’} Produces… <img src=“images/tree.jpg alt=“My favorite tree” />
Tags with Attributes %a.new{:href => new_thing_path} Click me! Produces… <a class=“new” href=“/things/new”>Click me!</a>
Tags with HTML 5 Data Attributes %ul.todo %li{:data => { :priority => 1, :cost => 0 }} Kick ass %li{:data => { :priority => 2, :cost => 1 }} Chew bubble gum <ul class=“todo”> <li data-priority=“1” data-cost=“0”>Kick ass</li> <li data-priority=“2” data-cost=“1”>Chew bubble gum</li> </ul>
Attributes, HTML-style %img(src=‘images/tree.jpg’ alt=‘My favorite tree’) %a.new(href=new_thing_path) Click me
Attribute helpers %body{  body_attributes  } def  body_attributes { :id => controller.controller_name, :class => controller.action_name } end
Attribute helpers %li{  user_li_attributes (person)  } def  user_li_attributes (user) {}.tap do |attr| attr[:id] = dom_id(user) attr[:class] = ‘active’ if user == current_user end end
Flow & Output - if signed_in? = current_user.first_name - else = link_to ‘Sign in’, sign_in_path content_for :head do = javascript_include_tag ‘foo’
Not.
Haml Sucks for Content * Whitespace pain, particularly around punctuation Content is not structure Use a filter for inline content markup * See http://chriseppstein.github.com/blog/2010/02/08/haml-sucks-for-content/
Content Filters :textile, :markdown, :maruku, etc. .summary :textile h1. Welcome, #{current_user.name}. If you’re not, *#{current_user.name}*,  “ sign out”:#{sign_out_path}!
JavaScript Filter :javascript var annoyingMsg = ‘Welcome,  #{current_user.first_name}!’; $(function() { $(‘#welcome’).html(annoyingMsg); });
So why do I like Haml?
So why do I like Haml? Clean, well-structured source Easy to write, read & maintain
So why do I like Haml? Clean, well-structured source Easy to write, read & maintain Encourages good practices Minimal code in the view Extract helpers, partials
So why do I like Haml? Clean, well-structured source Easy to write, read & maintain Encourages good practices Minimal code in the view Extract helpers, partials Better mental mapping to CSS
gem install haml
Sass
CSS that doesn’t suck (as much)
Sass is a big deal.
Typical CSS
Sass Nested Rules
Parent Selector a { text-decoration: none; &:hover  { text-decoration: underline; } }
Typical CSS
Sass Mixin
Variables $highlight-color : #ff0; span.highlight { background-color:  $highlight-color ; }
OMG COLOR MATH! $highlight-color: #ff0; span.highlight { background-color: $highlight-color; color:  darken ($highlight-color, 70%); }
Other Kinds of Functions Color saturation, hue Opacity Math (round, ceil, floor, abs) Units Extensible: Add your own
What does it mean? CSS  programmability Composition Reuse Organization Better separation   of presentation from structure and content
A few more things... @import @extend @if / @else @for, @while
http://sass-lang.com
Compass
It’s a framework … for frameworks Built on Sass Easy integration with Rails, Rack, Ramaze, Sinatra, … Fresh, minty breath
Lots of toys!
With the Having of Many Useful Mixins Border radius Box shadow Float clearing (without markup) Image replacement
I don’t even know what most of these things are Resets CSS3 transitions Sticky footer Table striping And lots more!
Grid Systems Without Class-plosion Blueprint 960.gs Susy YUI etc
Fancy Buttons
Lemonade .logo { background: sprite-image(&quot;lemonade/lemonade-logo.png&quot;); } .lime { background: sprite-image(&quot;lemonade/lime.png&quot;); } .coffee { background: sprite-image(&quot;other-drinks/coffee.png&quot;) no-repeat; }
Questions? Did you write these? No. Credit to Hampton Catlin, Nathan Weizenbaum, Chris Eppstein, and others. How can I learn more? haml-lang.com, sass-lang.com, compass-style.org Why did Mark Hamill let himself go? The 80s were hard on all of us.
Thanks! Jeremy Weiskotten Blueleaf @doctorzaius

More Related Content

KEY
Why I love Haml
PDF
Layout with CSS
PDF
Creating a Webpage from a Template
PPTX
Wp meetup custom post types
ODP
Mechanize at the Ruby Drink-up of Sophia, November 2011
PDF
Modern Front-End Development
PPT
WordPress theme frameworks
PPT
Vancouver League of Drupallers - Remembering the User (August 2008)
Why I love Haml
Layout with CSS
Creating a Webpage from a Template
Wp meetup custom post types
Mechanize at the Ruby Drink-up of Sophia, November 2011
Modern Front-End Development
WordPress theme frameworks
Vancouver League of Drupallers - Remembering the User (August 2008)

What's hot (20)

PDF
Html for beginners
PPTX
Supercharged HTML & CSS
PPTX
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
PPTX
Page layout with css
PDF
Haml And Sass In 15 Minutes
PDF
Modular HTML, CSS, & JS Workshop
PDF
Web design for right-to-left languages
PPTX
CSS Layout Tutorial
KEY
HTML CSS & Javascript
PPTX
11 marquee
ZIP
Twitter Bootstrap
PPT
HTML & CSS Workshop Notes
PDF
Pemrograman Web 4 - Bootstrap 3
PPT
Designing Firefox Themes
PDF
Whirlwind Tour of SVG (plus RaphaelJS)
KEY
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
PPT
CSS Best practices
PPTX
Basics of Front End Web Dev PowerPoint
KEY
Twitter Bootstrap (spring)
PPTX
Bootstrap [part 2]
Html for beginners
Supercharged HTML & CSS
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
Page layout with css
Haml And Sass In 15 Minutes
Modular HTML, CSS, & JS Workshop
Web design for right-to-left languages
CSS Layout Tutorial
HTML CSS & Javascript
11 marquee
Twitter Bootstrap
HTML & CSS Workshop Notes
Pemrograman Web 4 - Bootstrap 3
Designing Firefox Themes
Whirlwind Tour of SVG (plus RaphaelJS)
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
CSS Best practices
Basics of Front End Web Dev PowerPoint
Twitter Bootstrap (spring)
Bootstrap [part 2]
Ad

Viewers also liked (6)

KEY
New Massachusetts Data Privacy Regulation
PPTX
Monolithic 140503234652-phpapp01
 
PDF
A Greener Wedding
PPT
Copia de adjectives in comparision
PDF
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
PDF
Odoo - Open Source CMS: A performance comparision
New Massachusetts Data Privacy Regulation
Monolithic 140503234652-phpapp01
 
A Greener Wedding
Copia de adjectives in comparision
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
Odoo - Open Source CMS: A performance comparision
Ad

Similar to Haml, Sass and Compass for Sane Web Development (20)

PDF
Haml And Sass: Put your markup on a diet
PDF
Haml Presentation
KEY
Authoring Stylesheets with Compass & Sass
PDF
A complete html and css guidelines for beginners
KEY
Sass: The Future of Stylesheets
PDF
PDF
Killing the Angle Bracket
PDF
Introduction to HTML-CSS-Javascript.pdf
PDF
Old Dog, New Tricks
PDF
Sass that CSS
PDF
Create a landing page
PPT
Html & CSS - Best practices 2-hour-workshop
PPTX
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
PDF
Big Design Conference: CSS3
PPTX
Introduction to HTML+CSS+Javascript.pptx
PPTX
Introduction to HTML+CSS+Javascript.pptx
PDF
Web Design for Literary Theorists II: Overview of CSS (v 1.0)
KEY
Advanced Technology for Web Application Design
PPT
Web design-workflow
PDF
HTML+CSS: how to get started
Haml And Sass: Put your markup on a diet
Haml Presentation
Authoring Stylesheets with Compass & Sass
A complete html and css guidelines for beginners
Sass: The Future of Stylesheets
Killing the Angle Bracket
Introduction to HTML-CSS-Javascript.pdf
Old Dog, New Tricks
Sass that CSS
Create a landing page
Html & CSS - Best practices 2-hour-workshop
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
Big Design Conference: CSS3
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
Web Design for Literary Theorists II: Overview of CSS (v 1.0)
Advanced Technology for Web Application Design
Web design-workflow
HTML+CSS: how to get started

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
KodekX | Application Modernization Development
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
Teaching material agriculture food technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation theory and applications.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KodekX | Application Modernization Development
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Teaching material agriculture food technology

Haml, Sass and Compass for Sane Web Development

  • 1. Haml, Sass and Compass for Sane Web Development Jeremy Weiskotten @doctorzaius
  • 4.  
  • 5.  
  • 6. Mark Hamill may not be beautiful, but…
  • 7. “ Markup should be beautiful.” http://haml-lang.com
  • 8. Is this beautiful?
  • 9. No.
  • 10.  
  • 11.  
  • 12.  
  • 13.  
  • 14. HTML Tags %p My paragraph. %span= @user.first_name %ul %li Item 1 %li Item 2
  • 15. Tags with IDs and Classes %p#summary %span.hint %p#summary.magnificent.bastard
  • 16. Tags with Attributes %img{:src => ‘images/tree.jpg’, :alt => ‘My favorite tree’} Produces… <img src=“images/tree.jpg alt=“My favorite tree” />
  • 17. Tags with Attributes %a.new{:href => new_thing_path} Click me! Produces… <a class=“new” href=“/things/new”>Click me!</a>
  • 18. Tags with HTML 5 Data Attributes %ul.todo %li{:data => { :priority => 1, :cost => 0 }} Kick ass %li{:data => { :priority => 2, :cost => 1 }} Chew bubble gum <ul class=“todo”> <li data-priority=“1” data-cost=“0”>Kick ass</li> <li data-priority=“2” data-cost=“1”>Chew bubble gum</li> </ul>
  • 19. Attributes, HTML-style %img(src=‘images/tree.jpg’ alt=‘My favorite tree’) %a.new(href=new_thing_path) Click me
  • 20. Attribute helpers %body{ body_attributes } def body_attributes { :id => controller.controller_name, :class => controller.action_name } end
  • 21. Attribute helpers %li{ user_li_attributes (person) } def user_li_attributes (user) {}.tap do |attr| attr[:id] = dom_id(user) attr[:class] = ‘active’ if user == current_user end end
  • 22. Flow & Output - if signed_in? = current_user.first_name - else = link_to ‘Sign in’, sign_in_path content_for :head do = javascript_include_tag ‘foo’
  • 23. Not.
  • 24. Haml Sucks for Content * Whitespace pain, particularly around punctuation Content is not structure Use a filter for inline content markup * See http://chriseppstein.github.com/blog/2010/02/08/haml-sucks-for-content/
  • 25. Content Filters :textile, :markdown, :maruku, etc. .summary :textile h1. Welcome, #{current_user.name}. If you’re not, *#{current_user.name}*, “ sign out”:#{sign_out_path}!
  • 26. JavaScript Filter :javascript var annoyingMsg = ‘Welcome, #{current_user.first_name}!’; $(function() { $(‘#welcome’).html(annoyingMsg); });
  • 27. So why do I like Haml?
  • 28. So why do I like Haml? Clean, well-structured source Easy to write, read & maintain
  • 29. So why do I like Haml? Clean, well-structured source Easy to write, read & maintain Encourages good practices Minimal code in the view Extract helpers, partials
  • 30. So why do I like Haml? Clean, well-structured source Easy to write, read & maintain Encourages good practices Minimal code in the view Extract helpers, partials Better mental mapping to CSS
  • 32. Sass
  • 33. CSS that doesn’t suck (as much)
  • 34. Sass is a big deal.
  • 37. Parent Selector a { text-decoration: none; &:hover { text-decoration: underline; } }
  • 40. Variables $highlight-color : #ff0; span.highlight { background-color: $highlight-color ; }
  • 41. OMG COLOR MATH! $highlight-color: #ff0; span.highlight { background-color: $highlight-color; color: darken ($highlight-color, 70%); }
  • 42. Other Kinds of Functions Color saturation, hue Opacity Math (round, ceil, floor, abs) Units Extensible: Add your own
  • 43. What does it mean? CSS programmability Composition Reuse Organization Better separation of presentation from structure and content
  • 44. A few more things... @import @extend @if / @else @for, @while
  • 47. It’s a framework … for frameworks Built on Sass Easy integration with Rails, Rack, Ramaze, Sinatra, … Fresh, minty breath
  • 49. With the Having of Many Useful Mixins Border radius Box shadow Float clearing (without markup) Image replacement
  • 50. I don’t even know what most of these things are Resets CSS3 transitions Sticky footer Table striping And lots more!
  • 51. Grid Systems Without Class-plosion Blueprint 960.gs Susy YUI etc
  • 53. Lemonade .logo { background: sprite-image(&quot;lemonade/lemonade-logo.png&quot;); } .lime { background: sprite-image(&quot;lemonade/lime.png&quot;); } .coffee { background: sprite-image(&quot;other-drinks/coffee.png&quot;) no-repeat; }
  • 54. Questions? Did you write these? No. Credit to Hampton Catlin, Nathan Weizenbaum, Chris Eppstein, and others. How can I learn more? haml-lang.com, sass-lang.com, compass-style.org Why did Mark Hamill let himself go? The 80s were hard on all of us.
  • 55. Thanks! Jeremy Weiskotten Blueleaf @doctorzaius

Editor's Notes

  • #14: Note: 2 space indentation