TeX and CSS tweaks.
Sync with latest Instiki Trunk (Updates Rails to 1.2.2)
This commit is contained in:
parent
0ac586ee25
commit
c358389f25
443 changed files with 24218 additions and 9823 deletions
78
vendor/rails/railties/lib/dispatcher.rb
vendored
78
vendor/rails/railties/lib/dispatcher.rb
vendored
|
@ -1,5 +1,5 @@
|
|||
#--
|
||||
# Copyright (c) 2004 David Heinemeier Hansson
|
||||
# Copyright (c) 2004-2006 David Heinemeier Hansson
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
|
@ -25,6 +25,7 @@
|
|||
# to the appropriate controller and action. It also takes care of resetting
|
||||
# the environment (when Dependencies.load? is true) after each request.
|
||||
class Dispatcher
|
||||
|
||||
class << self
|
||||
|
||||
# Dispatch the given CGI request, using the given session options, and
|
||||
|
@ -32,14 +33,18 @@ class Dispatcher
|
|||
# own CGI object be sure to handle the exceptions it raises on multipart
|
||||
# requests (EOFError and ArgumentError).
|
||||
def dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
|
||||
controller = nil
|
||||
if cgi ||= new_cgi(output)
|
||||
request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
|
||||
prepare_application
|
||||
ActionController::Routing::Routes.recognize!(request).process(request, response).out(output)
|
||||
controller = ActionController::Routing::Routes.recognize(request)
|
||||
controller.process(request, response).out(output)
|
||||
end
|
||||
rescue Object => exception
|
||||
rescue Exception => exception # errors from CGI dispatch
|
||||
failsafe_response(output, '500 Internal Server Error', exception) do
|
||||
ActionController::Base.process_with_exception(request, response, exception).out(output)
|
||||
controller ||= ApplicationController rescue LoadError nil
|
||||
controller ||= ActionController::Base
|
||||
controller.process_with_exception(request, response, exception).out(output)
|
||||
end
|
||||
ensure
|
||||
# Do not give a failsafe response here.
|
||||
|
@ -50,12 +55,44 @@ class Dispatcher
|
|||
# mailers, and so forth. This allows them to be loaded again without having
|
||||
# to restart the server (WEBrick, FastCGI, etc.).
|
||||
def reset_application!
|
||||
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
|
||||
|
||||
Dependencies.clear
|
||||
ActiveRecord::Base.reset_subclasses
|
||||
Class.remove_class(*Reloadable.reloadable_classes)
|
||||
ActiveSupport::Deprecation.silence do # TODO: Remove after 1.2
|
||||
Class.remove_class(*Reloadable.reloadable_classes)
|
||||
end
|
||||
|
||||
ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
|
||||
end
|
||||
|
||||
# Add a preparation callback. Preparation callbacks are run before every
|
||||
# request in development mode, and before the first request in production
|
||||
# mode.
|
||||
#
|
||||
# An optional identifier may be supplied for the callback. If provided,
|
||||
# to_prepare may be called again with the same identifier to replace the
|
||||
# existing callback. Passing an identifier is a suggested practice if the
|
||||
# code adding a preparation block may be reloaded.
|
||||
def to_prepare(identifier = nil, &block)
|
||||
unless identifier.nil?
|
||||
callback = preparation_callbacks.detect { |ident, _| ident == identifier }
|
||||
|
||||
if callback # Already registered: update the existing callback
|
||||
callback[-1] = block
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
preparation_callbacks << [identifier, block]
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_accessor :preparation_callbacks, :preparation_callbacks_run
|
||||
alias_method :preparation_callbacks_run?, :preparation_callbacks_run
|
||||
|
||||
# CGI.new plus exception handling. CGI#read_multipart raises EOFError
|
||||
# if body.empty? or body.size != Content-Length and raises ArgumentError
|
||||
# if Content-Length is non-integer.
|
||||
|
@ -64,10 +101,15 @@ class Dispatcher
|
|||
end
|
||||
|
||||
def prepare_application
|
||||
ActionController::Routing::Routes.reload if Dependencies.load?
|
||||
if Dependencies.load?
|
||||
ActionController::Routing::Routes.reload
|
||||
self.preparation_callbacks_run = false
|
||||
end
|
||||
|
||||
prepare_breakpoint
|
||||
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
|
||||
ActiveRecord::Base.verify_active_connections!
|
||||
require_dependency 'application' unless Object.const_defined?(:ApplicationController)
|
||||
ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord)
|
||||
run_preparation_callbacks
|
||||
end
|
||||
|
||||
def reset_after_dispatch
|
||||
|
@ -84,10 +126,16 @@ class Dispatcher
|
|||
nil
|
||||
end
|
||||
|
||||
def run_preparation_callbacks
|
||||
return if preparation_callbacks_run?
|
||||
preparation_callbacks.each { |_, callback| callback.call }
|
||||
self.preparation_callbacks_run = true
|
||||
end
|
||||
|
||||
# If the block raises, send status code as a last-ditch response.
|
||||
def failsafe_response(output, status, exception = nil)
|
||||
yield
|
||||
rescue Object
|
||||
rescue Exception # errors from executed block
|
||||
begin
|
||||
output.write "Status: #{status}\r\n"
|
||||
|
||||
|
@ -110,8 +158,16 @@ class Dispatcher
|
|||
output.write(message)
|
||||
end
|
||||
end
|
||||
rescue Object
|
||||
rescue Exception # Logger or IO errors
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.preparation_callbacks = []
|
||||
self.preparation_callbacks_run = false
|
||||
|
||||
end
|
||||
|
||||
Dispatcher.to_prepare :activerecord_instantiate_observers do
|
||||
ActiveRecord::Base.instantiate_observers
|
||||
end if defined?(ActiveRecord)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue