diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-27 15:56:16 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-27 15:56:16 -0300 |
commit | d395391e1dfae4531671fbb09911e6b9418474ba (patch) | |
tree | 65d679e11c15de32c18a4303d6dcb9f88f2a0925 /actionpack/lib | |
parent | 286f47f3b034db4550110b9a0f9ff48dda29e807 (diff) | |
parent | c10396b1426fcddea35d88fe865846b8aaab5de4 (diff) | |
download | rails-d395391e1dfae4531671fbb09911e6b9418474ba.tar.gz rails-d395391e1dfae4531671fbb09911e6b9418474ba.tar.bz2 rails-d395391e1dfae4531671fbb09911e6b9418474ba.zip |
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/lib')
16 files changed, 75 insertions, 43 deletions
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index b93e6ce634..f5b1c9e4d1 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -89,7 +89,6 @@ module AbstractController end process_action(action_name) - self end private diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index a8bd2b80e1..ef66b24dd6 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -145,6 +145,9 @@ module AbstractController # This is a little bit messy. We need to explicitly handle partial # layouts here since the core lookup logic is in the view, but # we need to determine the layout based on the controller + # + # TODO: An easier way to handle this would probably be to override + # render_template if layout layout = _layout_for_option(layout, options[:_template].details) response = layout.render(view_context, options[:locals] || {}) { response } diff --git a/actionpack/lib/abstract_controller/logger.rb b/actionpack/lib/abstract_controller/logger.rb index fd33bd2ddd..1b879b963b 100644 --- a/actionpack/lib/abstract_controller/logger.rb +++ b/actionpack/lib/abstract_controller/logger.rb @@ -29,7 +29,7 @@ module AbstractController # Override process_action in the AbstractController::Base # to log details about the method. def process_action(action) - super + retval = super if logger log = DelayedLog.new do @@ -40,6 +40,8 @@ module AbstractController logger.info(log) end + + retval end private diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 37ff618edd..d27a867efe 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -3,6 +3,7 @@ module ActionController autoload :ConditionalGet, "action_controller/metal/conditional_get" autoload :HideActions, "action_controller/metal/hide_actions" autoload :Metal, "action_controller/metal" + autoload :Middleware, "action_controller/middleware" autoload :Layouts, "action_controller/metal/layouts" autoload :RackConvenience, "action_controller/metal/rack_convenience" autoload :Rails2Compatibility, "action_controller/metal/compatibility" diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index aad9570237..51fbba3661 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -88,23 +88,6 @@ module ActionController end end - class ActionMiddleware - def initialize(controller, action) - @controller, @action = controller, action - end - - def call(env) - controller = @controller.new - controller.app = @app - controller.call(@action, env) - end - - def new(app) - @app = app - self - end - end - # Return a rack endpoint for the given action. Memoize the endpoint, so # multiple calls into MyController.action will return the same object # for the same action. @@ -118,10 +101,5 @@ module ActionController @actions ||= {} @actions[name.to_s] ||= ActionEndpoint.new(self, name) end - - def self.middleware(name) - @middlewares ||= {} - @middlewares[name.to_s] ||= ActionMiddleware.new(self, name) - end end end diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 2b62a1be85..0f35a7c040 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -115,7 +115,7 @@ module ActionController end def authenticate_with_http_basic(&login_procedure) - HttpAuthentication::Basic.authenticate(self, &login_procedure) + HttpAuthentication::Basic.authenticate(request, &login_procedure) end def request_http_basic_authentication(realm = "Application") @@ -123,9 +123,9 @@ module ActionController end end - def authenticate(controller, &login_procedure) - unless authorization(controller.request).blank? - login_procedure.call(*user_name_and_password(controller.request)) + def authenticate(request, &login_procedure) + unless authorization(request).blank? + login_procedure.call(*user_name_and_password(request)) end end @@ -150,7 +150,8 @@ module ActionController def authentication_request(controller, realm) controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}") - controller.__send__ :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized + controller.response_body = "HTTP Basic: Access denied.\n" + controller.status = 401 end end @@ -164,7 +165,7 @@ module ActionController # Authenticate with HTTP Digest, returns true or false def authenticate_with_http_digest(realm = "Application", &password_procedure) - HttpAuthentication::Digest.authenticate(self, realm, &password_procedure) + HttpAuthentication::Digest.authenticate(request, realm, &password_procedure) end # Render output including the HTTP Digest authentication header @@ -174,8 +175,8 @@ module ActionController end # Returns false on a valid response, true otherwise - def authenticate(controller, realm, &password_procedure) - authorization(controller.request) && validate_digest_response(controller.request, realm, &password_procedure) + def authenticate(request, realm, &password_procedure) + authorization(request) && validate_digest_response(request, realm, &password_procedure) end def authorization(request) @@ -243,7 +244,8 @@ module ActionController def authentication_request(controller, realm, message = nil) message ||= "HTTP Digest: Access denied.\n" authentication_header(controller, realm) - controller.__send__ :render, :text => message, :status => :unauthorized + controller.response_body = message + controller.status = 401 end # Uses an MD5 digest based on time to generate a value to be used only once. diff --git a/actionpack/lib/action_controller/metal/redirector.rb b/actionpack/lib/action_controller/metal/redirector.rb index 20060b001f..f79fd54acd 100644 --- a/actionpack/lib/action_controller/metal/redirector.rb +++ b/actionpack/lib/action_controller/metal/redirector.rb @@ -8,6 +8,9 @@ module ActionController end module Redirector + extend ActiveSupport::Concern + include AbstractController::Logger + def redirect_to(url, status) #:doc: raise AbstractController::DoubleRenderError if response_body logger.info("Redirected to #{url}") if logger && logger.info? diff --git a/actionpack/lib/action_controller/middleware.rb b/actionpack/lib/action_controller/middleware.rb new file mode 100644 index 0000000000..fac0ed2645 --- /dev/null +++ b/actionpack/lib/action_controller/middleware.rb @@ -0,0 +1,38 @@ +module ActionController + class Middleware < Metal + class ActionMiddleware + def initialize(controller) + @controller = controller + end + + def call(env) + controller = @controller.allocate + controller.send(:initialize) + controller.app = @app + controller._call(env) + end + + def app=(app) + @app = app + end + end + + def self.new(app) + middleware = ActionMiddleware.new(self) + middleware.app = app + middleware + end + + def _call(env) + @_env = env + @_request = ActionDispatch::Request.new(env) + @_response = ActionDispatch::Response.new + @_response.request = @_request + process(:index) + end + + def index + call(env) + end + end +end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/routing/generation/url_rewriter.rb b/actionpack/lib/action_controller/routing/generation/url_rewriter.rb index 9717582b5e..52b66c9303 100644 --- a/actionpack/lib/action_controller/routing/generation/url_rewriter.rb +++ b/actionpack/lib/action_controller/routing/generation/url_rewriter.rb @@ -172,7 +172,7 @@ module ActionController path = rewrite_path(options) rewritten_url << ActionController::Base.relative_url_root.to_s unless options[:skip_relative_url_root] rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path) - rewritten_url << "##{options[:anchor]}" if options[:anchor] + rewritten_url << "##{CGI.escape(options[:anchor].to_param.to_s)}" if options[:anchor] rewritten_url end diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index 6bc7d60d76..4185b803c5 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -249,6 +249,7 @@ module ActionController #:nodoc: temporary_routes = ActionController::Routing::RouteSet.new ActionController::Routing.module_eval { const_set :Routes, temporary_routes } + ActionController::Dispatcher.router = temporary_routes yield temporary_routes ensure @@ -256,6 +257,7 @@ module ActionController #:nodoc: ActionController::Routing.module_eval { remove_const :Routes } end ActionController::Routing.const_set(:Routes, real_routes) if real_routes + ActionController::Dispatcher.router = ActionController::Routing::Routes end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 547a2d2062..9cfd6956d0 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/hash/keys" + module ActionDispatch module Session # This cookie-based session store is the Rails default. Sessions typically diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index ade2d6f05e..4f71ea6165 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -27,10 +27,10 @@ module ActionDispatch end def klass - if @klass.respond_to?(:call) - @klass.call - elsif @klass.is_a?(Class) + if @klass.respond_to?(:new) @klass + elsif @klass.respond_to?(:call) + @klass.call else @klass.to_s.constantize end diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 4620a52272..3db5202e7d 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -571,7 +571,8 @@ module ActionView option_tags = "<option value=\"\">#{options[:include_blank] if options[:include_blank].kind_of?(String)}</option>\n" + option_tags end if value.blank? && options[:prompt] - ("<option value=\"\">#{options[:prompt].kind_of?(String) ? options[:prompt] : 'Please select'}</option>\n") + option_tags + prompt = options[:prompt].kind_of?(String) ? options[:prompt] : I18n.translate('support.select.prompt', :default => 'Please select') + "<option value=\"\">#{prompt}</option>\n" + option_tags else option_tags end diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index afe35691bc..c82cd07ec2 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -108,3 +108,7 @@ # The variable :count is also available body: "There were problems with the following fields:" + support: + select: + # default value for :prompt => true in FormOptionsHelper + prompt: "Please select"
\ No newline at end of file diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index 4001757a9b..5524a3219a 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -34,7 +34,6 @@ module ActionView #:nodoc: end def find(path, details = {}, prefix = nil, partial = false) - # template_path = path.sub(/^\//, '') template_path = path each do |load_path| @@ -43,8 +42,6 @@ module ActionView #:nodoc: end end - # TODO: Have a fallback absolute path? - extension = details[:formats] || [] raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path} - #{details.inspect} - partial: #{!!partial}") end diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index fe657166d5..0b4c62d4d0 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -4,7 +4,7 @@ require "action_view/template/template" module ActionView # Abstract superclass class Resolver - def initialize(options) + def initialize(options = {}) @cache = options[:cache] @cached = {} end |