Top Banner
Sinatra Ryan Farnell (@criscokid)
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Sinatra

SinatraRyan Farnell (@criscokid)

Page 2: Sinatra

What is Sinatra?

Page 3: Sinatra

Micro Web Framework

• Built on top of Rack

• Uses RESTful thinking

• URL’s are king

Page 4: Sinatra

Features

• Routing to code blocks

• Static Files

• Views/Layouts

• Filters

• Helpers

Page 5: Sinatra

Routing To Blocks

• Routes made up of 3 basic parts

• HTTP Verb

• Match Expression

• Code block

Page 6: Sinatra

HTTP Verbs

POST

DELETEPUT

GET

Page 7: Sinatra

Demo

Page 8: Sinatra

Serving Public Files

• If no matching URL was found, Sinatra checks the public folder

• Public folder can be changed by setting :public

set :public,'path/to/file/static'

Page 9: Sinatra

Views• Views are mixes of code and markup

• Sinatra works with ERB, HAML, and Builder by default

• Views are kept in a folder at the root of the site called “views”

• View folder can be changed by setting :views

set :views,,'path/to/file/static'

Page 10: Sinatra

Layout

• Layouts are like templates for all your pages.

• By default looks for a file called “layout” in views with the same extension as the view you are rendering.

• Default name can be overridden.

Page 11: Sinatra

Demo

Page 12: Sinatra

Filters

• Filters run before all routes.

• They can modify the Request and Response object.

• Any instance variable created in the before filter is available in the route.

Page 13: Sinatra

Helpers

• Small methods that you find useful.

• Available within the route and within the views.

Page 14: Sinatra

Demo

Page 15: Sinatra

Example Apps

Page 16: Sinatra

Git-Wikihttp://atonie.org/2008/02/git-wiki

Page 17: Sinatra

Rif-Grafhttp://rifgraf.heroku.com/

Page 18: Sinatra

Github-Serviceshttp://github.com/pjhyett/github-services/tree/master

Page 19: Sinatra

Deployment

• Any server compatible with Rack

• Ruby Servers

• Mongrel

• Thin

• Webrick

• Apache running mod_rack (Phusion Passenger)

• FastCGI Server

• Apache

• Lighttpd

Page 20: Sinatra

http://www.sinatrarb.com/

Page 21: Sinatra

Q&A