get slim!

Post on 28-Nov-2014

294 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Simon Courtois - @happynoff

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

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

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

But there is another cool one!

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>

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.rb” ParisRB

Haml %a{href=“rubyparis.org” title=“Paris.rb”} ParisRB

Ok but why bother?

Speed!

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

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 youSimon Courtois - @happynoff

top related