Sinatra

2,746 views
2,611 views

Published on

Introduction to Sinatra @FOSDEM 2009

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,746
On SlideShare
0
From Embeds
0
Number of Embeds
41
Actions
Shares
0
Downloads
27
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Sinatra

  1. Introduction to Sinatra
  2. About • Koen Van der Auwera • Co-founder 10to1 (http://10to1.be) • @atog • http://atog.be
  3. Sinatra Sinatra is a Domain Specific Language(DSL) for quickly creating web-applications in ruby. It keeps a minimal feature set, leaving the developer to use the tools that best suit them and their application.
  4. where to start sudo gem install sinatra
  5. Rack Rack provides an minimal interface between webservers supporting Ruby and Ruby frameworks.
  6. require “rubygems” require “sinatra” ruby yourapp.rb Sinatra will look for any Rack compatible server to run the app in.
  7. http://localhost:4567
  8. not_found do “whoops-a-daisy” end get “/” do “Hello FOSDEM!” end
  9. get “/” do erb :index end __END__ @@ index <h1>Hello FOSDEM</h1> ...or you can use a “views” folder
  10. Familiar Rails Stuff • Routing • params • before filter • helper methods • layout
  11. Routing “/:one/:two/:three” {quot;twoquot;=>quot;bquot;, quot;threequot;=>quot;cquot;, quot;onequot;=>quot;aquot;} “/*/alot/*” {quot;splatquot;=>[quot;aquot;, quot;cquot;]}
  12. before, helpers before do #whatever you want end helper do #all you helper methods end
  13. Layout Pretty much equals application.html.erb in Rails Provide your html and use <%= yield %>
  14. Public Use a “public” folder to store your stylesheets, javascript files and images
  15. Tests? Sure. require 'sinatra/test/unit class TestBla < Test::Unit::TestCase configure do set :views => File.join(File.dirname(__FILE__), quot;..quot;, quot;viewsquot;)) end def test_home get quot;/quot; assert_equal 200, @response.status assert @response.body.length > 0 end def test_submit post quot;/submitquot;, {:q => quot;fooquot; } assert_equal 302, @response.status end end
  16. Deployment Apache + Passenger config.ru + public require “yourapp” set :environment, :production run Sinatra::Application
  17. Sinatra in action Go.

×