SlideShare a Scribd company logo
1 of 26
Download to read offline
Haml
                     XHTML Abstraction Markup Language

“Any sufficiently complicated rhtml partial contains an
ad hoc, informally-specified, bug-ridden, implementation
of half of Haml.”
                          Dan Grigsby of railspikes.com

          http://scribd.com/doc/978532
What is Haml?
• Haml is based on one primary principal.
  Markup should be beautiful.
• ...it was created for use in highly productive
  environments. The beauty makes you faster.
• Stop using the slow, repetitive, and annoying
  templates that you don’t even know how
  much you hate yet.
Recreating Haml
• Original HTML document
     <div class=quot;productquot;>
       <div class=quot;namequot;>
         Foo
       </div>
       <div class=quot;pricequot;>
         $100.00
       </div>
       <div class=quot;updated_atquot;>
         9 Jan 15:13
       </div>
       <div class=quot;actionsquot;>
         <a href=quot;/products/foo/purchases/newquot;>buy</a>
       </div>
     </div>
Recreating Haml
• RHTML version of the page
  <div class=quot;productquot;>
    <div class=quot;namequot;>
      <%= product.name %>
    </div>
    <div class=quot;pricequot;>
      <%= number_to_currency product.price %>
    </div>
    <div class=quot;updated_atquot;>
      <%= product.to_s(:short) %>
    </div>
    <div class=quot;actionsquot;>
      <%= link_to 'buy', new_purchase_product_url(product) %>
      <% if product.owners.find_by_user_id(session[:user_id]) -%>
         <%= link_to 'sell', new_sale_product_url(product) %>
      <% end -%>
    </div>
  </div>
Recreating Haml
• Dropping closing tags and block “end”
  <div class=quot;productquot;>
    <div class=quot;namequot;>
      <%= product.name %>
    <div class=quot;pricequot;>
      <%= number_to_currency product.price %>
    <div class=quot;updated_atquot;>
      <%= product.to_s(:short) %>
    <div class=quot;actionsquot;>
      <%= link_to 'buy', new_purchase_product_url(product) %>
      <% if product.owners.find_by_user_id(session[:user_id]) -%>
        <%= link_to 'sell', new_sale_product_url(product) %>
Recreating Haml
• Removing <> Brackets
 div class=quot;productquot;
   div class=quot;namequot;
     = product.name
   div class=quot;pricequot;
     = number_to_currency product.price
   div class=quot;updated_atquot;
     = product.to_s(:short)
   div class=quot;actionsquot;
     = link_to 'buy', new_purchase_product_url(product)
     - if product.owners.find_by_user_id(session[:user_id])
       = link_to 'sell', new_sale_product_url(product)
Recreating Haml
• CSS shortcuts
 div.product
   div.name
     = product.name
   div.price
     = number_to_currency product.price
   div.updated_at
     = product.to_s(:short)
   div.actions
     = link_to 'buy', new_purchase_product_url(product)
     - if product.owners.find_by_user_id(session[:user_id])
       = link_to 'sell', new_sale_product_url(product)
Recreating Haml
• Drop the div tags (this is valid Haml)
  .product
    .name
      = product.name
    .price
      = number_to_currency product.price
    .updated_at
      = product.to_s(:short)
    .actions
      = link_to 'buy', new_purchase_product_url(product)
      - if product.owners.find_by_user_id(session[:user_id])
        = link_to 'sell', new_sale_product_url(product)
Comparison
<div class=quot;productquot;>                                             .product
  <div class=quot;namequot;>                                                .name
    <%= product.name %>                                               = product.name
  </div>                                                            .price
  <div class=quot;pricequot;>                                                 = number_to_currency product.price
    <%= number_to_currency product.price %>                         .updated_at
  </div>                                                              = product.to_s(:short)
  <div class=quot;updated_atquot;>                                          .actions
    <%= product.to_s(:short) %>                                       = link_to 'buy', new_purchase_product_url(product)
  </div>                                                              - if product.owners.find_by_user_id(session[:user_id])
  <div class=quot;actionsquot;>                                                 = link_to 'sell', new_sale_product_url(product)
    <%= link_to 'buy', new_purchase_product_url(product) %>
    <% if product.owners.find_by_user_id(session[:user_id]) -%>
                                                                  Alternative syntax:
       <%= link_to 'sell', new_sale_product_url(product) %>
    <% end -%>
                                                                  .product
  </div>
                                                                    .name= product.name
</div>
                                                                    .price= number_to_currency product.price
                                                                    .updated_at= product.to_s(:short)
                                                                    .actions
                                                                      = link_to 'buy', new_purchase_product_url(product)
                                                                      - if product.owners.find_by_user_id(session[:user_id])
                                                                        = link_to 'sell', new_sale_product_url(product)
Haml Features
•   Whitespace active

•   Well-formatted markup

•   DRY

•   Follows CSS conventions

•   Integrates with Ruby code

•   Implements Rails templates with the .haml
    extension
Using Haml

•   Haml 1.8.0 was released on January 6, 2008
    •   gem install haml

    •   haml --rails path/to/app

    •   echo '.message Hello, World' | haml
        # => “<div class='message'>Hello, World</div>”
Using Haml
• XML tags are specified with a %tagname
              %one
                %two
                   %three Hello, World



           <one>
             <two>
               <three>Hello, World</three>
             </two>
           </one>
Using Haml
 •     Brackets {} represent a Ruby hash that is used for
       specifying the attributes of an element.

%head{ :name => 'document_head' }
  %script{ 'type' => quot;text/quot; + quot;javascriptquot;, :src => quot;javascripts/script_#{2 + 7}.jsquot; }




           <head name='document_head'>
             <script src='javascripts/script_9.js' type='text/javascript'></script>
           </head>
Using Haml
•   Square brackets [] use the dom_id and
    dom_class methods to tag the element.
                       %div[@user]
                         %div[290] Hello!



        <div class='user' id='user_15'>
          <div class='fixnum' id='fixnum_581'>Hello!</div>
        </div>
Using Haml
•   . and # assign classes and ids, respectively.

          %div#things
            %span#rice Chicken Fried
            %p.beans{ :food => 'true' } The magical fruit
            %h1.class.otherclass#id La La La



        <div id='things'>
          <span id='rice'>Chicken Fried</span>
          <p class='beans' food='true'>The magical fruit</p>
          <h1 class='class otherclass' id='id'>La La La</h1>
        </div>
Using Haml
•   = is a shortcut for inserting Ruby code into an
    element.
                  #hello_1= quot;<span>Hello</span>quot;
                  #hello_2=h quot;<span>Hello</span>quot;




       <div id='hello_1'><span>Hello</span></div>
       <div id='hello_2'>&lt;span&gt;Hello&lt;/span&gt;</div>
Using Haml
•   - designates a Ruby block that should not be outputted.
    (notice no need for end)
              - (12...14).each do |i|
                %p= i
              %p See, I can count!
              %p.array
                - if [].blank?
                  %span.blank The array was blank.
                - else
                  %span.notblank The array was not blank.



           <p>12</p>
           <p>13</p>
           <p>See, I can count!</p>
           <p class='array'>
             <span class='blank'>The array was blank.</span>
           </p>
Sass
                  Syntactically Awesome StyleSheets



• Basically just another way of writing CSS.
• Like Haml, it is designed to be very DRY
  and help you write CSS faster.
• Supports nested selectors, constants, and
  simple arithmetic.
Using Sass
• Basic example of nested rules
#main p                      #main p {
  :color #0f0                  color: #0f0;
  :width 97%                   width: 97%; }
  .redbox                      #main p .redbox {
    :background-color #f00       background-color: #f00;
    :color #000                  color: #000; }
Using Sass
• Simple Sass can equal complex CSS
  #main                     #main {
    :width 97%                width: 97%; }
    p, div                    #main p, #main div {
      :font-size 2em            font-size: 2em; }
      a                         #main p a, #main div a {
        :font-weight bold         font-weight: bold; }
    pre                       #main pre {
      :font-size 3em            font-size: 3em; }
Using Sass
    • Constants and simple arithmetic
!bg_color   = #0f0                     #container {
!main_width = 700px                      width: 800px; }
!side_width = 100px                      #container #main {
                                           background-color: #00ff00;
#container                                 color: #20ff20;
  :width = !main_width + !side_width       width: 700px; }
  #main                                  #container #side {
    :background-color = !bg_color          width: 100px; }
    :color = !bg_color + 32
    :width = !main_width
  #side
    :width = !side_width
Using Sass
• Advanced Sass with parent selectors
                                   a{
a
                                     color: #00f; }
    :color #00f
                                     a.disabled {
    &.disabled
                                       color: #999 !important; }
      :color #999 !important
                                     a:link, a:active, a:visited {
    &:link, &:active, &:visited
                                       text-decoration: none; }
      :text-decoration none
                                       a:link span.hidden, a:active
      span.hidden
                                   span.hidden, a:visited span.hidden {
        :display none
                                         display: none; }
    &:visited
                                     a:visited {
      :color #00c
                                       color: #00c; }
    &:hover
                                     a:hover {
      :text-decoration underline
                                       text-decoration: underline; }
Performance


              Haml 1.7.2
              ERB
Performance


              Haml
              ERB
              Erubis
              Markaby
Performance


              Haml
              ERB
              Erubis
Haml in the Wild

•   MyStock mystock.com
    •   Rails 2 with Haml trunk


•   Grand Harmony Spa grandharmonyspa.com
    or 029a630.netsolhost.com (until DNS fixed)
    •   Generated with StaticMatic using Haml 1.7.2

More Related Content

Recently uploaded

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 slidevu2urc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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 Servicegiselly40
 
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 AutomationSafe Software
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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...Drew Madelung
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Atlanta Ruby Users Group (AtlRug) - January 2008 - Haml and Sass

  • 1. Haml XHTML Abstraction Markup Language “Any sufficiently complicated rhtml partial contains an ad hoc, informally-specified, bug-ridden, implementation of half of Haml.” Dan Grigsby of railspikes.com http://scribd.com/doc/978532
  • 2. What is Haml? • Haml is based on one primary principal. Markup should be beautiful. • ...it was created for use in highly productive environments. The beauty makes you faster. • Stop using the slow, repetitive, and annoying templates that you don’t even know how much you hate yet.
  • 3. Recreating Haml • Original HTML document <div class=quot;productquot;> <div class=quot;namequot;> Foo </div> <div class=quot;pricequot;> $100.00 </div> <div class=quot;updated_atquot;> 9 Jan 15:13 </div> <div class=quot;actionsquot;> <a href=quot;/products/foo/purchases/newquot;>buy</a> </div> </div>
  • 4. Recreating Haml • RHTML version of the page <div class=quot;productquot;> <div class=quot;namequot;> <%= product.name %> </div> <div class=quot;pricequot;> <%= number_to_currency product.price %> </div> <div class=quot;updated_atquot;> <%= product.to_s(:short) %> </div> <div class=quot;actionsquot;> <%= link_to 'buy', new_purchase_product_url(product) %> <% if product.owners.find_by_user_id(session[:user_id]) -%> <%= link_to 'sell', new_sale_product_url(product) %> <% end -%> </div> </div>
  • 5. Recreating Haml • Dropping closing tags and block “end” <div class=quot;productquot;> <div class=quot;namequot;> <%= product.name %> <div class=quot;pricequot;> <%= number_to_currency product.price %> <div class=quot;updated_atquot;> <%= product.to_s(:short) %> <div class=quot;actionsquot;> <%= link_to 'buy', new_purchase_product_url(product) %> <% if product.owners.find_by_user_id(session[:user_id]) -%> <%= link_to 'sell', new_sale_product_url(product) %>
  • 6. Recreating Haml • Removing <> Brackets div class=quot;productquot; div class=quot;namequot; = product.name div class=quot;pricequot; = number_to_currency product.price div class=quot;updated_atquot; = product.to_s(:short) div class=quot;actionsquot; = link_to 'buy', new_purchase_product_url(product) - if product.owners.find_by_user_id(session[:user_id]) = link_to 'sell', new_sale_product_url(product)
  • 7. Recreating Haml • CSS shortcuts div.product div.name = product.name div.price = number_to_currency product.price div.updated_at = product.to_s(:short) div.actions = link_to 'buy', new_purchase_product_url(product) - if product.owners.find_by_user_id(session[:user_id]) = link_to 'sell', new_sale_product_url(product)
  • 8. Recreating Haml • Drop the div tags (this is valid Haml) .product .name = product.name .price = number_to_currency product.price .updated_at = product.to_s(:short) .actions = link_to 'buy', new_purchase_product_url(product) - if product.owners.find_by_user_id(session[:user_id]) = link_to 'sell', new_sale_product_url(product)
  • 9. Comparison <div class=quot;productquot;> .product <div class=quot;namequot;> .name <%= product.name %> = product.name </div> .price <div class=quot;pricequot;> = number_to_currency product.price <%= number_to_currency product.price %> .updated_at </div> = product.to_s(:short) <div class=quot;updated_atquot;> .actions <%= product.to_s(:short) %> = link_to 'buy', new_purchase_product_url(product) </div> - if product.owners.find_by_user_id(session[:user_id]) <div class=quot;actionsquot;> = link_to 'sell', new_sale_product_url(product) <%= link_to 'buy', new_purchase_product_url(product) %> <% if product.owners.find_by_user_id(session[:user_id]) -%> Alternative syntax: <%= link_to 'sell', new_sale_product_url(product) %> <% end -%> .product </div> .name= product.name </div> .price= number_to_currency product.price .updated_at= product.to_s(:short) .actions = link_to 'buy', new_purchase_product_url(product) - if product.owners.find_by_user_id(session[:user_id]) = link_to 'sell', new_sale_product_url(product)
  • 10. Haml Features • Whitespace active • Well-formatted markup • DRY • Follows CSS conventions • Integrates with Ruby code • Implements Rails templates with the .haml extension
  • 11. Using Haml • Haml 1.8.0 was released on January 6, 2008 • gem install haml • haml --rails path/to/app • echo '.message Hello, World' | haml # => “<div class='message'>Hello, World</div>”
  • 12. Using Haml • XML tags are specified with a %tagname %one %two %three Hello, World <one> <two> <three>Hello, World</three> </two> </one>
  • 13. Using Haml • Brackets {} represent a Ruby hash that is used for specifying the attributes of an element. %head{ :name => 'document_head' } %script{ 'type' => quot;text/quot; + quot;javascriptquot;, :src => quot;javascripts/script_#{2 + 7}.jsquot; } <head name='document_head'> <script src='javascripts/script_9.js' type='text/javascript'></script> </head>
  • 14. Using Haml • Square brackets [] use the dom_id and dom_class methods to tag the element. %div[@user] %div[290] Hello! <div class='user' id='user_15'> <div class='fixnum' id='fixnum_581'>Hello!</div> </div>
  • 15. Using Haml • . and # assign classes and ids, respectively. %div#things %span#rice Chicken Fried %p.beans{ :food => 'true' } The magical fruit %h1.class.otherclass#id La La La <div id='things'> <span id='rice'>Chicken Fried</span> <p class='beans' food='true'>The magical fruit</p> <h1 class='class otherclass' id='id'>La La La</h1> </div>
  • 16. Using Haml • = is a shortcut for inserting Ruby code into an element. #hello_1= quot;<span>Hello</span>quot; #hello_2=h quot;<span>Hello</span>quot; <div id='hello_1'><span>Hello</span></div> <div id='hello_2'>&lt;span&gt;Hello&lt;/span&gt;</div>
  • 17. Using Haml • - designates a Ruby block that should not be outputted. (notice no need for end) - (12...14).each do |i| %p= i %p See, I can count! %p.array - if [].blank? %span.blank The array was blank. - else %span.notblank The array was not blank. <p>12</p> <p>13</p> <p>See, I can count!</p> <p class='array'> <span class='blank'>The array was blank.</span> </p>
  • 18. Sass Syntactically Awesome StyleSheets • Basically just another way of writing CSS. • Like Haml, it is designed to be very DRY and help you write CSS faster. • Supports nested selectors, constants, and simple arithmetic.
  • 19. Using Sass • Basic example of nested rules #main p #main p { :color #0f0 color: #0f0; :width 97% width: 97%; } .redbox #main p .redbox { :background-color #f00 background-color: #f00; :color #000 color: #000; }
  • 20. Using Sass • Simple Sass can equal complex CSS #main #main { :width 97% width: 97%; } p, div #main p, #main div { :font-size 2em font-size: 2em; } a #main p a, #main div a { :font-weight bold font-weight: bold; } pre #main pre { :font-size 3em font-size: 3em; }
  • 21. Using Sass • Constants and simple arithmetic !bg_color = #0f0 #container { !main_width = 700px width: 800px; } !side_width = 100px #container #main { background-color: #00ff00; #container color: #20ff20; :width = !main_width + !side_width width: 700px; } #main #container #side { :background-color = !bg_color width: 100px; } :color = !bg_color + 32 :width = !main_width #side :width = !side_width
  • 22. Using Sass • Advanced Sass with parent selectors a{ a color: #00f; } :color #00f a.disabled { &.disabled color: #999 !important; } :color #999 !important a:link, a:active, a:visited { &:link, &:active, &:visited text-decoration: none; } :text-decoration none a:link span.hidden, a:active span.hidden span.hidden, a:visited span.hidden { :display none display: none; } &:visited a:visited { :color #00c color: #00c; } &:hover a:hover { :text-decoration underline text-decoration: underline; }
  • 23. Performance Haml 1.7.2 ERB
  • 24. Performance Haml ERB Erubis Markaby
  • 25. Performance Haml ERB Erubis
  • 26. Haml in the Wild • MyStock mystock.com • Rails 2 with Haml trunk • Grand Harmony Spa grandharmonyspa.com or 029a630.netsolhost.com (until DNS fixed) • Generated with StaticMatic using Haml 1.7.2