get slim!

23
Simon Courtois - @happynoff Get Slim!

Upload: simon-courtois

Post on 28-Nov-2014

294 views

Category:

Software


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Get Slim!

Simon Courtois - @happynoff

Get Slim!

Page 2: Get Slim!

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

Page 3: Get Slim!

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

Page 4: Get Slim!

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

Page 5: Get Slim!

But there is another cool one!

Slim

Page 6: Get Slim!

ERB Slimdoctype 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>

Page 7: Get Slim!

What’s the difference?

Page 8: Get Slim!

First things first…

no fucking %(haters gonna hate)

Page 9: Get Slim!

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

Page 10: Get Slim!

Ok but why bother?

Page 11: Get Slim!

Speed!

Page 12: Get Slim!

Seco

nds

to re

ach

1000

0 ite

ratio

ns

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

Page 13: Get Slim!

What’s the trick then?

Page 14: Get Slim!

Spaces handling

%span Hello %span Paris.rbHaml

Slim span Hello span Paris.rb

Hello Paris.rb

HelloParis.rb

Page 15: Get Slim!

Spaces handling

Haml conserves spaces by default

Slim spaces are opt-in

Page 16: Get Slim!

Spaces handling

%span> Hello %span Paris.rbHaml

Slim span Hello span Paris.rb

HelloParis.rb

HelloParis.rb

Page 17: Get Slim!

Spaces handling

%span Hello %span Paris.rbHaml

Slim span> Hello span Paris.rb

Hello Paris.rb

Hello Paris.rb

Page 18: Get Slim!

Wanna nest things?

ul: li.active: a href=“rubyparis.org” Paris.rb

Go ahead!

Page 19: Get Slim!

One more thing

Page 20: Get Slim!

Like it logic-less?

- articles p.title = title .content = body !-! articles p No articles yet!

Page 21: Get Slim!

Get it on

http://slim-lang.com/

Page 22: Get Slim!

Questions?

Page 23: Get Slim!

Thank youSimon Courtois - @happynoff