From cbb0724f0d0d51a8097ba707517dcf1d09b07a31 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 26 May 2009 12:06:48 -0700 Subject: In new base Rails2Compatibility, move @template assignment to right before the first action is processed. --- actionpack/lib/action_controller/new_base/compatibility.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb index 4245ba982b..646e69843e 100644 --- a/actionpack/lib/action_controller/new_base/compatibility.rb +++ b/actionpack/lib/action_controller/new_base/compatibility.rb @@ -69,7 +69,12 @@ module ActionController # TODO: Remove this after we flip def template - _action_view + @template ||= _action_view + end + + def process_action(*) + template + super end module ClassMethods @@ -83,11 +88,6 @@ module ActionController @@cache_store = ActiveSupport::Cache.lookup_store(store_option) end end - - def initialize(*) - super - @template = _action_view - end def render_to_body(options) if options.is_a?(Hash) && options.key?(:template) -- cgit v1.2.3 From 09907d1b933d202333280fb2efc079f8bf969e16 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 26 May 2009 12:14:50 -0700 Subject: Get controller/view_paths_test.rb to pass on new base --- actionpack/lib/action_controller/abstract/renderer.rb | 4 ++++ actionpack/lib/action_controller/new_base/compatibility.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index d7c68549e1..7f7ec78054 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -86,6 +86,10 @@ module AbstractController self.view_paths << path end + def prepend_view_path(path) + self.view_paths.unshift(path) + end + def view_paths self._view_paths end diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb index 646e69843e..fddfadcbf2 100644 --- a/actionpack/lib/action_controller/new_base/compatibility.rb +++ b/actionpack/lib/action_controller/new_base/compatibility.rb @@ -116,5 +116,18 @@ module ActionController def performed? response_body end + + # ==== Request only view path switching ==== + def append_view_path(path) + view_paths.push(*path) + end + + def prepend_view_path(path) + view_paths.unshift(*path) + end + + def view_paths + _action_view.view_paths + end end end -- cgit v1.2.3 From 7dd094329eee01cf9d18e4141226357eb8f75c76 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 26 May 2009 13:40:58 -0700 Subject: Add html-scanner to the new base set of autoloads --- actionpack/lib/action_controller/new_base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb index 276be50614..e9e89769f1 100644 --- a/actionpack/lib/action_controller/new_base.rb +++ b/actionpack/lib/action_controller/new_base.rb @@ -40,5 +40,7 @@ module ActionController require 'action_controller/routing' end +autoload :HTML, 'action_controller/vendor/html-scanner' + require 'action_dispatch' require 'action_view' -- cgit v1.2.3 From a3ca5638d365113028610141f025839bb3ed738b Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 26 May 2009 14:13:35 -0700 Subject: Get controller/test_test.rb to pass on new base --- actionpack/lib/action_controller/testing/process2.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/testing/process2.rb b/actionpack/lib/action_controller/testing/process2.rb index 677dd41781..1c6fd2d80a 100644 --- a/actionpack/lib/action_controller/testing/process2.rb +++ b/actionpack/lib/action_controller/testing/process2.rb @@ -51,9 +51,10 @@ module ActionController @request.session = ActionController::TestSession.new(session) unless session.nil? @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash - build_request_uri(action, parameters) + @controller.request = @request @controller.params.merge!(parameters) + build_request_uri(action, parameters) # Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest @controller.process_with_new_base_test(@request, @response) @response -- cgit v1.2.3 From a1f280e83d2b134e23897d4de457d76fb0095768 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 26 May 2009 15:03:09 -0700 Subject: Got all the dispatch tests running on new base --- actionpack/lib/action_controller/new_base/compatibility.rb | 3 +++ actionpack/lib/action_dispatch/middleware/show_exceptions.rb | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb index fddfadcbf2..c09e086b1b 100644 --- a/actionpack/lib/action_controller/new_base/compatibility.rb +++ b/actionpack/lib/action_controller/new_base/compatibility.rb @@ -61,6 +61,9 @@ module ActionController # and images to a dedicated asset server away from the main web server. Example: # ActionController::Base.asset_host = "http://assets.example.com" cattr_accessor :asset_host + + cattr_accessor :ip_spoofing_check + self.ip_spoofing_check = true end # For old tests diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 4d598669c7..1bd6a86bec 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -10,7 +10,8 @@ module ActionDispatch @@rescue_responses = Hash.new(:internal_server_error) @@rescue_responses.update({ 'ActionController::RoutingError' => :not_found, - 'ActionController::UnknownAction' => :not_found, + # TODO: Clean this up after the switch + ActionController::UnknownAction.name => :not_found, 'ActiveRecord::RecordNotFound' => :not_found, 'ActiveRecord::StaleObjectError' => :conflict, 'ActiveRecord::RecordInvalid' => :unprocessable_entity, @@ -23,10 +24,10 @@ module ActionDispatch cattr_accessor :rescue_templates @@rescue_templates = Hash.new('diagnostics') @@rescue_templates.update({ - 'ActionView::MissingTemplate' => 'missing_template', - 'ActionController::RoutingError' => 'routing_error', - 'ActionController::UnknownAction' => 'unknown_action', - 'ActionView::TemplateError' => 'template_error' + 'ActionView::MissingTemplate' => 'missing_template', + 'ActionController::RoutingError' => 'routing_error', + ActionController::UnknownAction.name => 'unknown_action', + 'ActionView::TemplateError' => 'template_error' }) FAILSAFE_RESPONSE = [500, {'Content-Type' => 'text/html'}, -- cgit v1.2.3 From 7211048b2b1d640c4f33587b57261bdfe9c77b93 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 26 May 2009 15:19:39 -0700 Subject: Get all template tests passing on new base --- actionpack/lib/action_controller/new_base/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index ffe608ade4..3477fc0403 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -40,7 +40,7 @@ module ActionController module ImplicitRender def process_action(method_name) ret = super - default_render if response_body.nil? + default_render unless performed? ret end -- cgit v1.2.3 From 6bbe965ccdcef2d7e713e65175722718d325b2bd Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 27 May 2009 10:40:43 +0200 Subject: Reduce the cost of using ActionController::Http significantly by: * Removing the dependency on AD::Request and AD::Response * Moving the logic for the request and response object into a new module that is included by default. * Changing Renderer and Redirector to use self.headers, self.content_type, and self.status, which have very basic default implementations on AC::Http. When RackConvenience is included (which it is by default on AC::Base), the full Request/Response logic is used instead of the simple logic. --- actionpack/lib/action_controller/new_base.rb | 1 + actionpack/lib/action_controller/new_base/base.rb | 1 + .../action_controller/new_base/conditional_get.rb | 3 ++ actionpack/lib/action_controller/new_base/http.rb | 42 +++++++++++++++------- .../action_controller/new_base/rack_convenience.rb | 34 ++++++++++++++++++ .../lib/action_controller/new_base/redirector.rb | 4 +-- .../action_controller/new_base/render_options.rb | 8 ++--- .../lib/action_controller/new_base/renderer.rb | 13 +++---- .../lib/action_controller/new_base/session.rb | 4 +++ .../lib/action_controller/new_base/testing.rb | 2 ++ .../lib/action_controller/new_base/url_for.rb | 4 +++ 11 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 actionpack/lib/action_controller/new_base/rack_convenience.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb index e9e89769f1..df256985ac 100644 --- a/actionpack/lib/action_controller/new_base.rb +++ b/actionpack/lib/action_controller/new_base.rb @@ -4,6 +4,7 @@ module ActionController autoload :HideActions, "action_controller/new_base/hide_actions" autoload :Http, "action_controller/new_base/http" autoload :Layouts, "action_controller/new_base/layouts" + autoload :RackConvenience, "action_controller/new_base/rack_convenience" autoload :Rails2Compatibility, "action_controller/new_base/compatibility" autoload :Redirector, "action_controller/new_base/redirector" autoload :Renderer, "action_controller/new_base/renderer" diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 3477fc0403..6fe7793030 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -14,6 +14,7 @@ module ActionController include ActionController::Renderers::All include ActionController::Layouts include ActionController::ConditionalGet + include ActionController::RackConvenience # Legacy modules include SessionManagement diff --git a/actionpack/lib/action_controller/new_base/conditional_get.rb b/actionpack/lib/action_controller/new_base/conditional_get.rb index 116ce34494..7d41ee6371 100644 --- a/actionpack/lib/action_controller/new_base/conditional_get.rb +++ b/actionpack/lib/action_controller/new_base/conditional_get.rb @@ -1,5 +1,8 @@ module ActionController module ConditionalGet + extend ActiveSupport::DependencyModule + + depends_on RackConvenience # Sets the etag, last_modified, or both on the response and renders a # "304 Not Modified" response if the request is already fresh. diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb index 2525e221a6..7ff490bb9c 100644 --- a/actionpack/lib/action_controller/new_base/http.rb +++ b/actionpack/lib/action_controller/new_base/http.rb @@ -6,7 +6,7 @@ module ActionController abstract! # :api: public - attr_internal :request, :response, :params + attr_internal :params, :env # :api: public def self.controller_name @@ -36,32 +36,48 @@ module ActionController controller.call(env).to_rack end - delegate :headers, :to => "@_response" + # The details below can be overridden to support a specific + # Request and Response object. The default ActionController::Base + # implementation includes RackConvenience, which makes a request + # and response object available. You might wish to control the + # environment and response manually for performance reasons. - def params - @_params ||= @_request.parameters + attr_internal :status, :headers, :content_type + + def initialize(*) + @_headers = {} + super + end + + # Basic implements for content_type=, location=, and headers are + # provided to reduce the dependency on the RackConvenience module + # in Renderer and Redirector. + + def content_type=(type) + headers["Content-Type"] = type.to_s + end + + def location=(url) + headers["Location"] = url end # :api: private def call(name, env) - @_request = ActionDispatch::Request.new(env) - @_response = ActionDispatch::Response.new - @_response.request = request + @_env = env process(name) to_rack end + # :api: private + def to_rack + [status, headers, response_body] + end + def self.action(name) @actions ||= {} @actions[name.to_s] ||= proc do |env| new.call(name, env) end end - - # :api: private - def to_rack - @_response.prepare! - @_response.to_a - end end end diff --git a/actionpack/lib/action_controller/new_base/rack_convenience.rb b/actionpack/lib/action_controller/new_base/rack_convenience.rb new file mode 100644 index 0000000000..0422ab2f14 --- /dev/null +++ b/actionpack/lib/action_controller/new_base/rack_convenience.rb @@ -0,0 +1,34 @@ +module ActionController + module RackConvenience + extend ActiveSupport::DependencyModule + + included do + delegate :headers, :status=, :location=, + :status, :location, :content_type, :to => "@_response" + attr_internal :request, :response + end + + def call(name, env) + @_request = ActionDispatch::Request.new(env) + @_response = ActionDispatch::Response.new + @_response.request = request + super + end + + def params + @_params ||= @_request.parameters + end + + # :api: private + def to_rack + @_response.prepare! + @_response.to_a + end + + def response_body=(body) + response.body = body if response + super + end + + end +end \ No newline at end of file diff --git a/actionpack/lib/action_controller/new_base/redirector.rb b/actionpack/lib/action_controller/new_base/redirector.rb index ff7b74341c..b2da412edf 100644 --- a/actionpack/lib/action_controller/new_base/redirector.rb +++ b/actionpack/lib/action_controller/new_base/redirector.rb @@ -11,8 +11,8 @@ module ActionController def redirect_to(url, status) #:doc: raise AbstractController::DoubleRenderError if response_body logger.info("Redirected to #{url}") if logger && logger.info? - response.status = status - response.location = url.gsub(/[\r\n]/, '') + self.status = status + self.location = url.gsub(/[\r\n]/, '') self.response_body = "You are being redirected." end end diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb index 581a92cb7b..48575ec0bd 100644 --- a/actionpack/lib/action_controller/new_base/render_options.rb +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -57,7 +57,7 @@ module ActionController def _render_json(json, options) json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? - response.content_type ||= Mime::JSON + self.content_type ||= Mime::JSON self.response_body = json end end @@ -67,7 +67,7 @@ module ActionController register_renderer :js def _render_js(js, options) - response.content_type ||= Mime::JS + self.content_type ||= Mime::JS self.response_body = js end end @@ -77,7 +77,7 @@ module ActionController register_renderer :xml def _render_xml(xml, options) - response.content_type ||= Mime::XML + self.content_type ||= Mime::XML self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml end end @@ -88,7 +88,7 @@ module ActionController def _render_update(proc, options) generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(_action_view, &proc) - response.content_type = Mime::JS + self.content_type = Mime::JS self.response_body = generator.to_s end end diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 987751a601..fb6fe4aee6 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -8,16 +8,11 @@ module ActionController self.formats = request.formats.map {|x| x.to_sym} super end - - def response_body=(body) - response.body = body if response - super - end def render(options) super options[:_template] ||= _action_view._partial - response.content_type ||= begin + self.content_type ||= begin mime = options[:_template].mime_type formats.include?(mime && mime.to_sym) || formats.include?(:all) ? mime : Mime::Type.lookup_by_extension(formats.first) end @@ -76,9 +71,9 @@ module ActionController def _process_options(options) status, content_type, location = options.values_at(:status, :content_type, :location) - response.status = status if status - response.content_type = content_type if content_type - response.headers["Location"] = url_for(location) if location + self.status = status if status + self.content_type = content_type if content_type + self.headers["Location"] = url_for(location) if location end end end diff --git a/actionpack/lib/action_controller/new_base/session.rb b/actionpack/lib/action_controller/new_base/session.rb index a8715555fb..9ee3e9e136 100644 --- a/actionpack/lib/action_controller/new_base/session.rb +++ b/actionpack/lib/action_controller/new_base/session.rb @@ -1,5 +1,9 @@ module ActionController module Session + extend ActiveSupport::DependencyModule + + depends_on RackConvenience + def session @_request.session end diff --git a/actionpack/lib/action_controller/new_base/testing.rb b/actionpack/lib/action_controller/new_base/testing.rb index 78051a6252..596f613a13 100644 --- a/actionpack/lib/action_controller/new_base/testing.rb +++ b/actionpack/lib/action_controller/new_base/testing.rb @@ -2,6 +2,8 @@ module ActionController module Testing extend ActiveSupport::DependencyModule + depends_on RackConvenience + # OMG MEGA HAX def process_with_new_base_test(request, response) @_request = request diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb index 94de9fab50..e6e5d3acce 100644 --- a/actionpack/lib/action_controller/new_base/url_for.rb +++ b/actionpack/lib/action_controller/new_base/url_for.rb @@ -1,5 +1,9 @@ module ActionController module UrlFor + extend ActiveSupport::DependencyModule + + depends_on RackConvenience + def process_action(*) initialize_current_url super -- cgit v1.2.3 From bb8e5843f32b13e759da51a4713a31b23ebcac6d Mon Sep 17 00:00:00 2001 From: Niels Ganser Date: Wed, 27 May 2009 14:51:33 -0500 Subject: ActionController::Flash::FlashHash.use now returns either the value corresponding to the passed key or itself when no key is passed [#1792 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_controller/base/chained/flash.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/chained/flash.rb b/actionpack/lib/action_controller/base/chained/flash.rb index 6bd482d85a..7a8dd2dcf9 100644 --- a/actionpack/lib/action_controller/base/chained/flash.rb +++ b/actionpack/lib/action_controller/base/chained/flash.rb @@ -135,12 +135,11 @@ module ActionController #:nodoc: # use('msg') # marks the "msg" entry as used # use(nil, false) # marks the entire flash as unused (keeps it around for one more action) # use('msg', false) # marks the "msg" entry as unused (keeps it around for one more action) - def use(k=nil, v=true) - unless k.nil? - @used[k] = v - else - keys.each{ |key| use(key, v) } - end + # Returns the single value for the key you asked to be marked (un)used or the FlashHash itself + # if no key is passed. + def use(key = nil, used = true) + Array(key || keys).each { |k| @used[k] = used } + return key ? self[key] : self end end -- cgit v1.2.3 From 61c471eebb3718a3ef5741e1e4d0974be7483290 Mon Sep 17 00:00:00 2001 From: Eduard Bondarenko Date: Wed, 27 May 2009 14:53:05 -0500 Subject: Add % to RESERVED_PCHAR [#2574 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_controller/routing/segments.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/routing/segments.rb b/actionpack/lib/action_controller/routing/segments.rb index 4f936d51d2..2603855476 100644 --- a/actionpack/lib/action_controller/routing/segments.rb +++ b/actionpack/lib/action_controller/routing/segments.rb @@ -1,7 +1,7 @@ module ActionController module Routing class Segment #:nodoc: - RESERVED_PCHAR = ':@&=+$,;' + RESERVED_PCHAR = ':@&=+$,;%' SAFE_PCHAR = "#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}" if RUBY_VERSION >= '1.9' UNSAFE_PCHAR = Regexp.new("[^#{SAFE_PCHAR}]", false).freeze -- cgit v1.2.3 From 760cb633396a954b465ec0dd0344915185bddec1 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Wed, 27 May 2009 15:01:03 -0500 Subject: Make the default 500 Internal Server Error page more friendly. Many people don't know they're supposed to look in the log files. [#2716 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_dispatch/middleware/show_exceptions.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 1bd6a86bec..bfff307669 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -31,7 +31,10 @@ module ActionDispatch }) FAILSAFE_RESPONSE = [500, {'Content-Type' => 'text/html'}, - ['

500 Internal Server Error

']] + ["

500 Internal Server Error

" << + "If you are the administrator of this website, then please read this web " << + "application's log file and/or the web server's log file to find out what " << + "went wrong."]] def initialize(app, consider_all_requests_local = false) @app = app -- cgit v1.2.3 From a5688fa9073dc8824d98071346e6cd9ae417eb72 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 27 May 2009 11:02:13 -0700 Subject: Add the ability to prepend filters to new callbacks --- actionpack/lib/action_controller/abstract/callbacks.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index e4f9dd3112..83dd06bf8b 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -37,6 +37,15 @@ module AbstractController end end + def prepend_#{filter}_filter(*names, &blk) + options = names.last.is_a?(Hash) ? names.pop : {} + _normalize_callback_options(options) + names.push(blk) if block_given? + names.each do |name| + process_action_callback(:#{filter}, name, options.merge(:prepend => true)) + end + end + def skip_#{filter}_filter(*names, &blk) options = names.last.is_a?(Hash) ? names.pop : {} _normalize_callback_options(options) -- cgit v1.2.3 From e70bd6bdfae3615a013cf6252efdea3d94c5b64c Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Wed, 27 May 2009 15:59:14 -0700 Subject: Added hook point in new base #send_action which does the actual action method dispatching --- actionpack/lib/action_controller/abstract/base.rb | 4 +++- actionpack/lib/action_controller/new_base/base.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index 0e4803388a..bbd42623d3 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -95,9 +95,11 @@ module AbstractController # overrides it to include the case where a template matching the # action_name is found. def process_action(method_name) - send(method_name) + send_action(method_name) end + alias send_action send + def _handle_action_missing action_missing(@_action_name) end diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 6fe7793030..f8aaf05387 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -39,7 +39,7 @@ module ActionController # TODO: Extract into its own module # This should be moved together with other normalizing behavior module ImplicitRender - def process_action(method_name) + def send_action(method_name) ret = super default_render unless performed? ret -- cgit v1.2.3 From f2f58f535520bfa77ab2d0ad1fb598f18349dd2e Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Wed, 27 May 2009 17:31:48 -0700 Subject: Fix failing ActionCacheFilter tests due to around filter changes. --- actionpack/lib/action_controller/caching/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 3646ff1af9..54148b55d8 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -93,7 +93,7 @@ module ActionController #:nodoc: # TODO: Remove once New Base is merged if defined?(ActionController::Http) - def around_process_action(controller) + def filter(controller) should_continue = before(controller) yield if should_continue after(controller) -- cgit v1.2.3 From 0349278f3da9f7f532330cf295eed35ede3bae66 Mon Sep 17 00:00:00 2001 From: Olly Legg Date: Thu, 28 May 2009 09:18:27 -0500 Subject: Memoize cookies so that updates to cookies are available in the current request. [#2733 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_controller/base/cookies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/cookies.rb b/actionpack/lib/action_controller/base/cookies.rb index ca380e98d0..d4806623c3 100644 --- a/actionpack/lib/action_controller/base/cookies.rb +++ b/actionpack/lib/action_controller/base/cookies.rb @@ -51,7 +51,7 @@ module ActionController #:nodoc: protected # Returns the cookie container, which operates as described above. def cookies - CookieJar.new(self) + @cookies ||= CookieJar.new(self) end end -- cgit v1.2.3 From 72cb6f58be6590ac2590eea420a1b3ef175189b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20S=C3=B6rensen?= Date: Thu, 28 May 2009 09:30:49 -0500 Subject: The FlashHash and friends causes a lot of needless session storing, when we know for a fact that there's no content in the flash. By not storing the empty hash in the session we save a lot of communication with the various session backends, while still keeping the same interface to the flash. [#2703 state:resolved] Signed-off-by: Joshua Peek --- .../lib/action_controller/base/chained/flash.rb | 70 ++++++++++++---------- 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/chained/flash.rb b/actionpack/lib/action_controller/base/chained/flash.rb index 7a8dd2dcf9..2d084ba1ab 100644 --- a/actionpack/lib/action_controller/base/chained/flash.rb +++ b/actionpack/lib/action_controller/base/chained/flash.rb @@ -30,7 +30,7 @@ module ActionController #:nodoc: # TODO : Remove the defined? check when new base is the main base depends_on Session if defined?(ActionController::Http) - + included do # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) @@ -129,6 +129,11 @@ module ActionController #:nodoc: (@used.keys - keys).each{ |k| @used.delete(k) } end + def store(session, key = "flash") + return if self.empty? + session[key] = self + end + private # Used internally by the keep and discard methods # use() # marks the entire flash as used @@ -145,48 +150,47 @@ module ActionController #:nodoc: module InstanceMethodsForBase #:nodoc: protected + def perform_action_with_flash + perform_action_without_flash + if defined? @_flash + @_flash.store(session) + remove_instance_variable(:@_flash) + end + end - def perform_action_with_flash - perform_action_without_flash - remove_instance_variable(:@_flash) if defined?(@_flash) - end - - def reset_session_with_flash - reset_session_without_flash - remove_instance_variable(:@_flash) if defined?(@_flash) - end + def reset_session_with_flash + reset_session_without_flash + remove_instance_variable(:@_flash) if defined?(@_flash) + end end module InstanceMethodsForNewBase #:nodoc: protected + def process_action(method_name) + super + if defined? @_flash + @_flash.store(session) + remove_instance_variable(:@_flash) + end + end - def reset_session - super - remove_flash_instance_variable - end - - def process_action(method_name) - super - remove_flash_instance_variable - end - - def remove_flash_instance_variable - remove_instance_variable(:@_flash) if defined?(@_flash) - end + def reset_session + super + remove_instance_variable(:@_flash) if defined?(@_flash) + end end protected + # Access the contents of the flash. Use flash["notice"] to + # read a notice you put there or flash["notice"] = "hello" + # to put a new one. + def flash #:doc: + if !defined?(@_flash) + @_flash = session["flash"] || FlashHash.new + @_flash.sweep + end - # Access the contents of the flash. Use flash["notice"] to - # read a notice you put there or flash["notice"] = "hello" - # to put a new one. - def flash #:doc: - unless defined?(@_flash) - @_flash = session["flash"] ||= FlashHash.new - @_flash.sweep + @_flash end - - @_flash - end end end -- cgit v1.2.3 From dd98280e38d640f5724887cf8a715b79f0439d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20S=C3=B6rensen?= Date: Thu, 28 May 2009 09:35:17 -0500 Subject: Only save the session if we're actually writing to it [#2703 state:resolved] Signed-off-by: Joshua Peek --- .../lib/action_dispatch/middleware/session/abstract_store.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 03761b10bd..6d109f4624 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -15,6 +15,7 @@ module ActionDispatch @by = by @env = env @loaded = false + @updated = false end def session_id @@ -32,6 +33,7 @@ module ActionDispatch def []=(key, value) load! unless @loaded super(key.to_s, value) + @updated = true end def to_hash @@ -79,6 +81,10 @@ module ActionDispatch @loaded end + def updated? + @updated + end + def load! stale_session_check! do id, session = @by.send(:load_session, @env) @@ -147,7 +153,10 @@ module ActionDispatch options = env[ENV_SESSION_OPTIONS_KEY] if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) || options[:expire_after] - session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.send(:loaded?) + if session_data.is_a?(AbstractStore::SessionHash) + session_data.send(:load!) if !session_data.send(:loaded?) + return response if !session_data.send(:updated?) + end sid = options[:id] || generate_sid -- cgit v1.2.3 From de203245afd2bbf7f93f3241fcf3a71a88101d47 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 28 May 2009 09:49:02 -0500 Subject: Revert "Revert "Whitespace!"" This reverts commit 0cac68d3bed3e6bf8ec2eb994858e4a179046941. --- actionpack/lib/action_controller/abstract.rb | 2 +- actionpack/lib/action_controller/abstract/base.rb | 34 ++++----- .../lib/action_controller/abstract/benchmarker.rb | 6 +- .../lib/action_controller/abstract/callbacks.rb | 8 +- .../lib/action_controller/abstract/exceptions.rb | 4 +- .../lib/action_controller/abstract/helpers.rb | 9 +-- .../lib/action_controller/abstract/layouts.rb | 25 ++++--- .../lib/action_controller/abstract/logger.rb | 12 +-- .../lib/action_controller/abstract/renderer.rb | 24 +++--- actionpack/lib/action_controller/new_base/base.rb | 18 ++--- .../action_controller/new_base/compatibility.rb | 34 +++++---- .../action_controller/new_base/conditional_get.rb | 29 ++++---- .../lib/action_controller/new_base/helpers.rb | 49 ++++++------- .../lib/action_controller/new_base/hide_actions.rb | 46 +++++++----- actionpack/lib/action_controller/new_base/http.rb | 38 ++++++---- .../lib/action_controller/new_base/layouts.rb | 38 +++++----- .../action_controller/new_base/rack_convenience.rb | 15 ++-- .../lib/action_controller/new_base/redirector.rb | 4 +- .../action_controller/new_base/render_options.rb | 16 ++-- .../lib/action_controller/new_base/renderer.rb | 85 +++++++++++----------- .../lib/action_controller/new_base/rescuable.rb | 29 ++++---- .../lib/action_controller/new_base/testing.rb | 3 +- .../lib/action_controller/new_base/url_for.rb | 6 +- 23 files changed, 270 insertions(+), 264 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract.rb b/actionpack/lib/action_controller/abstract.rb index d6b7a44f5f..f46b91627f 100644 --- a/actionpack/lib/action_controller/abstract.rb +++ b/actionpack/lib/action_controller/abstract.rb @@ -11,4 +11,4 @@ module AbstractController autoload :Renderer, "action_controller/abstract/renderer" # === Exceptions autoload :ActionNotFound, "action_controller/abstract/exceptions" -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index bbd42623d3..87083a4d79 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -2,28 +2,27 @@ require 'active_support/core_ext/module/attr_internal' module AbstractController class Error < StandardError; end - + class DoubleRenderError < Error DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"." def initialize(message = nil) super(message || DEFAULT_MESSAGE) end - end - + end + class Base - attr_internal :response_body attr_internal :response_obj attr_internal :action_name class << self - attr_reader :abstract - + attr_reader :abstract + def abstract! @abstract = true end - + alias_method :abstract?, :abstract def inherited(klass) @@ -34,13 +33,13 @@ module AbstractController def subclasses @subclasses ||= [] end - + def internal_methods controller = self controller = controller.superclass until controller.abstract? controller.public_instance_methods(true) end - + def process(action) new.process(action.to_s) end @@ -48,7 +47,7 @@ module AbstractController def hidden_actions [] end - + def action_methods @action_methods ||= # All public instance methods of this class, including ancestors @@ -61,13 +60,13 @@ module AbstractController hidden_actions end end - + abstract! - + def initialize self.response_obj = {} end - + def process(action) @_action_name = action_name = action.to_s @@ -78,17 +77,16 @@ module AbstractController process_action(action_name) self end - + private - def action_methods self.class.action_methods end - + def action_method?(action) action_methods.include?(action) end - + # It is possible for respond_to?(action_name) to be false and # respond_to?(:action_missing) to be false if respond_to_action? # is overridden in a subclass. For instance, ActionController::Base @@ -114,4 +112,4 @@ module AbstractController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb index 9f5889c704..9be06f48fb 100644 --- a/actionpack/lib/action_controller/abstract/benchmarker.rb +++ b/actionpack/lib/action_controller/abstract/benchmarker.rb @@ -1,9 +1,9 @@ module AbstractController module Benchmarker extend ActiveSupport::DependencyModule - + depends_on Logger - + module ClassMethods def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true) if logger && logger.level >= log_level @@ -25,4 +25,4 @@ module AbstractController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index 83dd06bf8b..4314235ba9 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -13,7 +13,7 @@ module AbstractController super end end - + module ClassMethods def _normalize_callback_options(options) if only = options[:only] @@ -21,11 +21,11 @@ module AbstractController options[:per_key] = {:if => only} end if except = options[:except] - except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") + except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") options[:per_key] = {:unless => except} end end - + [:before, :after, :around].each do |filter| class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{filter}_filter(*names, &blk) @@ -60,4 +60,4 @@ module AbstractController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/exceptions.rb b/actionpack/lib/action_controller/abstract/exceptions.rb index ec4680629b..2f6c55f068 100644 --- a/actionpack/lib/action_controller/abstract/exceptions.rb +++ b/actionpack/lib/action_controller/abstract/exceptions.rb @@ -1,3 +1,3 @@ module AbstractController - class ActionNotFound < StandardError ; end -end \ No newline at end of file + class ActionNotFound < StandardError; end +end diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb index 41decfd0c7..7b1b197e1d 100644 --- a/actionpack/lib/action_controller/abstract/helpers.rb +++ b/actionpack/lib/action_controller/abstract/helpers.rb @@ -16,12 +16,12 @@ module AbstractController av end end - + module ClassMethods def inherited(klass) klass.master_helper_module = Module.new klass.master_helper_module.__send__ :include, master_helper_module - + super end @@ -57,7 +57,7 @@ module AbstractController ruby_eval end end - + def helper(*args, &block) args.flatten.each do |arg| case arg @@ -68,6 +68,5 @@ module AbstractController master_helper_module.module_eval(&block) if block_given? end end - end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb index 3d6810bda9..dd38485271 100644 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ b/actionpack/lib/action_controller/abstract/layouts.rb @@ -17,18 +17,18 @@ module AbstractController conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} } self._layout_conditions = conditions - + @_layout = layout || false # Converts nil to false _write_layout_method end - + def _implied_layout_name name.underscore end - + # Takes the specified layout and creates a _layout method to be called # by _default_layout - # + # # If the specified layout is a: # String:: return the string # Symbol:: call the method specified by the symbol @@ -57,11 +57,12 @@ module AbstractController end end end - + private - - def _layout(details) end # This will be overwritten - + # This will be overwritten + def _layout(details) + end + # :api: plugin # ==== # Override this to mutate the inbound layout name @@ -69,7 +70,7 @@ module AbstractController unless [String, FalseClass, NilClass].include?(name.class) raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}" end - + name && view_paths.find_by_parts(name, details, _layout_prefix(name)) end @@ -77,7 +78,7 @@ module AbstractController def _layout_prefix(name) "layouts" end - + def _default_layout(require_layout = false, details = {:formats => formats}) if require_layout && _action_has_layout? && !_layout(details) raise ArgumentError, @@ -87,7 +88,7 @@ module AbstractController begin _layout_for_name(_layout(details), details) if _action_has_layout? rescue NameError => e - raise NoMethodError, + raise NoMethodError, "You specified #{@_layout.inspect} as the layout, but no such method was found" end end @@ -103,4 +104,4 @@ module AbstractController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb index 980ede0bed..ce73888763 100644 --- a/actionpack/lib/action_controller/abstract/logger.rb +++ b/actionpack/lib/action_controller/abstract/logger.rb @@ -9,7 +9,7 @@ module AbstractController def initialize(&blk) @blk = blk end - + def to_s @blk.call end @@ -19,10 +19,10 @@ module AbstractController included do cattr_accessor :logger end - + def process(action) ret = super - + if logger log = DelayedLog.new do "\n\nProcessing #{self.class.name}\##{action_name} " \ @@ -32,14 +32,14 @@ module AbstractController logger.info(log) end - + ret end - + def request_origin # this *needs* to be cached! # otherwise you'd get different results if calling it more than once @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}" - end + end end end diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index 7f7ec78054..374ceb5b74 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -15,22 +15,22 @@ module AbstractController end def _action_view - @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self) + @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self) end - + def render(*args) if response_body raise AbstractController::DoubleRenderError, "OMG" end - + self.response_body = render_to_body(*args) end - + # Raw rendering of a template to a Rack-compatible body. # ==== # @option _prefix The template's path prefix # @option _layout The relative path to the layout template to use - # + # # :api: plugin def render_to_body(options = {}) # TODO: Refactor so we can just use the normal template logic for this @@ -46,7 +46,7 @@ module AbstractController # ==== # @option _prefix The template's path prefix # @option _layout The relative path to the layout template to use - # + # # :api: plugin def render_to_string(options = {}) AbstractController::Renderer.body_to_s(render_to_body(options)) @@ -55,8 +55,10 @@ module AbstractController def _render_template(options) _action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial]) end - - def view_paths() _view_paths end + + def view_paths() + _view_paths + end # Return a string representation of a Rack-compatible response body. def self.body_to_s(body) @@ -71,7 +73,6 @@ module AbstractController end private - def _determine_template(options) name = (options[:_template_name] || action_name).to_s @@ -81,11 +82,10 @@ module AbstractController end module ClassMethods - def append_view_path(path) self.view_paths << path end - + def prepend_view_path(path) self.view_paths.unshift(path) end @@ -93,7 +93,7 @@ module AbstractController def view_paths self._view_paths end - + def view_paths=(paths) self._view_paths = paths.is_a?(ActionView::PathSet) ? paths : ActionView::Base.process_view_paths(paths) diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index f8aaf05387..d7b65d37fa 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -1,7 +1,7 @@ module ActionController class Base < Http abstract! - + include AbstractController::Benchmarker include AbstractController::Callbacks include AbstractController::Logger @@ -66,31 +66,31 @@ module ActionController ::ActionController::Base.subclasses << klass.to_s super end - + def self.subclasses @subclasses ||= [] end - + def self.app_loaded! @subclasses.each do |subclass| subclass.constantize._write_layout_method end end - + def _normalize_options(action = nil, options = {}, &blk) if action.is_a?(Hash) - options, action = action, nil + options, action = action, nil elsif action.is_a?(String) || action.is_a?(Symbol) key = case action = action.to_s when %r{^/} then :file when %r{/} then :template else :action - end + end options.merge! key => action elsif action options.merge! :partial => action end - + if options.key?(:action) && options[:action].to_s.index("/") options[:template] = options.delete(:action) end @@ -140,7 +140,7 @@ module ActionController # # When using redirect_to :back, if there is no referrer, # RedirectBackError will be raised. You may specify some fallback - # behavior for this case by rescuing RedirectBackError. + # behavior for this case by rescuing RedirectBackError. def redirect_to(options = {}, response_status = {}) #:doc: raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? @@ -166,7 +166,7 @@ module ActionController else url_for(options) end - + super(url, status) end end diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb index c09e086b1b..1d0cb601e3 100644 --- a/actionpack/lib/action_controller/new_base/compatibility.rb +++ b/actionpack/lib/action_controller/new_base/compatibility.rb @@ -9,43 +9,43 @@ module ActionController included do ::ActionController::UnknownAction = ::AbstractController::ActionNotFound ::ActionController::DoubleRenderError = ::AbstractController::DoubleRenderError - + cattr_accessor :session_options self.session_options = {} - + cattr_accessor :allow_concurrency self.allow_concurrency = false - + cattr_accessor :param_parsers self.param_parsers = { Mime::MULTIPART_FORM => :multipart_form, Mime::URL_ENCODED_FORM => :url_encoded_form, Mime::XML => :xml_simple, Mime::JSON => :json } - + cattr_accessor :relative_url_root self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] - + cattr_accessor :default_charset self.default_charset = "utf-8" - + # cattr_reader :protected_instance_variables cattr_accessor :protected_instance_variables self.protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller @action_name @before_filter_chain_aborted @action_cache_path @_headers @_params @_flash @_response) - + # Indicates whether or not optimise the generated named # route helper methods cattr_accessor :optimise_named_routes self.optimise_named_routes = true - + cattr_accessor :resources_path_names self.resources_path_names = { :new => 'new', :edit => 'edit' } - + # Controls the resource action separator cattr_accessor :resource_action_separator self.resource_action_separator = "/" - + cattr_accessor :use_accept_header self.use_accept_header = true @@ -65,7 +65,7 @@ module ActionController cattr_accessor :ip_spoofing_check self.ip_spoofing_check = true end - + # For old tests def initialize_template_class(*) end def assign_shortcuts(*) end @@ -81,7 +81,9 @@ module ActionController end module ClassMethods - def consider_all_requests_local() end + def consider_all_requests_local + end + def rescue_action(env) raise env["action_dispatch.rescue.exception"] end @@ -91,12 +93,12 @@ module ActionController @@cache_store = ActiveSupport::Cache.lookup_store(store_option) end end - + def render_to_body(options) if options.is_a?(Hash) && options.key?(:template) options[:template].sub!(/^\//, '') end - + options[:text] = nil if options[:nothing] == true body = super @@ -110,8 +112,8 @@ module ActionController def method_for_action(action_name) super || (respond_to?(:method_missing) && "_handle_method_missing") - end - + end + def _layout_prefix(name) super unless name =~ /\blayouts/ end diff --git a/actionpack/lib/action_controller/new_base/conditional_get.rb b/actionpack/lib/action_controller/new_base/conditional_get.rb index 7d41ee6371..38f3d3cf68 100644 --- a/actionpack/lib/action_controller/new_base/conditional_get.rb +++ b/actionpack/lib/action_controller/new_base/conditional_get.rb @@ -3,13 +3,13 @@ module ActionController extend ActiveSupport::DependencyModule depends_on RackConvenience - + # Sets the etag, last_modified, or both on the response and renders a # "304 Not Modified" response if the request is already fresh. # # Parameters: # * :etag - # * :last_modified + # * :last_modified # * :public By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches). # # Example: @@ -21,14 +21,14 @@ module ActionController # # This will render the show template if the request isn't sending a matching etag or # If-Modified-Since header and just a "304 Not Modified" response if there's a match. - # + # def fresh_when(options) options.assert_valid_keys(:etag, :last_modified, :public) response.etag = options[:etag] if options[:etag] response.last_modified = options[:last_modified] if options[:last_modified] - - if options[:public] + + if options[:public] cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip } cache_control.delete("private") cache_control.delete("no-cache") @@ -39,8 +39,8 @@ module ActionController if request.fresh?(response) head :not_modified end - end - + end + # Return a response that has no content (merely headers). The options # argument is interpreted to be a hash of header names and values. # This allows you to easily return a response that consists only of @@ -67,8 +67,8 @@ module ActionController end render :nothing => true, :status => status - end - + end + # Sets the etag and/or last_modified on the response and checks it against # the client request. If the request doesn't match the options provided, the # request is considered stale and should be generated from scratch. Otherwise, @@ -76,7 +76,7 @@ module ActionController # # Parameters: # * :etag - # * :last_modified + # * :last_modified # * :public By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches). # # Example: @@ -95,7 +95,7 @@ module ActionController fresh_when(options) !request.fresh?(response) end - + # Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that # intermediate caches shouldn't cache the response. # @@ -117,10 +117,10 @@ module ActionController else cache_control << "private" end - + # This allows for additional headers to be passed through like 'max-stale' => 5.hours cache_control += options.symbolize_keys.reject{|k,v| k == :public || k == :private }.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"} - + response.headers["Cache-Control"] = cache_control.join(', ') end @@ -129,6 +129,5 @@ module ActionController def expires_now #:doc: response.headers["Cache-Control"] = "no-cache" end - end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/helpers.rb b/actionpack/lib/action_controller/new_base/helpers.rb index e00c3c338b..1dece13114 100644 --- a/actionpack/lib/action_controller/new_base/helpers.rb +++ b/actionpack/lib/action_controller/new_base/helpers.rb @@ -24,10 +24,10 @@ module ActionController # # * *args: One or more modules, strings or symbols, or the special symbol :all. # * &block: A block defining helper methods. - # + # # ==== Examples - # When the argument is a string or symbol, the method will provide the "_helper" suffix, require the file - # and include the module in the template class. The second form illustrates how to include custom helpers + # When the argument is a string or symbol, the method will provide the "_helper" suffix, require the file + # and include the module in the template class. The second form illustrates how to include custom helpers # when working with namespaced controllers, or other cases where the file containing the helper definition is not # in one of Rails' standard load paths: # helper :foo # => requires 'foo_helper' and includes FooHelper @@ -40,17 +40,17 @@ module ActionController # ActionController::Base.helpers_dir (defaults to app/helpers/**/*.rb under RAILS_ROOT). # helper :all # - # Additionally, the +helper+ class method can receive and evaluate a block, making the methods defined available + # Additionally, the +helper+ class method can receive and evaluate a block, making the methods defined available # to the template. # # One line # helper { def hello() "Hello, world!" end } # # Multi-line # helper do - # def foo(bar) - # "#{bar} is the very best" + # def foo(bar) + # "#{bar} is the very best" # end # end - # + # # Finally, all the above styles can be mixed together, and the +helper+ method can be invoked with a mix of # +symbols+, +strings+, +modules+ and blocks. # helper(:three, BlindHelper) { def mice() 'mice' end } @@ -106,25 +106,24 @@ module ActionController end private - - def default_helper_module! - unless name.blank? - module_name = name.sub(/Controller$|$/, 'Helper') - module_path = module_name.split('::').map { |m| m.underscore }.join('/') - require_dependency module_path - helper module_name.constantize + def default_helper_module! + unless name.blank? + module_name = name.sub(/Controller$|$/, 'Helper') + module_path = module_name.split('::').map { |m| m.underscore }.join('/') + require_dependency module_path + helper module_name.constantize + end + rescue MissingSourceFile => e + raise unless e.is_missing? module_path + rescue NameError => e + raise unless e.missing_name? module_name end - rescue MissingSourceFile => e - raise unless e.is_missing? module_path - rescue NameError => e - raise unless e.missing_name? module_name - end - # Extract helper names from files in app/helpers/**/*.rb - def all_application_helpers - extract = /^#{Regexp.quote(helpers_dir)}\/?(.*)_helper.rb$/ - Dir["#{helpers_dir}/**/*_helper.rb"].map { |file| file.sub extract, '\1' } - end - end # ClassMethods + # Extract helper names from files in app/helpers/**/*.rb + def all_application_helpers + extract = /^#{Regexp.quote(helpers_dir)}\/?(.*)_helper.rb$/ + Dir["#{helpers_dir}/**/*_helper.rb"].map { |file| file.sub extract, '\1' } + end + end end end diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb index a29b09a893..10b8b582f5 100644 --- a/actionpack/lib/action_controller/new_base/hide_actions.rb +++ b/actionpack/lib/action_controller/new_base/hide_actions.rb @@ -7,27 +7,33 @@ module ActionController self.hidden_actions ||= Set.new end - def action_methods() self.class.action_names end - def action_names() action_methods end - - private - - def action_method?(action_name) - !hidden_actions.include?(action_name) && super + def action_methods + self.class.action_names end - - module ClassMethods - def hide_action(*args) - args.each do |arg| - self.hidden_actions << arg.to_s - end - end - - def action_methods - @action_names ||= Set.new(super.reject {|name| self.hidden_actions.include?(name.to_s)}) - end - def self.action_names() action_methods end + def action_names + action_methods end + + private + def action_method?(action_name) + !hidden_actions.include?(action_name) && super + end + + module ClassMethods + def hide_action(*args) + args.each do |arg| + self.hidden_actions << arg.to_s + end + end + + def action_methods + @action_names ||= Set.new(super.reject {|name| self.hidden_actions.include?(name.to_s)}) + end + + def self.action_names + action_methods + end + end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb index 7ff490bb9c..c96aaaa865 100644 --- a/actionpack/lib/action_controller/new_base/http.rb +++ b/actionpack/lib/action_controller/new_base/http.rb @@ -4,7 +4,7 @@ require 'active_support/core_ext/module/delegation' module ActionController class Http < AbstractController::Base abstract! - + # :api: public attr_internal :params, :env @@ -14,28 +14,36 @@ module ActionController end # :api: public - def controller_name() self.class.controller_name end + def controller_name + self.class.controller_name + end - # :api: public + # :api: public def self.controller_path @controller_path ||= self.name.sub(/Controller$/, '').underscore end - - # :api: public - def controller_path() self.class.controller_path end - - # :api: private - def self.action_names() action_methods end - + + # :api: public + def controller_path + self.class.controller_path + end + # :api: private - def action_names() action_methods end - + def self.action_names + action_methods + end + + # :api: private + def action_names + action_methods + end + # :api: plugin def self.call(env) controller = new controller.call(env).to_rack end - + # The details below can be overridden to support a specific # Request and Response object. The default ActionController::Base # implementation includes RackConvenience, which makes a request @@ -60,14 +68,14 @@ module ActionController def location=(url) headers["Location"] = url end - + # :api: private def call(name, env) @_env = env process(name) to_rack end - + # :api: private def to_rack [status, headers, response_body] diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb index 35068db770..9b4057caaa 100644 --- a/actionpack/lib/action_controller/new_base/layouts.rb +++ b/actionpack/lib/action_controller/new_base/layouts.rb @@ -4,33 +4,31 @@ module ActionController depends_on ActionController::Renderer depends_on AbstractController::Layouts - + module ClassMethods def _implied_layout_name controller_path end end - - private - def _determine_template(options) - super - if (!options.key?(:text) && !options.key?(:inline) && !options.key?(:partial)) || options.key?(:layout) - options[:_layout] = _layout_for_option(options.key?(:layout) ? options[:layout] : :none, options[:_template].details) + private + def _determine_template(options) + super + if (!options.key?(:text) && !options.key?(:inline) && !options.key?(:partial)) || options.key?(:layout) + options[:_layout] = _layout_for_option(options.key?(:layout) ? options[:layout] : :none, options[:_template].details) + end end - end - - def _layout_for_option(name, details) - case name - when String then _layout_for_name(name, details) - when true then _default_layout(true, details) - when :none then _default_layout(false, details) - when false, nil then nil - else - raise ArgumentError, - "String, true, or false, expected for `layout'; you passed #{name.inspect}" + + def _layout_for_option(name, details) + case name + when String then _layout_for_name(name, details) + when true then _default_layout(true, details) + when :none then _default_layout(false, details) + when false, nil then nil + else + raise ArgumentError, + "String, true, or false, expected for `layout'; you passed #{name.inspect}" + end end - end - end end diff --git a/actionpack/lib/action_controller/new_base/rack_convenience.rb b/actionpack/lib/action_controller/new_base/rack_convenience.rb index 0422ab2f14..e465acca6e 100644 --- a/actionpack/lib/action_controller/new_base/rack_convenience.rb +++ b/actionpack/lib/action_controller/new_base/rack_convenience.rb @@ -1,34 +1,33 @@ module ActionController module RackConvenience extend ActiveSupport::DependencyModule - + included do - delegate :headers, :status=, :location=, + delegate :headers, :status=, :location=, :status, :location, :content_type, :to => "@_response" attr_internal :request, :response end - + def call(name, env) @_request = ActionDispatch::Request.new(env) @_response = ActionDispatch::Response.new @_response.request = request super end - + def params @_params ||= @_request.parameters end - + # :api: private def to_rack @_response.prepare! @_response.to_a end - + def response_body=(body) response.body = body if response super end - end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/redirector.rb b/actionpack/lib/action_controller/new_base/redirector.rb index b2da412edf..20060b001f 100644 --- a/actionpack/lib/action_controller/new_base/redirector.rb +++ b/actionpack/lib/action_controller/new_base/redirector.rb @@ -6,7 +6,7 @@ module ActionController super(message || DEFAULT_MESSAGE) end end - + module Redirector def redirect_to(url, status) #:doc: raise AbstractController::DoubleRenderError if response_body @@ -16,4 +16,4 @@ module ActionController self.response_body = "You are being redirected." end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb index 48575ec0bd..f12198a710 100644 --- a/actionpack/lib/action_controller/new_base/render_options.rb +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -1,12 +1,12 @@ module ActionController module RenderOptions extend ActiveSupport::DependencyModule - + included do extlib_inheritable_accessor :_renderers self._renderers = [] end - + module ClassMethods def _write_render_options renderers = _renderers.map do |r| @@ -17,25 +17,25 @@ module ActionController end RUBY_EVAL end - + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def _handle_render_options(options) #{renderers.join} end RUBY_EVAL end - + def _add_render_option(name) _renderers << name _write_render_options end end - + def render_to_body(options) _handle_render_options(options) || super end end - + module RenderOption extend ActiveSupport::DependencyModule @@ -53,13 +53,13 @@ module ActionController module Json include RenderOption register_renderer :json - + def _render_json(json, options) json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? self.content_type ||= Mime::JSON self.response_body = json - end + end end module Js diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index fb6fe4aee6..737a0d6fcf 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -3,7 +3,7 @@ module ActionController extend ActiveSupport::DependencyModule depends_on AbstractController::Renderer - + def process_action(*) self.formats = request.formats.map {|x| x.to_sym} super @@ -21,7 +21,7 @@ module ActionController def render_to_body(options) _process_options(options) - + if options.key?(:partial) _render_partial(options[:partial], options) end @@ -29,51 +29,50 @@ module ActionController super end - private + private + def _prefix + controller_path + end - def _prefix - controller_path - end + def _determine_template(options) + if options.key?(:text) + options[:_template] = ActionView::TextTemplate.new(options[:text], formats.first) + elsif options.key?(:inline) + handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb") + template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {}) + options[:_template] = template + elsif options.key?(:template) + options[:_template_name] = options[:template] + elsif options.key?(:file) + options[:_template_name] = options[:file] + elsif !options.key?(:partial) + options[:_template_name] = (options[:action] || action_name).to_s + options[:_prefix] = _prefix + end - def _determine_template(options) - if options.key?(:text) - options[:_template] = ActionView::TextTemplate.new(options[:text], formats.first) - elsif options.key?(:inline) - handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb") - template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {}) - options[:_template] = template - elsif options.key?(:template) - options[:_template_name] = options[:template] - elsif options.key?(:file) - options[:_template_name] = options[:file] - elsif !options.key?(:partial) - options[:_template_name] = (options[:action] || action_name).to_s - options[:_prefix] = _prefix + super end - - super - end - def _render_partial(partial, options) - case partial - when true - options[:_prefix] = _prefix - when String - options[:_prefix] = _prefix unless partial.index('/') - options[:_template_name] = partial - else - options[:_partial_object] = true - return + def _render_partial(partial, options) + case partial + when true + options[:_prefix] = _prefix + when String + options[:_prefix] = _prefix unless partial.index('/') + options[:_template_name] = partial + else + options[:_partial_object] = true + return + end + + options[:_partial] = options[:object] || true + end + + def _process_options(options) + status, content_type, location = options.values_at(:status, :content_type, :location) + self.status = status if status + self.content_type = content_type if content_type + self.headers["Location"] = url_for(location) if location end - - options[:_partial] = options[:object] || true - end - - def _process_options(options) - status, content_type, location = options.values_at(:status, :content_type, :location) - self.status = status if status - self.content_type = content_type if content_type - self.headers["Location"] = url_for(location) if location - end end end diff --git a/actionpack/lib/action_controller/new_base/rescuable.rb b/actionpack/lib/action_controller/new_base/rescuable.rb index 29ffe19d5f..4450a1131a 100644 --- a/actionpack/lib/action_controller/new_base/rescuable.rb +++ b/actionpack/lib/action_controller/new_base/rescuable.rb @@ -32,22 +32,21 @@ module ActionController #:nodoc: attr_internal :rescued_exception - private - - def method_for_action(action_name) - return action_name if self.rescued_exception = request.env.delete("action_dispatch.rescue.exception") - super - end + private + def method_for_action(action_name) + return action_name if self.rescued_exception = request.env.delete("action_dispatch.rescue.exception") + super + end - def _rescue_action - rescue_with_handler(rescued_exception) || raise(rescued_exception) - end + def _rescue_action + rescue_with_handler(rescued_exception) || raise(rescued_exception) + end - def process_action(*) - super - rescue Exception => exception - self.rescued_exception = exception - _rescue_action - end + def process_action(*) + super + rescue Exception => exception + self.rescued_exception = exception + _rescue_action + end end end diff --git a/actionpack/lib/action_controller/new_base/testing.rb b/actionpack/lib/action_controller/new_base/testing.rb index 596f613a13..97aadfe78f 100644 --- a/actionpack/lib/action_controller/new_base/testing.rb +++ b/actionpack/lib/action_controller/new_base/testing.rb @@ -15,7 +15,7 @@ module ActionController set_test_assigns ret end - + def set_test_assigns @assigns = {} (instance_variable_names - self.class.protected_instance_variables).each do |var| @@ -35,6 +35,5 @@ module ActionController _process_action_callbacks.find_all{|x| x.kind == :before}.map{|x| x.name} end end - end end diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb index e6e5d3acce..87bc689134 100644 --- a/actionpack/lib/action_controller/new_base/url_for.rb +++ b/actionpack/lib/action_controller/new_base/url_for.rb @@ -25,7 +25,7 @@ module ActionController # by this method. def default_url_options(options = nil) end - + def rewrite_options(options) #:nodoc: if defaults = default_url_options(options) defaults.merge(options) @@ -33,7 +33,7 @@ module ActionController options end end - + def url_for(options = {}) options ||= {} case options @@ -46,4 +46,4 @@ module ActionController end end end -end \ No newline at end of file +end -- cgit v1.2.3 From 4e50a35fa243f6cf7ad567774a9f7c1cb87a1653 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 28 May 2009 11:35:36 -0500 Subject: Break up DependencyModule's dual function of providing a "depend_on" DSL and "included" block DSL into separate modules. But, unify both approaches under AS::Concern. --- .../lib/action_controller/abstract/benchmarker.rb | 2 +- .../lib/action_controller/abstract/callbacks.rb | 2 +- .../lib/action_controller/abstract/helpers.rb | 2 +- .../lib/action_controller/abstract/layouts.rb | 2 +- .../lib/action_controller/abstract/logger.rb | 2 +- .../lib/action_controller/abstract/renderer.rb | 2 +- .../lib/action_controller/base/chained/flash.rb | 2 +- .../base/filter_parameter_logging.rb | 2 +- actionpack/lib/action_controller/base/helpers.rb | 2 +- .../base/request_forgery_protection.rb | 2 +- actionpack/lib/action_controller/base/streaming.rb | 2 +- .../lib/action_controller/base/verification.rb | 2 +- actionpack/lib/action_controller/caching.rb | 2 +- .../action_controller/new_base/compatibility.rb | 2 +- .../action_controller/new_base/conditional_get.rb | 2 +- .../lib/action_controller/new_base/helpers.rb | 2 +- .../lib/action_controller/new_base/hide_actions.rb | 2 +- .../lib/action_controller/new_base/layouts.rb | 2 +- .../action_controller/new_base/rack_convenience.rb | 2 +- .../action_controller/new_base/render_options.rb | 36 ++++++++++------------ .../lib/action_controller/new_base/renderer.rb | 2 +- .../lib/action_controller/new_base/rescuable.rb | 2 +- .../lib/action_controller/new_base/session.rb | 2 +- .../lib/action_controller/new_base/testing.rb | 2 +- .../lib/action_controller/new_base/url_for.rb | 2 +- .../lib/action_controller/testing/integration.rb | 2 +- actionpack/lib/action_view/render/partials.rb | 2 +- 27 files changed, 42 insertions(+), 46 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb index 9be06f48fb..6999329144 100644 --- a/actionpack/lib/action_controller/abstract/benchmarker.rb +++ b/actionpack/lib/action_controller/abstract/benchmarker.rb @@ -1,6 +1,6 @@ module AbstractController module Benchmarker - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on Logger diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index 4314235ba9..6c67315c58 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -1,6 +1,6 @@ module AbstractController module Callbacks - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on ActiveSupport::NewCallbacks diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb index 7b1b197e1d..43832f1e2d 100644 --- a/actionpack/lib/action_controller/abstract/helpers.rb +++ b/actionpack/lib/action_controller/abstract/helpers.rb @@ -1,6 +1,6 @@ module AbstractController module Helpers - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on Renderer diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb index dd38485271..b3f21f7b22 100644 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ b/actionpack/lib/action_controller/abstract/layouts.rb @@ -1,6 +1,6 @@ module AbstractController module Layouts - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on Renderer diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb index ce73888763..d6fa843485 100644 --- a/actionpack/lib/action_controller/abstract/logger.rb +++ b/actionpack/lib/action_controller/abstract/logger.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/logger' module AbstractController module Logger - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern class DelayedLog def initialize(&blk) diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index 374ceb5b74..cd3e87d861 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -2,7 +2,7 @@ require "action_controller/abstract/logger" module AbstractController module Renderer - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on AbstractController::Logger diff --git a/actionpack/lib/action_controller/base/chained/flash.rb b/actionpack/lib/action_controller/base/chained/flash.rb index 2d084ba1ab..04d27bf090 100644 --- a/actionpack/lib/action_controller/base/chained/flash.rb +++ b/actionpack/lib/action_controller/base/chained/flash.rb @@ -26,7 +26,7 @@ module ActionController #:nodoc: # # See docs on the FlashHash class for more details about the flash. module Flash - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern # TODO : Remove the defined? check when new base is the main base depends_on Session if defined?(ActionController::Http) diff --git a/actionpack/lib/action_controller/base/filter_parameter_logging.rb b/actionpack/lib/action_controller/base/filter_parameter_logging.rb index f5a678ca03..9df286ee24 100644 --- a/actionpack/lib/action_controller/base/filter_parameter_logging.rb +++ b/actionpack/lib/action_controller/base/filter_parameter_logging.rb @@ -1,6 +1,6 @@ module ActionController module FilterParameterLogging - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) diff --git a/actionpack/lib/action_controller/base/helpers.rb b/actionpack/lib/action_controller/base/helpers.rb index 96fa7896a9..f74158bc13 100644 --- a/actionpack/lib/action_controller/base/helpers.rb +++ b/actionpack/lib/action_controller/base/helpers.rb @@ -3,7 +3,7 @@ require 'active_support/dependencies' # FIXME: helper { ... } is broken on Ruby 1.9 module ActionController #:nodoc: module Helpers #:nodoc: - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do # Initialize the base module to aggregate its helpers. diff --git a/actionpack/lib/action_controller/base/request_forgery_protection.rb b/actionpack/lib/action_controller/base/request_forgery_protection.rb index 0a0e20e1f1..368c6e9de8 100644 --- a/actionpack/lib/action_controller/base/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/base/request_forgery_protection.rb @@ -3,7 +3,7 @@ module ActionController #:nodoc: end module RequestForgeryProtection - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) diff --git a/actionpack/lib/action_controller/base/streaming.rb b/actionpack/lib/action_controller/base/streaming.rb index 5872ba99a2..5f56c95483 100644 --- a/actionpack/lib/action_controller/base/streaming.rb +++ b/actionpack/lib/action_controller/base/streaming.rb @@ -2,7 +2,7 @@ module ActionController #:nodoc: # Methods for sending arbitrary data and for streaming files to the browser, # instead of rendering. module Streaming - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) diff --git a/actionpack/lib/action_controller/base/verification.rb b/actionpack/lib/action_controller/base/verification.rb index 3fa5a105b1..31654e36f3 100644 --- a/actionpack/lib/action_controller/base/verification.rb +++ b/actionpack/lib/action_controller/base/verification.rb @@ -1,6 +1,6 @@ module ActionController #:nodoc: module Verification #:nodoc: - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 2f2eec10f6..38cf1da6a8 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -24,7 +24,7 @@ module ActionController #:nodoc: # ActionController::Base.cache_store = :mem_cache_store, "localhost" # ActionController::Base.cache_store = MyOwnStore.new("parameter") module Caching - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern autoload :Actions, 'action_controller/caching/actions' autoload :Fragments, 'action_controller/caching/fragments' diff --git a/actionpack/lib/action_controller/new_base/compatibility.rb b/actionpack/lib/action_controller/new_base/compatibility.rb index 1d0cb601e3..f278c2da14 100644 --- a/actionpack/lib/action_controller/new_base/compatibility.rb +++ b/actionpack/lib/action_controller/new_base/compatibility.rb @@ -1,6 +1,6 @@ module ActionController module Rails2Compatibility - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern class ::ActionController::ActionControllerError < StandardError #:nodoc: end diff --git a/actionpack/lib/action_controller/new_base/conditional_get.rb b/actionpack/lib/action_controller/new_base/conditional_get.rb index 38f3d3cf68..8bd6db500b 100644 --- a/actionpack/lib/action_controller/new_base/conditional_get.rb +++ b/actionpack/lib/action_controller/new_base/conditional_get.rb @@ -1,6 +1,6 @@ module ActionController module ConditionalGet - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on RackConvenience diff --git a/actionpack/lib/action_controller/new_base/helpers.rb b/actionpack/lib/action_controller/new_base/helpers.rb index 1dece13114..c2ebd343e3 100644 --- a/actionpack/lib/action_controller/new_base/helpers.rb +++ b/actionpack/lib/action_controller/new_base/helpers.rb @@ -4,7 +4,7 @@ require 'active_support/dependencies' module ActionController module Helpers - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on AbstractController::Helpers diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb index 10b8b582f5..b45e520bee 100644 --- a/actionpack/lib/action_controller/new_base/hide_actions.rb +++ b/actionpack/lib/action_controller/new_base/hide_actions.rb @@ -1,6 +1,6 @@ module ActionController module HideActions - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do extlib_inheritable_accessor :hidden_actions diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb index 9b4057caaa..727358c394 100644 --- a/actionpack/lib/action_controller/new_base/layouts.rb +++ b/actionpack/lib/action_controller/new_base/layouts.rb @@ -1,6 +1,6 @@ module ActionController module Layouts - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on ActionController::Renderer depends_on AbstractController::Layouts diff --git a/actionpack/lib/action_controller/new_base/rack_convenience.rb b/actionpack/lib/action_controller/new_base/rack_convenience.rb index e465acca6e..5dfa7d12f3 100644 --- a/actionpack/lib/action_controller/new_base/rack_convenience.rb +++ b/actionpack/lib/action_controller/new_base/rack_convenience.rb @@ -1,6 +1,6 @@ module ActionController module RackConvenience - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do delegate :headers, :status=, :location=, diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb index f12198a710..04b954134f 100644 --- a/actionpack/lib/action_controller/new_base/render_options.rb +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -1,6 +1,6 @@ module ActionController module RenderOptions - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do extlib_inheritable_accessor :_renderers @@ -36,14 +36,12 @@ module ActionController end end - module RenderOption - extend ActiveSupport::DependencyModule + module RenderOption #:nodoc: + def self.extended(base) + base.extend ActiveSupport::Concern + base.depends_on ::ActionController::RenderOptions - included do - extend ActiveSupport::DependencyModule - depends_on ::ActionController::RenderOptions - - def self.register_renderer(name) + def base.register_renderer(name) included { _add_render_option(name) } end end @@ -51,7 +49,7 @@ module ActionController module Renderers module Json - include RenderOption + extend RenderOption register_renderer :json def _render_json(json, options) @@ -63,7 +61,7 @@ module ActionController end module Js - include RenderOption + extend RenderOption register_renderer :js def _render_js(js, options) @@ -73,7 +71,7 @@ module ActionController end module Xml - include RenderOption + extend RenderOption register_renderer :xml def _render_xml(xml, options) @@ -82,8 +80,8 @@ module ActionController end end - module Rjs - include RenderOption + module RJS + extend RenderOption register_renderer :update def _render_update(proc, options) @@ -94,14 +92,12 @@ module ActionController end module All - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern - included do - include ::ActionController::Renderers::Json - include ::ActionController::Renderers::Js - include ::ActionController::Renderers::Xml - include ::ActionController::Renderers::Rjs - end + depends_on ActionController::Renderers::Json + depends_on ActionController::Renderers::Js + depends_on ActionController::Renderers::Xml + depends_on ActionController::Renderers::RJS end end end diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 737a0d6fcf..e132d4fdbb 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -1,6 +1,6 @@ module ActionController module Renderer - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on AbstractController::Renderer diff --git a/actionpack/lib/action_controller/new_base/rescuable.rb b/actionpack/lib/action_controller/new_base/rescuable.rb index 4450a1131a..029e643d93 100644 --- a/actionpack/lib/action_controller/new_base/rescuable.rb +++ b/actionpack/lib/action_controller/new_base/rescuable.rb @@ -15,7 +15,7 @@ module ActionController #:nodoc: # behavior is achieved by overriding the rescue_action_in_public # and rescue_action_locally methods. module Rescue - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do include ActiveSupport::Rescuable diff --git a/actionpack/lib/action_controller/new_base/session.rb b/actionpack/lib/action_controller/new_base/session.rb index 9ee3e9e136..a585630230 100644 --- a/actionpack/lib/action_controller/new_base/session.rb +++ b/actionpack/lib/action_controller/new_base/session.rb @@ -1,6 +1,6 @@ module ActionController module Session - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on RackConvenience diff --git a/actionpack/lib/action_controller/new_base/testing.rb b/actionpack/lib/action_controller/new_base/testing.rb index 97aadfe78f..e8d210d149 100644 --- a/actionpack/lib/action_controller/new_base/testing.rb +++ b/actionpack/lib/action_controller/new_base/testing.rb @@ -1,6 +1,6 @@ module ActionController module Testing - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on RackConvenience diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb index 87bc689134..902cac4d15 100644 --- a/actionpack/lib/action_controller/new_base/url_for.rb +++ b/actionpack/lib/action_controller/new_base/url_for.rb @@ -1,6 +1,6 @@ module ActionController module UrlFor - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern depends_on RackConvenience diff --git a/actionpack/lib/action_controller/testing/integration.rb b/actionpack/lib/action_controller/testing/integration.rb index cc157816e2..af4ccb7837 100644 --- a/actionpack/lib/action_controller/testing/integration.rb +++ b/actionpack/lib/action_controller/testing/integration.rb @@ -301,7 +301,7 @@ module ActionController # A module used to extend ActionController::Base, so that integration tests # can capture the controller used to satisfy a request. module ControllerCapture #:nodoc: - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do alias_method_chain :initialize, :capture diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index f2429e8cef..eacf117bea 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -171,7 +171,7 @@ module ActionView # <% end %> module Partials extend ActiveSupport::Memoizable - extend ActiveSupport::DependencyModule + extend ActiveSupport::Concern included do attr_accessor :_partial -- cgit v1.2.3 From e23554d79e2db2324144f3ab58f82a895b93fbf5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 28 May 2009 16:56:09 -0500 Subject: Ruby 1.9: flushing the output buffer preserves its encoding --- actionpack/lib/action_view/helpers/capture_helper.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 9e39536653..b4197479a0 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -124,7 +124,11 @@ module ActionView # Use an alternate output buffer for the duration of the block. # Defaults to a new empty string. - def with_output_buffer(buf = '') #:nodoc: + def with_output_buffer(buf = nil) #:nodoc: + unless buf + buf = '' + buf.force_encoding(output_buffer.encoding) if buf.respond_to?(:force_encoding) + end self.output_buffer, old_buffer = buf, output_buffer yield output_buffer @@ -134,9 +138,12 @@ module ActionView # Add the output buffer to the response body and start a new one. def flush_output_buffer #:nodoc: - if output_buffer && output_buffer != '' + if output_buffer && !output_buffer.empty? response.body_parts << output_buffer - self.output_buffer = '' + new = '' + new.force_encoding(output_buffer.encoding) if new.respond_to?(:force_encoding) + self.output_buffer = new + nil end end end -- cgit v1.2.3 From 5ec2c7dc29b36d85b2658465b8a979deb0529d7e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 28 May 2009 17:12:28 -0500 Subject: Ruby 1.9: ERB template encoding using a magic comment at the top of the file --- actionpack/lib/action_view/template/handlers/erb.rb | 6 +----- actionpack/lib/action_view/template/template.rb | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 95f11d6490..d773df7d29 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -16,11 +16,7 @@ module ActionView self.default_format = Mime::HTML def compile(template) - src = ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src - - # Ruby 1.9 prepends an encoding to the source. However this is - # useless because you can only set an encoding on the first line - RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src + ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src end end end diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index f61dd591a5..a9897258d2 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -52,16 +52,26 @@ module ActionView locals_code = locals.keys.map! { |key| "#{key} = local_assigns[:#{key}];" }.join + code = @handler.call(self) + encoding_comment = $1 if code.sub!(/\A(#.*coding.*)\n/, '') + source = <<-end_src def #{method_name}(local_assigns) - old_output_buffer = output_buffer;#{locals_code};#{@handler.call(self)} + old_output_buffer = output_buffer;#{locals_code};#{code} ensure self.output_buffer = old_output_buffer end end_src + if encoding_comment + source = "#{encoding_comment}\n#{source}" + line = -1 + else + line = 0 + end + begin - ActionView::Base::CompiledTemplates.module_eval(source, identifier, 0) + ActionView::Base::CompiledTemplates.module_eval(source, identifier, line) method_name rescue Exception => e # errors from template code if logger = (view && view.logger) @@ -79,4 +89,4 @@ module ActionView "_render_template_#{@identifier.hash}_#{__id__}_#{locals.keys.hash}".gsub('-', "_") end end -end \ No newline at end of file +end -- cgit v1.2.3 From c7c35be8fe30b3e29a5d05edae767f7d6a286911 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 29 May 2009 16:28:54 -0500 Subject: AS::Concern includes InstanceMethods module if it exists --- actionpack/lib/action_controller/base/chained/filters.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/chained/filters.rb b/actionpack/lib/action_controller/base/chained/filters.rb index e121c0129d..f528dd0686 100644 --- a/actionpack/lib/action_controller/base/chained/filters.rb +++ b/actionpack/lib/action_controller/base/chained/filters.rb @@ -1,11 +1,6 @@ module ActionController #:nodoc: module Filters #:nodoc: - def self.included(base) - base.class_eval do - extend ClassMethods - include ActionController::Filters::InstanceMethods - end - end + extend ActiveSupport::Concern class FilterChain < ActiveSupport::Callbacks::CallbackChain #:nodoc: def append_filter_to_chain(filters, filter_type, &block) -- cgit v1.2.3 From 669fd84910586d4c791b6f5bf4320f68ac7845aa Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 29 May 2009 17:03:23 -0500 Subject: AS::Concern redefines "include" to lazy include modules as dependencies --- actionpack/lib/action_controller/abstract/benchmarker.rb | 2 +- actionpack/lib/action_controller/abstract/callbacks.rb | 2 +- actionpack/lib/action_controller/abstract/helpers.rb | 2 +- actionpack/lib/action_controller/abstract/layouts.rb | 2 +- actionpack/lib/action_controller/abstract/renderer.rb | 2 +- actionpack/lib/action_controller/base/chained/flash.rb | 2 +- .../lib/action_controller/base/filter_parameter_logging.rb | 6 ++---- .../lib/action_controller/base/request_forgery_protection.rb | 2 +- actionpack/lib/action_controller/base/streaming.rb | 2 +- actionpack/lib/action_controller/base/verification.rb | 2 +- actionpack/lib/action_controller/new_base/conditional_get.rb | 2 +- actionpack/lib/action_controller/new_base/helpers.rb | 2 +- actionpack/lib/action_controller/new_base/layouts.rb | 4 ++-- actionpack/lib/action_controller/new_base/render_options.rb | 10 +++++----- actionpack/lib/action_controller/new_base/renderer.rb | 2 +- actionpack/lib/action_controller/new_base/session.rb | 2 +- actionpack/lib/action_controller/new_base/testing.rb | 2 +- actionpack/lib/action_controller/new_base/url_for.rb | 2 +- 18 files changed, 24 insertions(+), 26 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb index 6999329144..07294cede3 100644 --- a/actionpack/lib/action_controller/abstract/benchmarker.rb +++ b/actionpack/lib/action_controller/abstract/benchmarker.rb @@ -2,7 +2,7 @@ module AbstractController module Benchmarker extend ActiveSupport::Concern - depends_on Logger + include Logger module ClassMethods def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true) diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index 6c67315c58..c6d3413c30 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -2,7 +2,7 @@ module AbstractController module Callbacks extend ActiveSupport::Concern - depends_on ActiveSupport::NewCallbacks + include ActiveSupport::NewCallbacks included do define_callbacks :process_action, "response_body" diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb index 43832f1e2d..0a2776de9c 100644 --- a/actionpack/lib/action_controller/abstract/helpers.rb +++ b/actionpack/lib/action_controller/abstract/helpers.rb @@ -2,7 +2,7 @@ module AbstractController module Helpers extend ActiveSupport::Concern - depends_on Renderer + include Renderer included do extlib_inheritable_accessor :master_helper_module diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb index b3f21f7b22..273063f74b 100644 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ b/actionpack/lib/action_controller/abstract/layouts.rb @@ -2,7 +2,7 @@ module AbstractController module Layouts extend ActiveSupport::Concern - depends_on Renderer + include Renderer included do extlib_inheritable_accessor :_layout_conditions diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index cd3e87d861..dd58c7cb64 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -4,7 +4,7 @@ module AbstractController module Renderer extend ActiveSupport::Concern - depends_on AbstractController::Logger + include AbstractController::Logger included do attr_internal :formats diff --git a/actionpack/lib/action_controller/base/chained/flash.rb b/actionpack/lib/action_controller/base/chained/flash.rb index 04d27bf090..42c6e430ca 100644 --- a/actionpack/lib/action_controller/base/chained/flash.rb +++ b/actionpack/lib/action_controller/base/chained/flash.rb @@ -29,7 +29,7 @@ module ActionController #:nodoc: extend ActiveSupport::Concern # TODO : Remove the defined? check when new base is the main base - depends_on Session if defined?(ActionController::Http) + include Session if defined?(ActionController::Http) included do # TODO : Remove the defined? check when new base is the main base diff --git a/actionpack/lib/action_controller/base/filter_parameter_logging.rb b/actionpack/lib/action_controller/base/filter_parameter_logging.rb index 9df286ee24..8370ba6fc0 100644 --- a/actionpack/lib/action_controller/base/filter_parameter_logging.rb +++ b/actionpack/lib/action_controller/base/filter_parameter_logging.rb @@ -4,13 +4,11 @@ module ActionController # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) - depends_on AbstractController::Logger + include AbstractController::Logger end included do - if defined?(ActionController::Http) - include InstanceMethodsForNewBase - end + include InstanceMethodsForNewBase end module ClassMethods diff --git a/actionpack/lib/action_controller/base/request_forgery_protection.rb b/actionpack/lib/action_controller/base/request_forgery_protection.rb index 368c6e9de8..a470c8eec1 100644 --- a/actionpack/lib/action_controller/base/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/base/request_forgery_protection.rb @@ -7,7 +7,7 @@ module ActionController #:nodoc: # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) - depends_on AbstractController::Helpers, Session + include AbstractController::Helpers, Session end included do diff --git a/actionpack/lib/action_controller/base/streaming.rb b/actionpack/lib/action_controller/base/streaming.rb index 5f56c95483..73d4bde6c1 100644 --- a/actionpack/lib/action_controller/base/streaming.rb +++ b/actionpack/lib/action_controller/base/streaming.rb @@ -6,7 +6,7 @@ module ActionController #:nodoc: # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) - depends_on ActionController::Renderer + include ActionController::Renderer end DEFAULT_SEND_FILE_OPTIONS = { diff --git a/actionpack/lib/action_controller/base/verification.rb b/actionpack/lib/action_controller/base/verification.rb index 31654e36f3..d87b348ed4 100644 --- a/actionpack/lib/action_controller/base/verification.rb +++ b/actionpack/lib/action_controller/base/verification.rb @@ -4,7 +4,7 @@ module ActionController #:nodoc: # TODO : Remove the defined? check when new base is the main base if defined?(ActionController::Http) - depends_on AbstractController::Callbacks, Session, Flash, Renderer + include AbstractController::Callbacks, Session, Flash, Renderer end # This module provides a class-level method for specifying that certain diff --git a/actionpack/lib/action_controller/new_base/conditional_get.rb b/actionpack/lib/action_controller/new_base/conditional_get.rb index 8bd6db500b..d287ec4994 100644 --- a/actionpack/lib/action_controller/new_base/conditional_get.rb +++ b/actionpack/lib/action_controller/new_base/conditional_get.rb @@ -2,7 +2,7 @@ module ActionController module ConditionalGet extend ActiveSupport::Concern - depends_on RackConvenience + include RackConvenience # Sets the etag, last_modified, or both on the response and renders a # "304 Not Modified" response if the request is already fresh. diff --git a/actionpack/lib/action_controller/new_base/helpers.rb b/actionpack/lib/action_controller/new_base/helpers.rb index c2ebd343e3..e8000be87b 100644 --- a/actionpack/lib/action_controller/new_base/helpers.rb +++ b/actionpack/lib/action_controller/new_base/helpers.rb @@ -6,7 +6,7 @@ module ActionController module Helpers extend ActiveSupport::Concern - depends_on AbstractController::Helpers + include AbstractController::Helpers included do # Set the default directory for helpers diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb index 727358c394..0ff71587d6 100644 --- a/actionpack/lib/action_controller/new_base/layouts.rb +++ b/actionpack/lib/action_controller/new_base/layouts.rb @@ -2,8 +2,8 @@ module ActionController module Layouts extend ActiveSupport::Concern - depends_on ActionController::Renderer - depends_on AbstractController::Layouts + include ActionController::Renderer + include AbstractController::Layouts module ClassMethods def _implied_layout_name diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb index 04b954134f..fc9a02626f 100644 --- a/actionpack/lib/action_controller/new_base/render_options.rb +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -39,7 +39,7 @@ module ActionController module RenderOption #:nodoc: def self.extended(base) base.extend ActiveSupport::Concern - base.depends_on ::ActionController::RenderOptions + base.send :include, ::ActionController::RenderOptions def base.register_renderer(name) included { _add_render_option(name) } @@ -94,10 +94,10 @@ module ActionController module All extend ActiveSupport::Concern - depends_on ActionController::Renderers::Json - depends_on ActionController::Renderers::Js - depends_on ActionController::Renderers::Xml - depends_on ActionController::Renderers::RJS + include ActionController::Renderers::Json + include ActionController::Renderers::Js + include ActionController::Renderers::Xml + include ActionController::Renderers::RJS end end end diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index e132d4fdbb..2fab501302 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -2,7 +2,7 @@ module ActionController module Renderer extend ActiveSupport::Concern - depends_on AbstractController::Renderer + include AbstractController::Renderer def process_action(*) self.formats = request.formats.map {|x| x.to_sym} diff --git a/actionpack/lib/action_controller/new_base/session.rb b/actionpack/lib/action_controller/new_base/session.rb index a585630230..bcedd6e1c7 100644 --- a/actionpack/lib/action_controller/new_base/session.rb +++ b/actionpack/lib/action_controller/new_base/session.rb @@ -2,7 +2,7 @@ module ActionController module Session extend ActiveSupport::Concern - depends_on RackConvenience + include RackConvenience def session @_request.session diff --git a/actionpack/lib/action_controller/new_base/testing.rb b/actionpack/lib/action_controller/new_base/testing.rb index e8d210d149..a4a1116d9e 100644 --- a/actionpack/lib/action_controller/new_base/testing.rb +++ b/actionpack/lib/action_controller/new_base/testing.rb @@ -2,7 +2,7 @@ module ActionController module Testing extend ActiveSupport::Concern - depends_on RackConvenience + include RackConvenience # OMG MEGA HAX def process_with_new_base_test(request, response) diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb index 902cac4d15..7119c14cd3 100644 --- a/actionpack/lib/action_controller/new_base/url_for.rb +++ b/actionpack/lib/action_controller/new_base/url_for.rb @@ -2,7 +2,7 @@ module ActionController module UrlFor extend ActiveSupport::Concern - depends_on RackConvenience + include RackConvenience def process_action(*) initialize_current_url -- cgit v1.2.3 From a1140a10318a79b5dace11679f654c33f477ef57 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 30 May 2009 09:36:08 -0500 Subject: Revert "Only save the session if we're actually writing to it [#2703 state:resolved]" This reverts commit dd98280e38d640f5724887cf8a715b79f0439d2d. --- .../lib/action_dispatch/middleware/session/abstract_store.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 6d109f4624..03761b10bd 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -15,7 +15,6 @@ module ActionDispatch @by = by @env = env @loaded = false - @updated = false end def session_id @@ -33,7 +32,6 @@ module ActionDispatch def []=(key, value) load! unless @loaded super(key.to_s, value) - @updated = true end def to_hash @@ -81,10 +79,6 @@ module ActionDispatch @loaded end - def updated? - @updated - end - def load! stale_session_check! do id, session = @by.send(:load_session, @env) @@ -153,10 +147,7 @@ module ActionDispatch options = env[ENV_SESSION_OPTIONS_KEY] if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) || options[:expire_after] - if session_data.is_a?(AbstractStore::SessionHash) - session_data.send(:load!) if !session_data.send(:loaded?) - return response if !session_data.send(:updated?) - end + session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.send(:loaded?) sid = options[:id] || generate_sid -- cgit v1.2.3 From 249d9a660698a8eca479016f6ebf7cf8087318c8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 29 May 2009 21:45:59 -0500 Subject: Depend on Hash#diff extension --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 89d1a49403..e6d6b5a3ef 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/hash/diff' + module ActionDispatch module Assertions # Suite of assertions to test routes generated by Rails and the handling of requests made to them. -- cgit v1.2.3 From c53057d4fdd6aa55c42fe00ce81e0b04948c4f02 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 29 May 2009 21:46:34 -0500 Subject: html-scanner uses Set and class_inheritable_accessor --- actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb index a992f7d912..51e0868995 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb @@ -1,3 +1,6 @@ +require 'set' +require 'active_support/core_ext/class/inheritable_attributes' + module HTML class Sanitizer def sanitize(text, options = {}) -- cgit v1.2.3 From c79551f02b6437a8e2220a16ec3a32672fb32e90 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 29 May 2009 21:57:33 -0500 Subject: Depend on Hash#slice and Object#try --- actionpack/lib/action_controller/routing/resources.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/routing/resources.rb b/actionpack/lib/action_controller/routing/resources.rb index 86abb7b2f4..05c782d226 100644 --- a/actionpack/lib/action_controller/routing/resources.rb +++ b/actionpack/lib/action_controller/routing/resources.rb @@ -1,3 +1,6 @@ +require 'active_support/core_ext/hash/slice' +require 'active_support/core_ext/object/try' + module ActionController # == Overview # -- cgit v1.2.3 From 9537fd0e3a7625afe4bee75d749647ca1837195a Mon Sep 17 00:00:00 2001 From: Han Kessels Date: Fri, 27 Mar 2009 15:25:27 +0900 Subject: fix for IE incompatibility of :disable_with in submit_tag Signed-off-by: Michael Koziarski --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index daf38fe3da..c96b1fc8d2 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -353,7 +353,8 @@ module ActionView disable_with << ";#{options.delete('onclick')}" if options['onclick'] options["onclick"] = "if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }" - options["onclick"] << "else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }" + options["onclick"] << "else { hiddenCommit = document.createElement('input');hiddenCommit.type = 'hidden';" + options["onclick"] << "hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }" options["onclick"] << "this.setAttribute('originalValue', this.value);this.disabled = true;#{disable_with};" options["onclick"] << "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());" options["onclick"] << "if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" -- cgit v1.2.3 From 94911c7af7f2e1da0a23d64d2055b77bc1f6ece8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 1 Jun 2009 12:33:49 -0700 Subject: Ensure ERB source begins with the encoding comment --- actionpack/lib/action_view/template/handlers/erb.rb | 4 +++- actionpack/lib/action_view/template/template.rb | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index d773df7d29..21272ef089 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -16,7 +16,9 @@ module ActionView self.default_format = Mime::HTML def compile(template) - ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src + magic = $1 if template.source =~ /\A(<%#.*coding:\s*(\S+)\s*-?%>)/ + erb = "#{magic}<% __in_erb_template=true %>#{template.source}" + ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src end end end diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index a9897258d2..e7ea42c2eb 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -53,7 +53,11 @@ module ActionView locals_code = locals.keys.map! { |key| "#{key} = local_assigns[:#{key}];" }.join code = @handler.call(self) - encoding_comment = $1 if code.sub!(/\A(#.*coding.*)\n/, '') + if code.sub!(/\A(#.*coding.*)\n/, '') + encoding_comment = $1 + elsif defined?(Encoding) && Encoding.respond_to?(:default_external) + encoding_comment = "#coding:#{Encoding.default_external}" + end source = <<-end_src def #{method_name}(local_assigns) -- cgit v1.2.3 From 196f780e30fcece25e4d09c12f9b9f7374ebed29 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 1 Jun 2009 15:40:11 -0700 Subject: Get all the callback tests to work on new base --- actionpack/lib/action_controller/abstract/callbacks.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb index c6d3413c30..affe053bac 100644 --- a/actionpack/lib/action_controller/abstract/callbacks.rb +++ b/actionpack/lib/action_controller/abstract/callbacks.rb @@ -26,6 +26,12 @@ module AbstractController end end + def skip_filter(*names, &blk) + skip_before_filter(*names, &blk) + skip_after_filter(*names, &blk) + skip_around_filter(*names, &blk) + end + [:before, :after, :around].each do |filter| class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{filter}_filter(*names, &blk) -- cgit v1.2.3