lib/nitro/dispatcher.rb in nitro-0.23.0 vs lib/nitro/dispatcher.rb in nitro-0.24.0
- old
+ new
@@ -1,6 +1,6 @@
-require 'nano/object/singleton_class'
+require 'nano/kernel/singleton'
require 'nitro/controller'
require 'nitro/routing'
require 'nitro/mixin/helper'
@@ -49,11 +49,11 @@
@template_root = @public_root
if controllers and controllers.is_a?(Class) and controllers.ancestors.include?(Controller)
controllers = { '/' => controllers }
else
- controllers ||= { '/' => SimpleController }
+ controllers ||= { '/' => Controller }
end
mount(controllers)
end
@@ -88,17 +88,21 @@
auto_mixin(c)
# Perform mount-time initialization of the controller.
if c.respond_to? :mounted
- c.mounted
+ c.mounted(path)
end
# Try to setup a template_root if none is defined:
unless c.template_root
- c.template_root = "#{Template.root}#{path}".gsub(/\/$/, '')
+ c.module_eval %{
+ def self.template_root
+ "#{Template.root}#{path}".gsub(/\\/$/, '')
+ end
+ }
end
end
(@controllers ||= {}).update(controllers)
@@ -128,15 +132,21 @@
# Update the routes. Typically called after a new
# Controller is mounted.
def update_routes
@routes = []
+
@controllers.each do |base, c|
base = '' if base == '/'
- c.action_metadata.each do |action, meta|
- if route = meta[:route]
- @routes << [route, "#{base}/#{action}", *meta.params.keys]
+ for m in c.action_methods
+ if route = c.ann(:m).route and (!route.nil?)
+ unless c.ann(:m).params.nil?
+ keys = c.ann(:m).params.keys
+ else
+ keys = []
+ end
+ @routes << [route, "#{base}/#{action}", *keys]
end
end
end
end
@@ -165,10 +175,10 @@
def controller_class_for(key)
klass = @controllers[key]
if klass and Compiler.reload
- klass.instance_methods.grep(/(action$)|(template$)/).each do |m|
+ klass.instance_methods.grep(/(_action$)|(_template$)/).each do |m|
klass.send(:remove_method, m) rescue nil
end
end
return klass