Small Ruby Webstack

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    9 lines of code and it works!

    So how much code are we talking about for Ruby and Radiant
    Our small server is not visible
    Radiant’s core => 174908 loc (usually extended with plugins and own code)
    Rails’s core => 131990 loc

    Rack, This is what almost all Ruby based web frameworks build on
    Basically it translates http to ruby

    Rack, This is what almost all Ruby based web frameworks build on
    Basically it translates http to ruby

    Even merb
    Default Merb
    46595 loc

    Apache + passenger, mongrel, thin, webrick

    But there is still an other player out there...

    But there is still an other player out there...

    But there is still an other player out there...

    6 lines of code (and a Rack compatible server) and we are off

    This is Rails’ Rack stack
    Each class in use stack is called Middleware

    This is a piece of middelware, that doesn’t do much

    Rack::Lock executes the call in a synchronize block (Mutex)
    ActionController::Failsafe will render 500.html if it catches an exception
    Rails::Rack::Metal is basically a wrapper around middleware for ease of use in a rails app
    ...
    Your own... insert google analytic tags, filter out bad words...

    again 6 lines of code (and a Rack compatible server) and we are off

    Each page is defined by it’s
    - verb (get, post, put, delete)
    - URI, supporting parameters, wildcards and regex
    - And it should (usually) respond

    Rendering templates
    - erb + haml + builder from files, inline, or defined template methods
    - With layout files!

    Rendering templates
    - erb + haml + builder from files, inline, or defined template methods
    - With layout files!

    Before Filters!
    Passing allows for better structured code
    404’s
    and error handeling

    Rack as a stack
    Sinatra for non-data driven apps (isdemax.be, design prototyping)

    Favorites, Groups & Events

    Small Ruby Webstack - Presentation Transcript

    1. Small ruby web stacks When Rails is just to big
    2. Bert Goethals
    3. Small ruby web stacks When Rails is just to big
    4. The scale of our frameworks
    5. How much does it take to have a working ruby served web page?
    6. require 'socket'   server = TCPServer.new('127.0.0.1', 8080)   loop do   session = server.accept   request = session.gets   session.print "HTTP/1.1 200/OKrnServer: MakorsharnContent-type: text/ plainrnn"   session.write "Hello world"   session.close end
    7. Rails Radiant
    8. • The base of Rack (almost) all ruby web apps • 8439 lines of code
    9. • Rails, great The base of Rack development (almost) all ruby platform web apps • 131990 lines code 8439 lines of of code
    10. Merb Rails Radiant
    11. And we still need a webserver
    12. Radiant Rails Merb
    13. Sinatra Rack
    14. Sinatra Rack
    15. Rack
    16. class HelloWorld   def call(env)     [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]   end end   run HelloWorld.new
    17. Use a Rack to Stack
    18. use Rack::Lock use ActionController::Failsafe use ActionController::Session::CookieStore, , {:secret=>"<secret>", :session_key=>"_<app>_session"} use Rails::Rack::Metal use ActionController::RewindableInput use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::QueryCache run ActionController::Dispatcher.new
    19. class Exaple   def initialize(app)     @app = app   end     def call(env)     # edit environment     status, headers, body = @app.call(env)     # edit response     return status, headers, body   end end
    20. use Rack::Lock use ActionController::Failsafe use ActionController::Session::CookieStore, , {:secret=>"<secret>", :session_key=>"_<app>_session"} use Rails::Rack::Metal use ActionController::RewindableInput use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActiveRecord::QueryCache run ActionController::Dispatcher.new
    21. Don’t use Rack solo. ‘cause it don’t knows pages
    22. Sinatra knows pages
    23. require 'rubygems' require 'sinatra'   get '/' do   "Hello world!" end   run Sinatra::Application
    24. verb 'uri_with/:params/and/*' do   # your logic logic   "Your response" end
    25. There is more
    26. get '/' do Templates   erb :index end get '/haml/:title' do   haml '%h1 #{params[:title]}' end get '/builder' do   builder :index end get '/css/screen.css' do content_type 'text/css', :charset => 'utf-8'   sass :screen end
    27. Helpers helpers do   def pirate(name)     "#{name} Arrh!"   end end   get '/:name' do   pirate(params[:name]) end
    28. before do   request.path_info = '/foo/bar/baz' if request.path_info = '/foo/baz/bar' end   get '/guess/:who' do   pass unless params[:who] == 'Pirate'   "You got me!" end   get '/guess/*' do   "You missed!" end   not_found do   'This is nowhere to be found' end   error do   'Sorry there was a nasty error' end
    29. Ik zoek een collega! Shameless Plug
    30. Conclusion and questions?

    + Bert GoethalsBert Goethals, 1 month ago

    custom

    84 views, 0 favs, 0 embeds more stats

    Short presentation showing Rack and Sinatra, for wh more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 84
      • 84 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories