130 likes | 451 Views
Danial Parsa Negin Parya. HAML. HTML Abstraction Markup Language Doesn’t use of traditional inline coding. Makes markup as elegant as it can be. Haml's equivalent for CSS is Sass. What is HAML?. Markup should be beautiful Markup should be DRY <h1>Teen Wolf</h1 >
E N D
DanialParsa NeginParya HAML
HTML Abstraction Markup Language Doesn’t use of traditional inline coding. Makes markup as elegant as it can be. Haml's equivalent for CSS is Sass. What is HAML?
Markup should be beautiful • Markup should be DRY • <h1>Teen Wolf</h1> • Markup should be well-indented • XHTML structure should be clear Haml principals
Why use haml? • <% if @users.empty? %> <div class="empty_collection"> <em>Could not find any users.</em> </div><% else %> <table class="users_list"> <thead> <tr> <th>Name</th> <th>Email</th> <th>Age</th> </tr> </thead> <tbody> <% @users.each do |user| %> <tr class="<%= cycle('odd','even') %>"> <td><%= user.name %></td> <td><%= user.email %></td> <td><%= user.age %></td> </tr> <% end %> </tbody> </table><% end %> • if @users.empty? .empty_collection %em Could not find any users- else %table.users_list %thead %tr %th Name %th Email %th Age %tbody - @users.each do |user| %tr{:class => cycle('odd','even')} %td= user.name %td= user.email %td= user.age
Standard Gem • gem install haml • haml-edge Gem • gem install haml-edge • Installation from Git • git clone git://github.com/nex3/haml.git • cdhaml • rake install Install haml
before Rails 3, add the following line to environment.rb: config.gem "haml“ For Rails 3 add the following line to the Gemfile: gem "haml" Enable haml in rails
app/views/account/login.html.erb→ app/views/account/login.html.haml Getting started
Attribute Methods def html_attrs(lang = 'en-US') {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang} end Then it can be used like: %html{html_attrs('fr-fr')} <html lang='fr-fr' xml:lang='fr-fr' xmlns='http://www.w3.org/1999/xhtml'> </html>
Element Name: % %one %two %three Hey there <one> <two> <three>Hey there</three> </two> </one>
Class and ID: . and # is compiled to:
Running Ruby: - -foo = "hello“ -foo << " there" -foo << " you!" %p= foo is compiled to: <p> hello there you! </p>
http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html http://haml-lang.com/ http://en.wikipedia.org/wiki/Haml http://blog.digimonkey.com/2010/02/why-use-haml-and-sass-i-already-know-html/ References