lib/usher/interface/rails23.rb in usher-0.6.7 vs lib/usher/interface/rails23.rb in usher-0.6.8
- old
+ new
@@ -7,14 +7,15 @@
def named_routes
@router.named_routes
end
def add_named_route(name, route, options = {})
- @router.add_route(route, options).name(name)
+ add_route(route, options).name(name)
end
def add_route(path, options = {})
+ path.gsub!(/(\..*?(?!\)))$/, '(\1)')
if !@controller_action_route_added && path =~ %r{^/?:controller/:action/:id$}
add_route('/:controller/:action', options.dup)
@controller_action_route_added = true
end
@@ -64,18 +65,18 @@
app.call(env).to_a
end
def recognize(request)
response = @router.recognize(request)
+ request.path_parameters.merge!(response.destination)
request.path_parameters.merge!(response.params_as_hash)
"#{request.path_parameters[:controller].camelize}Controller".constantize
end
def reset!(options={})
options[:generator] = options[:generator] || Usher::Util::Generators::URL.new
options[:request_methods] = options[:request_methods] || [:protocol, :domain, :port, :query_string, :remote_ip, :user_agent, :referer, :method, :subdomains]
-
@router = Usher.new(options)
@configuration_files = []
@module ||= Module.new
@controller_route_added = false
@controller_action_route_added = false
@@ -91,14 +92,23 @@
#*_url and hash_for_*_url
Array(destinations).each do |d| d.module_eval { include Helpers }
@router.named_routes.keys.each do |name|
@module.module_eval <<-end_eval # We use module_eval to avoid leaks
def #{name}_url(options = {})
- ActionController::Routing::UsherRoutes.generate(options, {}, :generate, :#{name})
+ ActionController::Routing::Routes.generate(options, {}, :generate, :#{name})
end
+ def #{name}_path(options = {})
+ ActionController::Routing::Routes.generate(options, {}, :generate, :#{name})
+ end
end_eval
end
d.__send__(:include, @module)
+ @router.named_routes.instance_eval "
+ def helpers
+ { }
+ end
+ "
+ @router.named_routes.helpers.__send__(:extend, @module)
end
end
def generate(options, recall = {}, method = :generate, route_name = nil)
route = if(route_name)