lib/merb/merb_router.rb in merb-0.0.2 vs lib/merb/merb_router.rb in merb-0.0.3

- old
+ new

@@ -1,7 +1,32 @@ module Merb + # Merb::RouteMatcher is the request routing mapper for the merb framework. + # You can define placeholder parts of the url with the :smbol notation. + # so r.add '/foo/:bar/baz/:id', :class => 'Bar', :method => 'foo' + # will match against a request to /foo/123/baz/456. It will then + # use the class Bar as your merb controller and call the foo method on it. + # the foo method will recieve a hash with {:bar => '123', :id => '456'} + # as the content. So the :placeholders sections of your routes become + # a hash of arguments to your controller methods. These two methods map + # the default /controller/action and /controller/action/id urls you will + # use so you will want these two by default, in this order: + # r.add '/:class/:method/:id', {} + # r.add '/:class/:method', {} + # + # This is what a route prepare definition looks like. I have added + # code that will spit out the compiled routing lambda so you can see + # what is generated: + # + # puts "Compiling routes: \n" + # Merb::RouteMatcher.prepare do |r| + # r.add '/foo/:bar/baz/:id', :class => 'Test', :method => 'foo' + # r.add '/:class/:method/:id', {} + # r.add '/:class/:method', {} + # end + # m = Merb::RouteMatcher.new + # puts m.compiled_statement class RouteMatcher attr_accessor :sections SECTION_REGEX = /(?::([a-z]+))/ unless defined?SECTION_REGEX @@ -53,35 +78,5 @@ end end end - -=begin -if __FILE__ == $0 - Merb::RouteMatcher.prepare do |r| - r.add '/foo/:bar/baz/:id', :class => 'Test', :method => 'foo' - r.add '/hey/:there/you/:guys', :class => 'Test', :method => 'hello' - r.add '/these/:routes/are/:sweet', :class => 'Upload', :method => 'start' - r.add '/h/:a/b/:c/d/:f/g/:id', :class => 'Test' - r.add '/:class/:method/:id', {} - r.add '/:class/:method', {} - end - - routes = Merb::RouteMatcher.new - puts routes.compiled_statement - p routes.route_request( "/foo/234/baz/dsdsd") - routes = Merb::RouteMatcher.new - p routes.route_request( "/hey/jon/you/girls") - routes = Merb::RouteMatcher.new - p routes.route_request( "/upload/test/12") - routes = Merb::RouteMatcher.new - p routes.route_request( "/these/234/are/yup") - routes = Merb::RouteMatcher.new - p routes.route_request( '/h/12/b/red/d/blue/g/12') - routes = Merb::RouteMatcher.new - p routes.route_request( '/hdsfvsdfsdfdsf') - - p routes.routes - -end -=end