SlideShare une entreprise Scribd logo
1  sur  72
Télécharger pour lire hors ligne
Patrick Crowley
  the.railsi.st
Haml & Sass
in 15 minutes
What are Haml and Sass?
•   Template languages
•Template languages

• Haml generates .html
•Template languages

• Haml generates .html
• Sass generates .css
•Template languages

• Haml generates .html
• Sass generates .css

• You can use one or both
Do I have to learn another
   markup language?
Yes, you do. Get over it.
“Haml is poetry.”
       Max Muermann
The principles of Haml...
•   Markup should be beautiful
•Markup should be beautiful

• Markup should be DRY
•Markup should be beautiful

• Markup should be DRY
• Markup should be indented
•Markup should be beautiful

• Markup should be DRY
• Markup should be indented

• Structure should be clear
The Basics
•   White space active
•White space active

• Indentation = structure
•White space active

• Indentation = structure
• Tags begin with %
•White space active

• Indentation = structure
• Tags begin with %

• Tags close themselves
•White space active

• Indentation = structure
• Tags begin with %

• Tags close themselves
• Use hashes for attributes
<h1>Haml is cool</h1>
%h1 Haml is cool
<h1>Haml is cool, Lisa</h1>
<h1>Haml is cool,
<%= @name %></h1>
%h1 = quot;Haml is cool, #{@name}quot;
<div id=quot;colorquot;>Red</h1>
%div#color Red
#color Red
Loops
<ul id=quot;friendsquot;>
<% @friends.each do |friend| %>
<li><%= friend.name %></li>
<% end %>
</ul>
%ul#friends
- @friends.each do |friend|
	 %li= friend.name
<ul id=quot;friendsquot;>
 <li>Ted</li>
 <li>Erin</li>
 <li>Gerry</li>
</ul>
Attributes
ul#friends
- @friends.each do |friend|
	 %li= friend.name
ul{:id => quot;friendsquot;, :class => quot;listquot;}
- @friends.each do |friend|
	 %li= friend.name
<ul id=quot;friendsquot; class=quot;listquot;>
 <li>Ted</li>
 <li>Erin</li>
 <li>Gerry</li>
</ul>
Forms
<% if logged_in? -%>


 <% form_for :comment, :url => blog_comments_path(@post) do |f| %>


 <label for=quot;comment_commentquot;>Post a comment:</label>

 <%= f.text_area :comment, :rows => 14, :cols => 40 %>


 <%= submit_tag quot;Add commentquot; %>


 <% end -%>

<% else -%>


 <%= link_to quot;Loginquot;, :action => quot;loginquot; %>

<% end -%>
if logged_in?
  - form_for :comment, :url => blog_comments_path(@post) do |f|

    %label{:for => quot;comment_commentquot;} Post a comment:

    = f.text_area :comment, :rows => 14, :cols => 40

    = submit_tag quot;Add commentquot;

- else

 = link_to quot;Loginquot;, :action => quot;loginquot;
Layouts
<head><!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0 Strict//ENquot;
  quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtdquot;>
<html xmlns=quot;http://www.w3.org/1999/xhtmlquot; xml:lang=quot;enquot; lang=quot;enquot;>
<head>
<meta http-equiv=quot;content-typequot; content=quot;text/html;charset=UTF-8quot; />
<%= title :site => quot;Graffletopiaquot;, :separator => quot;-quot; %>
<%= stylesheets %>
<%= javascript_include_tag :defaults %>
</head>
<body>

<% if logged_in? %>
<p>You are logged in.</p>
<% end %>

<% if flash[:notice] != nil -%>
<p><%= flash[:notice] %></p>
<% end -%>

<%= yield %>

</body>
</html>
!!! Strict
%html{html_attrs}
  %head
    = title :site => quot;Graffletopiaquot;, :separator => quot;-quot;
    %meta{:http-equiv => quot;Content-typequot;, :content => quot;text/html;charset=UTF-8quot;}
    = stylesheets
    = javascript_include_tag :defaults
  %body
    - if logged_in?
      %p You are logged in.
    - if flash[:notice] != nil
      %p= flash[:notice]
    = yield
Sass
Basic syntax
#box {
  border: 0;
	 color: black;
  }
#box
  border: 0
	 color: black
#box
  :border 0
	 :color black
Nesting
#box
  :border 0
	 :color black
	 .orange
	 :border 1px orange
#box {
  border: 0;
	 color: black;
  }

#box .orange {
	 border: 1px orange;
  }
Variables
!pink = #f3f
#box
  :border 0
	 :color black
	 .pink
	 :border = !pink
#box {
  border: 0;
	 color: black;
  }

#box .pink {
	 color: #f3f;
  }
Comments
/* Homepage box
#box
  :border 0
	 :color black
Now go play!
script/plugin install
http://svn.hamptoncatlin.com/haml/tags/stable
Helpful hints
• Grab the TextMate bundles
• Grab the TextMate bundles
• Start a template at a time
• Grab the TextMate bundles
• Start a template at a time

• Use .haml or .html.haml
• Grab the TextMate bundles
• Start a template at a time

• Use .haml or .html.haml
• Use .sass
• Grab the TextMate bundles
• Start a template at a time

• Use .haml or .html.haml
• Use .sass

• Screw up? Check whitespace
• Grab the TextMate bundles
• Start a template at a time

• Use .haml or .html.haml
• Use .sass

• Screw up? Check whitespace
• Move logic to helpers
Have fun!
The End
Haml And Sass In 15 Minutes

Contenu connexe

Tendances

Basics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPointBasics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPoint
Sahil Gandhi
 
01 Introduction To CSS
01 Introduction To CSS01 Introduction To CSS
01 Introduction To CSS
crgwbr
 

Tendances (20)

How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
 
Basics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPointBasics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPoint
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
Using LESS, the CSS Preprocessor: J and Beyond 2013
Using LESS, the CSS Preprocessor: J and Beyond 2013Using LESS, the CSS Preprocessor: J and Beyond 2013
Using LESS, the CSS Preprocessor: J and Beyond 2013
 
CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
Less css
Less cssLess css
Less css
 
01 Introduction To CSS
01 Introduction To CSS01 Introduction To CSS
01 Introduction To CSS
 
Web Design 101
Web Design 101Web Design 101
Web Design 101
 
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone developmentiPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
 
Front End Tooling and Performance - Codeaholics HK 2015
Front End Tooling and Performance - Codeaholics HK 2015Front End Tooling and Performance - Codeaholics HK 2015
Front End Tooling and Performance - Codeaholics HK 2015
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
[Worskhop Summits] CSS3 Workshop
[Worskhop Summits] CSS3 Workshop[Worskhop Summits] CSS3 Workshop
[Worskhop Summits] CSS3 Workshop
 
Rapid and Responsive - UX to Prototype with Bootstrap
Rapid and Responsive - UX to Prototype with BootstrapRapid and Responsive - UX to Prototype with Bootstrap
Rapid and Responsive - UX to Prototype with Bootstrap
 
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS Workshop
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
 
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
 
CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong? CSS3 - is everything we used to do wrong?
CSS3 - is everything we used to do wrong?
 
LESS, the CSS Preprocessor
LESS, the CSS PreprocessorLESS, the CSS Preprocessor
LESS, the CSS Preprocessor
 

Similaire à Haml And Sass In 15 Minutes

Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 

Similaire à Haml And Sass In 15 Minutes (20)

Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of Twig
 
Haml and Sass Introduction
Haml and Sass IntroductionHaml and Sass Introduction
Haml and Sass Introduction
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
A Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsA Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on Rails
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with Shoes
 
SASS In The Real World
SASS In The Real WorldSASS In The Real World
SASS In The Real World
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Haml And Sass: Put your markup on a diet
Haml And Sass: Put your markup on a dietHaml And Sass: Put your markup on a diet
Haml And Sass: Put your markup on a diet
 
Plan your web site like you plan your parties
Plan your web site like you plan your partiesPlan your web site like you plan your parties
Plan your web site like you plan your parties
 
Juggling
JugglingJuggling
Juggling
 
Visualforce css developer guide(by forcetree.com)
Visualforce css developer guide(by forcetree.com)Visualforce css developer guide(by forcetree.com)
Visualforce css developer guide(by forcetree.com)
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Haml, Sass & Compass
Haml, Sass & CompassHaml, Sass & Compass
Haml, Sass & Compass
 
Xlrays online web tutorials
Xlrays online web tutorialsXlrays online web tutorials
Xlrays online web tutorials
 
CSS naming | ceci n'est pas un pipe
CSS naming | ceci n'est pas un pipeCSS naming | ceci n'est pas un pipe
CSS naming | ceci n'est pas un pipe
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
 
Fasten RWD Development with Sass
Fasten RWD Development with SassFasten RWD Development with Sass
Fasten RWD Development with Sass
 

Plus de Patrick Crowley (10)

Compass
CompassCompass
Compass
 
Mobile web apps
Mobile web appsMobile web apps
Mobile web apps
 
Trucker
TruckerTrucker
Trucker
 
Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)
 
Migrating Legacy Data
Migrating Legacy DataMigrating Legacy Data
Migrating Legacy Data
 
Paperclip
PaperclipPaperclip
Paperclip
 
CSS for iPhones
CSS for iPhonesCSS for iPhones
CSS for iPhones
 
Rails For Legacy Apps
Rails For Legacy AppsRails For Legacy Apps
Rails For Legacy Apps
 
Headliner
HeadlinerHeadliner
Headliner
 
Styler
StylerStyler
Styler
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Haml And Sass In 15 Minutes