We are unable to create an online viewer for this document. Please download the document instead.
HAMLor, how to get <arrowheads> out of your facePresented by Clifford HeathIs THIS YOU?when you see...<div id="column1" class= "robust"> <div class="sidebaritem"> <div class="sbihead"> <h1>Status Watch</h1> </div> <div class="sbicontent"> <%= render :partial => 'layouts/sidebar', :locals => { :value =>@mvalue } %> </div> </div> <div class="sidebaritem"> <div class="sbihead"> <h1>Your Account</h1> </div> <div class="sbilinks"> <ul> <% if session[:user_id] %> <li><%= link_to 'Log Out', :controller => 'authenticate', :action => 'logout' %></li> <% if @user && @user[:is_admin] -%> <li><%= link_to "Administration", :controller => 'admin', :action => 'index' %></li></etc></etc></etc> the right number of times ...With HAML...#column1.robust .sidebaritem .sbihead %h1 Status Watch .sbicontent = render :partial => 'layouts/sidebar', :locals => { :value =>@mvalue } .sidebaritem .sbihead %h1 Your Account .sbilinks %ul - if @user %li= link_to 'Log Out', :controller => 'authenticate', :action => 'logout' - if @user[:is_admin] %li= link_to "Administration", :controller => 'admin', :action => 'index' What’s Changed? All <arrowheads> are goneTags and code both self-close by indentationid=”xyz” and class=”abc” are just #xyz and .abc<div> is the default tag - for others, use %tag<%= some code %> is now just = some codeSame for <% some code -%>, use - some codeVisual SimplicityThe RHTML version has 261 lexical tokenscounting each word in strings and syntactic white-spaceThe HAML version has 117 tokensThat makes it easier on the eyes and the fingers!Markup HaikuRead it again...#column1.robust .sidebaritem .sbihead %h1 Status Watch .sbicontent = render :partial => 'layouts/sidebar', :locals => { :value =>@mvalue } .sidebaritem .sbihead %h1 Your Account .sbilinks %ul - if @user %li= link_to 'Log Out', :controller => 'authenticate', :action => 'logout' - if @user[:is_admin] %li= link_to "Administration", :controller => 'admin', :action => 'index' Extra benefitsNeed care to close tags correctly in RHTMLIn HAML, generated code is indented properlyincluding after nesting layouts and partials!valid XHTML with no extra effortDIVs almost always get a class or an ID or bothPlays well with RHTML during conversionOther nicetiesAttribute values are Ruby code:%label{:for=>@field.name}= @field.description+’:’Ruby blocks are automatically closed:%table - @people.each do |person| %tr %td= person.name%p.footer You can declare multiple classes, etc:%td.person.alignleft#husband= @husband.nameOther niceties... 2ID and class attributes can come from an object:%div[@mother]uses @mother.class and @mother.id to become:<div class=”person” id=”person_5724”>Most self-closing tags are recognisedothers may be declared self-closed: %br/Comments start with a single / and are output!Even multi-line; a comment wraps indented content
Add New Comment