Micro Web Framework
• Built on top of Rack
• Uses RESTful thinking
• URL’s are king
Features
• Routing to code blocks
• Static Files
• Views/Layouts
• Filters
• Helpers
Routing To Blocks
• Routes made up of 3 basic parts
• HTTP Verb
• Match Expression
• Code block
HTTP Verbs
POST GET
PUT DELETE
Demo
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'
Viewsmarkup
• Views are mixes of code and
• 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'
Layout
• Layouts are like templates for all your pages.
• Bydefault looks for a file called “layout” in
views with the same extension as the view you
are rendering.
• Default name can be overridden.
Demo
Filters
• Filters run before all routes.
• Theycan modify the Request and Response
object.
• Any instance variable created in the before filter
is available in the route.
Helpers
• Small methods that you find useful.
• Available within the route and within the views.
0 comments
Post a comment