lib/nitro/dispatcher.rb in nitro-0.29.0 vs lib/nitro/dispatcher.rb in nitro-0.30.0

- old
+ new

@@ -72,18 +72,18 @@ mixin_auto_helpers(klass) # Customize the class for mounting at the given path. #-- + # gmosx, TODO: path should include trailing '/' # gmosx, TODO: should actually create an instance, thus # allowing mounting the same controller to multiple # paths, plus simplifying the code. This instance will # be dup-ed for each request. #++ klass.mount_at(path) - klass.mounted(path) if klass.respond_to?(:mounted) end (@controllers ||= {}).update(controllers) @@ -110,20 +110,27 @@ end end # Update the routes. Typically called after a new # Controller is mounted. + # + # === Example of routing through annotations + # + # def view_user + # "params: #{request[:id]} and #{request[:mode]}" + # end + # ann :view_user, :route => [ /user_(\d*)_(*?)\.html/, :id, :mode ] def update_routes - @routes = [] + init_routes() @controllers.each do |base, c| base = '' if base == '/' for m in c.action_methods m = m.to_sym if route = c.ann(m).route and (!route.nil?) - add_route(route.first, c, m, route.last) + add_route(route.first, :controller => c, :action => m, :params => route.last) end end end end @@ -154,11 +161,12 @@ def dispatch(path, context = nil) # Try if the router can directly decode the path. klass, action, params = decode_route(path) if klass - context.params.update(params) - return klass, "#{action}_action", controller.ann.self.mount_point + context.params.update(params) if params + # gmosx, FIXME/OPTIMIZE: no annotation for mount point!! + return klass, "#{action}_action", klass.mount_path end parts = path.split('/') parts.shift # get rid of the leading '/'.