Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Simon Courtois - @happynoff
Get Slim!
Two Default Rails Stacks
http://words.steveklabnik.com/rails-has-two-default-stacks
• Views: ERB
• DB: MySQL
• Tests: Mini...
Two Default Rails Stacks
http://words.steveklabnik.com/rails-has-two-default-stacks
• Views: ERB!
• DB: MySQL
• Tests: Min...
ERB Haml
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
!
<body>
<div id=“main” class=“content”>
<%= yield %>
...
But there is another cool one!
Slim
ERB Slim
doctype html
html
head
title Hello
!
body
#main.content
= yield
<!DOCTYPE html>
<html>
<head>
<title>Hello</title...
What’s the difference ?
First things first…
no fucking %
(haters gonna hate)
What about attributes?
ERB
Slim
<a href=“rubyparis.org” title=“Paris.rb”>ParisRB</a>
a href=“rubyparis.org” title=“Paris.r...
Ok but why bother?
Speed!
Secondstoreach10000iterations
0
0,4
0,8
1,2
1,6
1st run 2nd run
ERB Haml Slim
https://travis-ci.org/slim-template/slim/job...
What’s the trick then?
Spaces handling
%span Hello
%span Paris.rbHaml
Slim span Hello
span Paris.rb
Hello Paris.rb
HelloParis.rb
Spaces handling
Haml conserves spaces by default
Slim spaces are opt-in
Spaces handling
%span> Hello
%span Paris.rbHaml
Slim span Hello
span Paris.rb
HelloParis.rb
HelloParis.rb
Spaces handling
%span Hello
%span Paris.rbHaml
Slim span> Hello
span Paris.rb
Hello Paris.rb
Hello Paris.rb
Wanna nest things?
ul: li.active: a href=“rubyparis.org” Paris.rb
Go ahead!
One more thing
Like it logic-less?
- articles

p.title = title

.content = body
!
-! articles

p No articles yet!
Get it on
http://slim-lang.com/
Questions ?
Thank you
Simon Courtois - @happynoff
Upcoming SlideShare
Loading in …5
×

Get Slim!

1,549 views

Published on

Slides of my talk at Paris.rb on 2014-06-03 about the Slim templating syntax.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Get Slim!

  1. 1. Simon Courtois - @happynoff Get Slim!
  2. 2. Two Default Rails Stacks http://words.steveklabnik.com/rails-has-two-default-stacks • Views: ERB • DB: MySQL • Tests: MiniTest • Fat Models /
 Skinny Controllers • Views: Haml • DB: PostgreSQL • Tests: RSpec • Skinny Models /
 Skinny Controllers /
 Service Layer
  3. 3. Two Default Rails Stacks http://words.steveklabnik.com/rails-has-two-default-stacks • Views: ERB! • DB: MySQL • Tests: MiniTest • Fat Models /
 Skinny Controllers • Views: Haml! • DB: PostgreSQL • Tests: RSpec • Skinny Models /
 Skinny Controllers /
 Service Layer
  4. 4. ERB Haml <!DOCTYPE html> <html> <head> <title>Hello</title> </head> ! <body> <div id=“main” class=“content”> <%= yield %> </div> </body> </html> !!! 5 %html %head %title Hello ! %body #main.content = yield
  5. 5. But there is another cool one! Slim
  6. 6. ERB Slim doctype html html head title Hello ! body #main.content = yield <!DOCTYPE html> <html> <head> <title>Hello</title> </head> ! <body> <div id=“main” class=“content”> <%= yield %> </div> </body> </html>
  7. 7. What’s the difference ?
  8. 8. First things first… no fucking % (haters gonna hate)
  9. 9. What about attributes? ERB Slim <a href=“rubyparis.org” title=“Paris.rb”>ParisRB</a> a href=“rubyparis.org” title=“Paris.rb” ParisRB Haml %a{href=“rubyparis.org” title=“Paris.rb”} ParisRB
  10. 10. Ok but why bother?
  11. 11. Speed!
  12. 12. Secondstoreach10000iterations 0 0,4 0,8 1,2 1,6 1st run 2nd run ERB Haml Slim https://travis-ci.org/slim-template/slim/jobs/26437512
  13. 13. What’s the trick then?
  14. 14. Spaces handling %span Hello %span Paris.rbHaml Slim span Hello span Paris.rb Hello Paris.rb HelloParis.rb
  15. 15. Spaces handling Haml conserves spaces by default Slim spaces are opt-in
  16. 16. Spaces handling %span> Hello %span Paris.rbHaml Slim span Hello span Paris.rb HelloParis.rb HelloParis.rb
  17. 17. Spaces handling %span Hello %span Paris.rbHaml Slim span> Hello span Paris.rb Hello Paris.rb Hello Paris.rb
  18. 18. Wanna nest things? ul: li.active: a href=“rubyparis.org” Paris.rb Go ahead!
  19. 19. One more thing
  20. 20. Like it logic-less? - articles
 p.title = title
 .content = body ! -! articles
 p No articles yet!
  21. 21. Get it on http://slim-lang.com/
  22. 22. Questions ?
  23. 23. Thank you Simon Courtois - @happynoff

×