Introduction to HAML

11

Click here to load reader

description

Introduction to HAML

Transcript of Introduction to HAML

Page 1: Introduction to  HAML

INTRODUCTION TO

HAML

Page 2: Introduction to  HAML

HAML

HAML : HTML Abstract Markup Language Light weight Avoid inline code

Page 3: Introduction to  HAML

Main ideas of Haml

Markup should

Be beautiul Be clean Be sensible

Page 4: Introduction to  HAML

FEATURES

Whitespace active Well-formatted markup DRY Follows css conventions Implements rails templates with the .haml extention

Page 5: Introduction to  HAML

Size of code(erb) <table class="users_list"> <thead> <tr> <th>Name</th> <th>Email</th> </tr> </thead> <tbody> <% @users.each do |user| %> <tr> <td><%= user.name %></td> <td><%= user.email %></td> </tr> <% end %> </tbody> </table><% end %>

Page 6: Introduction to  HAML

Size of code(HAML)

%table.users_list %thead %tr %th Name %th Email %tbody - @users.each do |user| %tr %td= user.name %td= user.email

Page 7: Introduction to  HAML

No need for words :)

ERB : 16 lines of code HAML: 10 lines of code 37% less key presses in case of haml

Page 8: Introduction to  HAML

Installing Haml

Gem 'haml' Geneate rails application setup for haml -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

Page 9: Introduction to  HAML

Convert to HAML ERB <strong><%= item.title %></strong> Haml %strong= item.title HTML <strong class="code" id="message">Hello, World!</strong> Haml %strong{:class => "code", :id => "message"} Hello, World! %strong.code#message Hello, World!

Page 10: Introduction to  HAML

Why not haml

Whitespace can have syntatic meaning Many editors not supporting haml Needs to be install Can be slower than html Without ugly 2.803 + 0.036 With ugly 1.037 + 1.0124

Page 11: Introduction to  HAML

Thank you