Copyright (c) 2006 Ezra Zygmuntowicz Merb. Mongrel+Erb Little bitty lightweight ruby app server. For when you really need performance for simple dynamic pages. **Sample APP included** ** Dependencies ** mongrel erubis json or fjson mime-types Install these gems first then you can build the merb gem from svn trunk like so: $ sudo gem install mongrel erubis json mime-types --include-dependencies $ svn co http://svn.devjavu.com/merb $ cd merb $ sudo rake install **Important** The new default filename extensions for templates are as follows html -> .herb js -> .jerb xml -> .xerb You can change the extensions to anything you want in your config file in yourapp/dist/conf/merb.yml. See the default settings in the sample app. First you need to install the dependencies. Merb requires the follwing gems erubis json fjson # will be used if present. requires C extension. # fastthread will be used if present and is reccommended. sudo gem install fastthread --source=http://mongrel.rubyforge.org/ If you have checked out merb trunk from svn you will want to build and install the gem to use merb. Run this command from the root of the merb svn checkout to do that: $ sudo rake install If you installed merb from gems then unpack the gem and grab the sample app $ gem unpack merb now with either the svn or the unpacked gem you can try out the sample app. $ cd merb* $ cd examples/sample_app $ merb You will need the mongrel_upload_progress gem installed to go to /files so use the -f flag to load a config file for mongrel_upload_progress $ merb -f dist/conf/mup.conf then the sample app will be running on port 4000 in the foreground. you can go to a few urls: http://localhost:4000/files/start http://localhost:4000/foo/123/baz/12234345 **FEATURES** *Mongrel handler* built in that parses incoming requests including multipart uploads and post as well as ?query=strings. Puts the params into params and the cookies into cookies when it instantiates your controller class. *RouteMatcher and route compiler* Reads your route definition and compiles a method on the fly that will match the request path against each route and do the right thing. So the following routes: Merb::RouteMatcher.prepare do |r| r.add '/foo/:bar/baz/:id', :controller => 'Test', :action => 'foo' r.add '/:controller/:action/:id' r.add '/bar/:*rest', :controller => 'Test', :action => 'glob' end Will be compiled and defined as a method with this lambda as the body: lambda{|path| case path when Regexp.new('/foo/([^/;.,?]+)/baz/([^/;.,?]+)') @sections[:bar] = $1 @sections[:id] = $2 return {:controller=>"Test", :action=>"foo"}.merge(@sections) when /\A\/([^\/;.,?]+)(?:\/?\Z|\/([^\/;.,?]+)\/?)(?:\/?\Z|\/([^\/;.,?]+)\/?)\Z/ @sections[:controller] = $1 @sections[:action] = $2 || 'index' @sections[:id] = $3 || nil return @sections when Regexp.new('/bar/([^;.,?]+)') @sections[:rest] = $1 return {:controller=>"Test", :action=>"glob"}.merge(@sections) else return {:controller=>'Noroutefound', :action=>'noroute'} end } *Simple Controllers* classes with built in render method and template handling with instance vars available in the views automatically. Merb also supports layouts. It will look for a layout named after your controller class first and then fall back to application.herb if no layout exists named after your controller. You can use render_no_layout or do layout :none right before you render class Test < Merb::Controller def hello # params, headers and cookies are available here. @name = params[:name] render end end