SlideShare a Scribd company logo
The Skinny On Slim
Presentation by Eric Mulligan
➢ What Is Slim?
➢ Why Slim?
➢ Syntax
➢ Features
➢ Slim vs HAML & ERB
➢ Demo
Outline
➢ A template engine for Ruby.
➢ Developed by Daniel Mendler in 2010.
➢ Similar to HAML & Jade (JavaScript).
➢ Supports Rails 3 & 4, Sinatra and other Rack-based
web frameworks.
➢ Tested on all major Ruby implementations.
What Is Slim?
➢ Core syntax is guided by one thought:
“What is the minimum required to make this work?”
➢ Allows us to write minimal templates.
➢ Syntax is aesthetically pleasing which makes it fun to
write templates.
➢ Designed with performance in mind.
➢ Guarantees well-formed HTML and XML.
➢ Faster to compile than HAML.
Why Slim?
Installation:
From the command line:
From a Gemfile:
Verbatim Text:
‘|’ tells Slim to copy the line and does no
processing. You can even embed HTML and it
will simply output it as is.
Syntax
gem install slim
gem ‘slim’
| This is some random text.
Outputs:
This is some random text.
| <p>A paragraph.</p>
Outputs:
<p>A paragraph</p>
Control Code:
The ‘-’ denotes control code such as
conditionals and loops. ‘end’ is forbidden as
blocks are defined by indentation only.
Dynamic Content:
The ‘=’ outputs the result of the Ruby call and
adds the output to the buffer.
The ‘==’ is the same as ‘=’, however, all HTML
is not escaped which is perfect for ‘yield’ and
‘render’ method calls.
- if @users.empty?
- @users.each do |user|
| I am a user.
= javascript_include_tag ‘application’
p = link_to ‘Link’, ‘#’
== yield
== render ‘partials/form’, locals: { user: @user }
Syntax (cont.)
Comments:
‘/’ does not output any markup.
‘/!’, however, outputs HTML comments.
‘/[if IE]’ outputs IE conditional comments.
Syntax (cont.)
/ This line won’t be displayed.
/! This line will be displayed as an HTML comment.
Outputs:
<!-- This line will be displayed as an HTML comment →
/[if IE]
p Some paragraph.
Outputs:
<--![if IE]--><p>Some paragraph</p><![endif]-->
DOCTYPE:
HTML doctypes:
XML doctypes:
doctype html
doctype 5
Outputs:
<!DOCTYPE html>
doctype 1.1
Outputs:
<!DOCTYPE html PUBLIC - “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
doctype xml
Outputs:
<?xml version=”1.0” encoding=”UTF-8” ?>
Syntax (cont.)
Inline Tags:
Adding ‘:’ between tags allows us to add
multiple tags in one single line.
Attributes:
Wrapping attributes is not required, but it does
improve readability. We can wrap attributes
with ‘{}’, ‘()’ and ‘[]’.
ul.alert.alert-danger: li: a href=”/” First link
Outputs:
<ul class=”alert alert-danger”>
<li><a href=”/”>First link</a></li>
</ul>
a href=”/” rel=”nofollow” Link Text
a[href=”/” rel=”nofollow”] Link Text
a(href=”/” rel=”nofollow”) Link Text
a{href=”/” rel=”nofollow”} Link Text
Outputs:
<a href=”/” rel=”nofollow”>Link Text</a>
Syntax (cont.)
Attributes (cont.):
Slim permits us to wrap attributes with ‘*{}’
which allows us to use a Ruby Hash-style
syntax.
Slim allows attribute values to be Ruby code
that outputs a string.
a*{:href => ‘/’, rel: ‘nofollow’} Link Text
Outputs:
<a href=”/” rel=”nofollow”>Link Text</a>
a href=root_path Link Text
Outputs:
<a href=”/”>Link Text</a>
Syntax (cont.)
Text Interpolation:
Slim allows the use of Ruby string interpolation
in attribute values as well as in the text
content.
img src=”/images/example.png” alt=”Welcome
#{user.name}” /
Outputs:
<img src=”/images/example.png” alt=”Welcome Eric
Mulligan” />
p Welcome #{user.name}
Outputs:
<p>Welcome Eric Mulligan</p>
Syntax (cont.)
➢ Outputs:
○ Pretty HTML in Development.
○ Ugly HTML in Production.
○ Valid XHTML.
➢ Sorts attributes by name.
➢ Automatic HTML escaping by default.
➢ Unicode support for element and attribute names.
➢ Support for Embedded Engines such as Ruby,
CoffeeScript, JavaScript, Markdown, etc.
Features
➢ To configure:
○ Create slim.rb in “config/initializers”.
○ Slim::Engine.set_options({...configuration hash…})
○ shortcut: { ‘@’ => { attr: ‘role’ } }:
■ p#example.slim-example@admin Some text
■ Outputs: <p id=”example” class=”slim-example” role=”admin”>Some Text</p>
○ format: :html:
■ Outputs HTML 5 markup instead of the default XHTML.
○ pretty: true:
■ Outputs pretty HTML instead of ugly HTML regardless of the environment.
Features (cont.)
➢ Embedded Ruby (ERB):
○ Ruby code is embedded in HTML markup.
○ Easier to use in projects where web designers have little to no
coding experience.
○ Faster to compile than Slim.
○ Recommended by David Heinemeier Hansson (aka DHH)
(Rails Creator & Basecamp Founder).
Slim vs ERB & HAML
➢ HTML Abstraction Markup Language (HAML):
○ Created by Hampton Catlin (Sass) in 2006.
○ Slim is influenced by HAML.
○ Slight syntax difference between HAML and Slim.
■ HTML/XML elements start with %
● %html, %body, %h1, etc.
■ () used for HTML-style attributes.
● %a(href=”http://google.com”)
Slim vs ERB & HAML (cont.)
Bootstrap Navbar in ERB
Bootstrap Navbar in HAML
Bootstrap Navbar in Slim
➢ Performance:
○ Slim is much faster to compile than HAML.
○ ERB is much faster to compile than Slim & HAML.
Slim vs ERB & HAML (cont.)
Ruby / Rails Perspective
Demo
References:
http://slim-lang.com
http://github.com/slim-lang/slim
http://rubydoc.info/gems/slim/frames
http://sephinrothcn.wordpress.com/2014/04/14/slim-vs-haml-performance-perspective
http://haml.info
Contact Me:
Email: eric.pierre.mulligan@gmail.com
Twitter: @EricPMulligan
Github: https://github.com/EricPMulligan
That’s It!

More Related Content

PPT
Web development basics (Part-3)
Rajat Pratap Singh
 
PPT
Web development basics (Part-1)
Rajat Pratap Singh
 
PPT
Web development basics (Part-2)
Rajat Pratap Singh
 
PPTX
Js syntax
Sireesh K
 
PPT
JSP Part 1
DeeptiJava
 
PPTX
Server Scripting Language -PHP
Deo Shao
 
PPTX
php basics
NIRMAL FELIX
 
PDF
Shootout! template engines on the jvm
NLJUG
 
Web development basics (Part-3)
Rajat Pratap Singh
 
Web development basics (Part-1)
Rajat Pratap Singh
 
Web development basics (Part-2)
Rajat Pratap Singh
 
Js syntax
Sireesh K
 
JSP Part 1
DeeptiJava
 
Server Scripting Language -PHP
Deo Shao
 
php basics
NIRMAL FELIX
 
Shootout! template engines on the jvm
NLJUG
 

What's hot (20)

KEY
Namespace less engine
shaokun
 
PPTX
Javascript 01 (js)
AbhishekMondal42
 
PPT
HTML Introduction
Jainul Musani
 
KEY
php app development 1
barryavery
 
PDF
Build a game with javascript (may 21 atlanta)
Thinkful
 
PPT
JavaScript - Part-1
Jainul Musani
 
PPT
01 basics
Ashwini1593
 
PPT
php basic
zalatarunk
 
PPTX
Java server pages
Apoorv Anand
 
PDF
Client side scripting
Eleonora Ciceri
 
PPTX
Java Server Pages
Shah Nawaz Bhurt
 
PDF
PHP7.1 New Features & Performance
Xinchen Hui
 
PDF
Dev days Szeged 2014: Plugin system in drupal 8
Bram Goffings
 
PPT
JavaScript Introduction
Jainul Musani
 
PPTX
SUGUK Cambridge - Display Templates & JSLink for IT Pros
Paul Hunt
 
PPTX
JavaScript operators
Vivek Kumar
 
PPTX
Client side scripting using Javascript
Bansari Shah
 
PPT
Ph pbasics
Shehrevar Davierwala
 
PPTX
Beanshell scripting in Apache JMeter
NaveenKumar Namachivayam
 
PPTX
Spsbe using js-linkanddisplaytemplates
Paul Hunt
 
Namespace less engine
shaokun
 
Javascript 01 (js)
AbhishekMondal42
 
HTML Introduction
Jainul Musani
 
php app development 1
barryavery
 
Build a game with javascript (may 21 atlanta)
Thinkful
 
JavaScript - Part-1
Jainul Musani
 
01 basics
Ashwini1593
 
php basic
zalatarunk
 
Java server pages
Apoorv Anand
 
Client side scripting
Eleonora Ciceri
 
Java Server Pages
Shah Nawaz Bhurt
 
PHP7.1 New Features & Performance
Xinchen Hui
 
Dev days Szeged 2014: Plugin system in drupal 8
Bram Goffings
 
JavaScript Introduction
Jainul Musani
 
SUGUK Cambridge - Display Templates & JSLink for IT Pros
Paul Hunt
 
JavaScript operators
Vivek Kumar
 
Client side scripting using Javascript
Bansari Shah
 
Beanshell scripting in Apache JMeter
NaveenKumar Namachivayam
 
Spsbe using js-linkanddisplaytemplates
Paul Hunt
 
Ad

Similar to The Skinny on Slim (20)

PDF
Killing the Angle Bracket
jnewmanux
 
PDF
Haml
Ciaran Lee
 
PPT
Richard Pipe 2
Digital Publishing Forum NZ
 
PDF
Haml. New HTML? (RU)
Kirill Zonov
 
KEY
Introduction to HAML
Zohar Arad
 
KEY
Advanced Technology for Web Application Design
Bryce Kerley
 
PPTX
Web technologies: Lesson 2
nhepner
 
PPT
Html For Beginners 2
Sriram Raj
 
PPT
Origins and evolution of HTML and XHTML
Howpk
 
PPTX
Introduction to HAML
Jon Dean
 
PDF
Web development Hackathon
Al Sayed Gamal
 
PPT
Design Tools Html Xhtml
Ahsan Uddin Shan
 
PDF
Architektura html, css i javascript - Jan Kraus
Women in Technology Poland
 
PPTX
Html and Xhtml
Chhom Karath
 
PPTX
web Technolotogies notes lke CSS443.pptx
ssuser46d915
 
PDF
Haml And Sass In 15 Minutes
Patrick Crowley
 
DOCX
List of html tags
Stellamaris Chinwendu
 
PDF
Mojolicious
Marcos Rebelo
 
PDF
Ruby on Rails from the other side of the tracks
infovore
 
PDF
Get Slim!
Simon Courtois
 
Killing the Angle Bracket
jnewmanux
 
Haml. New HTML? (RU)
Kirill Zonov
 
Introduction to HAML
Zohar Arad
 
Advanced Technology for Web Application Design
Bryce Kerley
 
Web technologies: Lesson 2
nhepner
 
Html For Beginners 2
Sriram Raj
 
Origins and evolution of HTML and XHTML
Howpk
 
Introduction to HAML
Jon Dean
 
Web development Hackathon
Al Sayed Gamal
 
Design Tools Html Xhtml
Ahsan Uddin Shan
 
Architektura html, css i javascript - Jan Kraus
Women in Technology Poland
 
Html and Xhtml
Chhom Karath
 
web Technolotogies notes lke CSS443.pptx
ssuser46d915
 
Haml And Sass In 15 Minutes
Patrick Crowley
 
List of html tags
Stellamaris Chinwendu
 
Mojolicious
Marcos Rebelo
 
Ruby on Rails from the other side of the tracks
infovore
 
Get Slim!
Simon Courtois
 
Ad

Recently uploaded (20)

PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Presentation about variables and constant.pptx
safalsingh810
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 

The Skinny on Slim

  • 1. The Skinny On Slim Presentation by Eric Mulligan
  • 2. ➢ What Is Slim? ➢ Why Slim? ➢ Syntax ➢ Features ➢ Slim vs HAML & ERB ➢ Demo Outline
  • 3. ➢ A template engine for Ruby. ➢ Developed by Daniel Mendler in 2010. ➢ Similar to HAML & Jade (JavaScript). ➢ Supports Rails 3 & 4, Sinatra and other Rack-based web frameworks. ➢ Tested on all major Ruby implementations. What Is Slim?
  • 4. ➢ Core syntax is guided by one thought: “What is the minimum required to make this work?” ➢ Allows us to write minimal templates. ➢ Syntax is aesthetically pleasing which makes it fun to write templates. ➢ Designed with performance in mind. ➢ Guarantees well-formed HTML and XML. ➢ Faster to compile than HAML. Why Slim?
  • 5. Installation: From the command line: From a Gemfile: Verbatim Text: ‘|’ tells Slim to copy the line and does no processing. You can even embed HTML and it will simply output it as is. Syntax gem install slim gem ‘slim’ | This is some random text. Outputs: This is some random text. | <p>A paragraph.</p> Outputs: <p>A paragraph</p>
  • 6. Control Code: The ‘-’ denotes control code such as conditionals and loops. ‘end’ is forbidden as blocks are defined by indentation only. Dynamic Content: The ‘=’ outputs the result of the Ruby call and adds the output to the buffer. The ‘==’ is the same as ‘=’, however, all HTML is not escaped which is perfect for ‘yield’ and ‘render’ method calls. - if @users.empty? - @users.each do |user| | I am a user. = javascript_include_tag ‘application’ p = link_to ‘Link’, ‘#’ == yield == render ‘partials/form’, locals: { user: @user } Syntax (cont.)
  • 7. Comments: ‘/’ does not output any markup. ‘/!’, however, outputs HTML comments. ‘/[if IE]’ outputs IE conditional comments. Syntax (cont.) / This line won’t be displayed. /! This line will be displayed as an HTML comment. Outputs: <!-- This line will be displayed as an HTML comment → /[if IE] p Some paragraph. Outputs: <--![if IE]--><p>Some paragraph</p><![endif]-->
  • 8. DOCTYPE: HTML doctypes: XML doctypes: doctype html doctype 5 Outputs: <!DOCTYPE html> doctype 1.1 Outputs: <!DOCTYPE html PUBLIC - “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”> doctype xml Outputs: <?xml version=”1.0” encoding=”UTF-8” ?> Syntax (cont.)
  • 9. Inline Tags: Adding ‘:’ between tags allows us to add multiple tags in one single line. Attributes: Wrapping attributes is not required, but it does improve readability. We can wrap attributes with ‘{}’, ‘()’ and ‘[]’. ul.alert.alert-danger: li: a href=”/” First link Outputs: <ul class=”alert alert-danger”> <li><a href=”/”>First link</a></li> </ul> a href=”/” rel=”nofollow” Link Text a[href=”/” rel=”nofollow”] Link Text a(href=”/” rel=”nofollow”) Link Text a{href=”/” rel=”nofollow”} Link Text Outputs: <a href=”/” rel=”nofollow”>Link Text</a> Syntax (cont.)
  • 10. Attributes (cont.): Slim permits us to wrap attributes with ‘*{}’ which allows us to use a Ruby Hash-style syntax. Slim allows attribute values to be Ruby code that outputs a string. a*{:href => ‘/’, rel: ‘nofollow’} Link Text Outputs: <a href=”/” rel=”nofollow”>Link Text</a> a href=root_path Link Text Outputs: <a href=”/”>Link Text</a> Syntax (cont.)
  • 11. Text Interpolation: Slim allows the use of Ruby string interpolation in attribute values as well as in the text content. img src=”/images/example.png” alt=”Welcome #{user.name}” / Outputs: <img src=”/images/example.png” alt=”Welcome Eric Mulligan” /> p Welcome #{user.name} Outputs: <p>Welcome Eric Mulligan</p> Syntax (cont.)
  • 12. ➢ Outputs: ○ Pretty HTML in Development. ○ Ugly HTML in Production. ○ Valid XHTML. ➢ Sorts attributes by name. ➢ Automatic HTML escaping by default. ➢ Unicode support for element and attribute names. ➢ Support for Embedded Engines such as Ruby, CoffeeScript, JavaScript, Markdown, etc. Features
  • 13. ➢ To configure: ○ Create slim.rb in “config/initializers”. ○ Slim::Engine.set_options({...configuration hash…}) ○ shortcut: { ‘@’ => { attr: ‘role’ } }: ■ p#example.slim-example@admin Some text ■ Outputs: <p id=”example” class=”slim-example” role=”admin”>Some Text</p> ○ format: :html: ■ Outputs HTML 5 markup instead of the default XHTML. ○ pretty: true: ■ Outputs pretty HTML instead of ugly HTML regardless of the environment. Features (cont.)
  • 14. ➢ Embedded Ruby (ERB): ○ Ruby code is embedded in HTML markup. ○ Easier to use in projects where web designers have little to no coding experience. ○ Faster to compile than Slim. ○ Recommended by David Heinemeier Hansson (aka DHH) (Rails Creator & Basecamp Founder). Slim vs ERB & HAML
  • 15. ➢ HTML Abstraction Markup Language (HAML): ○ Created by Hampton Catlin (Sass) in 2006. ○ Slim is influenced by HAML. ○ Slight syntax difference between HAML and Slim. ■ HTML/XML elements start with % ● %html, %body, %h1, etc. ■ () used for HTML-style attributes. ● %a(href=”http://google.com”) Slim vs ERB & HAML (cont.)
  • 19. ➢ Performance: ○ Slim is much faster to compile than HAML. ○ ERB is much faster to compile than Slim & HAML. Slim vs ERB & HAML (cont.)
  • 20. Ruby / Rails Perspective
  • 21. Demo