diff options
author | José Valim <jose.valim@gmail.com> | 2009-11-11 08:16:25 -0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-11-11 08:16:25 -0200 |
commit | 01ae99c681d31803f3a29f8305c9a041aa456660 (patch) | |
tree | 7fdb9e32b743aeb254854371349cecfd2499defa /actionpack/lib | |
parent | d002826e54415a340e55fdbf363d005faebf8fc5 (diff) | |
parent | fca32eb6c5b41e4f19a25b7b246c4a8a3d763667 (diff) | |
download | rails-01ae99c681d31803f3a29f8305c9a041aa456660.tar.gz rails-01ae99c681d31803f3a29f8305c9a041aa456660.tar.bz2 rails-01ae99c681d31803f3a29f8305c9a041aa456660.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack/lib')
17 files changed, 99 insertions, 63 deletions
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 8293e79b0a..c71cef42b2 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -89,7 +89,7 @@ module AbstractController # ==== Returns # String:: A template name def _implied_layout_name - name.underscore + name && name.underscore end # Takes the specified layout and creates a _layout method to be called @@ -100,7 +100,7 @@ module AbstractController # name, return that string. Otherwise, use the superclass' # layout (which might also be implied) def _write_layout_method - case @_layout + case defined?(@_layout) ? @_layout : nil when String self.class_eval %{def _layout(details) #{@_layout.inspect} end} when Symbol @@ -119,17 +119,19 @@ module AbstractController when true raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" when nil - self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def _layout(details) - self.class.cache_layout(details) do - if template_exists?("#{_implied_layout_name}", details, :_prefix => "layouts") - "#{_implied_layout_name}" - else - super + if name + self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def _layout(details) + self.class.cache_layout(details) do + if template_exists?("#{_implied_layout_name}", details, :_prefix => "layouts") + "#{_implied_layout_name}" + else + super + end end end - end - RUBY + RUBY + end end self.class_eval { private :_layout } end diff --git a/actionpack/lib/abstract_controller/rendering_controller.rb b/actionpack/lib/abstract_controller/rendering_controller.rb index 0aae2b18e9..7054b9cf26 100644 --- a/actionpack/lib/abstract_controller/rendering_controller.rb +++ b/actionpack/lib/abstract_controller/rendering_controller.rb @@ -12,6 +12,12 @@ module AbstractController self._view_paths ||= ActionView::PathSet.new end + # Initialize controller with nil formats. + def initialize(*) #:nodoc: + @_formats = nil + super + end + # An instance of a view class. The default view class is ActionView::Base # # The view class must have the following methods: diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 6f89bf5d67..60b3f9a89b 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -49,7 +49,7 @@ module ActionController # and response object available. You might wish to control the # environment and response manually for performance reasons. - attr_internal :status, :headers, :content_type, :app, :response + attr_internal :status, :headers, :content_type, :response def initialize(*) @_headers = {} @@ -69,7 +69,7 @@ module ActionController end # :api: private - def call(name, env) + def dispatch(name, env) @_env = env process(name) to_a @@ -95,7 +95,7 @@ module ActionController end def call(env) - controller = @controller.new.call(@action, env) + @controller.new.dispatch(@action, env) end end diff --git a/actionpack/lib/action_controller/metal/rack_convenience.rb b/actionpack/lib/action_controller/metal/rack_convenience.rb index a80569c530..131d20114d 100644 --- a/actionpack/lib/action_controller/metal/rack_convenience.rb +++ b/actionpack/lib/action_controller/metal/rack_convenience.rb @@ -8,7 +8,7 @@ module ActionController attr_internal :request end - def call(name, env) + def dispatch(action, env) @_request = ActionDispatch::Request.new(env) @_response = ActionDispatch::Response.new @_response.request = request diff --git a/actionpack/lib/action_controller/metal/streaming.rb b/actionpack/lib/action_controller/metal/streaming.rb index 4761763a26..43c661bef4 100644 --- a/actionpack/lib/action_controller/metal/streaming.rb +++ b/actionpack/lib/action_controller/metal/streaming.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/string/bytesize' - module ActionController #:nodoc: # Methods for sending arbitrary data and for streaming files to the browser, # instead of rendering. diff --git a/actionpack/lib/action_controller/middleware.rb b/actionpack/lib/action_controller/middleware.rb index fac0ed2645..17275793b7 100644 --- a/actionpack/lib/action_controller/middleware.rb +++ b/actionpack/lib/action_controller/middleware.rb @@ -1,34 +1,34 @@ module ActionController class Middleware < Metal class ActionMiddleware - def initialize(controller) - @controller = controller + def initialize(controller, app) + @controller, @app = controller, app end def call(env) - controller = @controller.allocate - controller.send(:initialize) - controller.app = @app - controller._call(env) + @controller.build(@app).dispatch(:index, env) end + end + + class << self + alias build new - def app=(app) - @app = app + def new(app) + ActionMiddleware.new(self, app) end end - - def self.new(app) - middleware = ActionMiddleware.new(self) - middleware.app = app - middleware + + attr_internal :app + + def process(action) + response = super + self.status, self.headers, self.response_body = response if response.is_a?(Array) + response end - - def _call(env) - @_env = env - @_request = ActionDispatch::Request.new(env) - @_response = ActionDispatch::Response.new - @_response.request = @_request - process(:index) + + def initialize(app) + super() + @_app = app end def index diff --git a/actionpack/lib/action_controller/translation.rb b/actionpack/lib/action_controller/translation.rb index 9bb63cdb15..65e9eddb0a 100644 --- a/actionpack/lib/action_controller/translation.rb +++ b/actionpack/lib/action_controller/translation.rb @@ -1,12 +1,12 @@ module ActionController module Translation def translate(*args) - I18n.translate *args + I18n.translate(*args) end alias :t :translate def localize(*args) - I18n.localize *args + I18n.localize(*args) end alias :l :localize end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 75be2cc260..b3bb8c623f 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -5,7 +5,7 @@ require 'strscan' require 'active_support/memoizable' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/hash/indifferent_access' -require 'active_support/core_ext/object/tap' +require 'active_support/core_ext/string/access' module ActionDispatch class Request < Rack::Request @@ -166,7 +166,7 @@ module ActionDispatch @env["action_dispatch.request.formats"] ||= if parameters[:format] - [Mime[parameters[:format]]] + Array.wrap(Mime[parameters[:format]]) elsif xhr? || (accept && !accept.include?(?,)) accepts else diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index 4f71ea6165..3b27309f58 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -1,3 +1,5 @@ +require "active_support/inflector/methods" + module ActionDispatch class MiddlewareStack < Array class Middleware @@ -32,7 +34,7 @@ module ActionDispatch elsif @klass.respond_to?(:call) @klass.call else - @klass.to_s.constantize + ActiveSupport::Inflector.constantize(@klass.to_s) end end @@ -53,7 +55,7 @@ module ActionDispatch when Class klass == middleware else - klass == middleware.to_s.constantize + klass == ActiveSupport::Inflector.constantize(middleware.to_s) end end diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index b9c377db2c..68ed1e3340 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -1,6 +1,4 @@ -require 'active_support/core_ext/object/conversions' -require 'active_support/core_ext/boolean/conversions' -require 'active_support/core_ext/nil/conversions' +require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/regexp' module ActionDispatch diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index d6d822842b..ebfb4c9be2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -20,15 +20,20 @@ module ActionDispatch return self end - controller(resource) do + singular = resource.to_s + plural = singular.pluralize + + controller(plural) do namespace(resource) do with_scope_level(:resource) do yield if block_given? - get "", :to => :show + get "", :to => :show, :as => "#{singular}" post "", :to => :create put "", :to => :update - delete "", :to => :destory + delete "", :to => :destroy + get "new", :to => :new, :as => "new_#{singular}" + get "edit", :to => :edit, :as => "edit_#{singular}" end end end @@ -54,22 +59,25 @@ module ActionDispatch return self end + plural = resource.to_s + singular = plural.singularize + controller(resource) do namespace(resource) do with_scope_level(:resources) do yield if block_given? member do - get "", :to => :show + get "", :to => :show, :as => "#{singular}" put "", :to => :update - delete "", :to => :destory - get "edit", :to => :edit + delete "", :to => :destroy + get "edit", :to => :edit, :as => "edit_#{singular}" end collection do - get "", :to => :index + get "", :to => :index, :as => "#{plural}" post "", :to => :create - get "new", :to => :new + get "new", :to => :new, :as => "new_#{singular}" end end end @@ -221,6 +229,10 @@ module ActionDispatch map_method(:delete, *args, &block) end + def root(options = {}) + match '/', options.merge(:as => :root) + end + def match(*args) options = args.last.is_a?(Hash) ? args.pop : {} diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 93617e826d..28e5b806da 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -20,7 +20,12 @@ module ActionDispatch params = env[PARAMETERS_KEY] merge_default_action!(params) split_glob_param!(params) if @glob_param - params.each { |key, value| params[key] = URI.unescape(value) if value.is_a?(String) } + params.each do |key, value| + if value.is_a?(String) + value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding) + params[key] = URI.unescape(value) + end + end if env['action_controller.recognize'] [200, {}, params] diff --git a/actionpack/lib/action_dispatch/testing/assertions.rb b/actionpack/lib/action_dispatch/testing/assertions.rb index 96f08f2355..0e4a92048f 100644 --- a/actionpack/lib/action_dispatch/testing/assertions.rb +++ b/actionpack/lib/action_dispatch/testing/assertions.rb @@ -1,8 +1,21 @@ module ActionDispatch module Assertions - %w(response selector tag dom routing model).each do |kind| - require "action_dispatch/testing/assertions/#{kind}" - include const_get("#{kind.camelize}Assertions") + autoload :DomAssertions, 'action_dispatch/testing/assertions/dom' + autoload :ModelAssertions, 'action_dispatch/testing/assertions/model' + autoload :ResponseAssertions, 'action_dispatch/testing/assertions/response' + autoload :RoutingAssertions, 'action_dispatch/testing/assertions/routing' + autoload :SelectorAssertions, 'action_dispatch/testing/assertions/selector' + autoload :TagAssertions, 'action_dispatch/testing/assertions/tag' + + extend ActiveSupport::Concern + + included do + include DomAssertions + include ModelAssertions + include ResponseAssertions + include RoutingAssertions + include SelectorAssertions + include TagAssertions end end end diff --git a/actionpack/lib/action_view/erb/util.rb b/actionpack/lib/action_view/erb/util.rb index f767a5e27e..aef859b3ac 100644 --- a/actionpack/lib/action_view/erb/util.rb +++ b/actionpack/lib/action_view/erb/util.rb @@ -23,6 +23,7 @@ class ERB end end + undef :h alias h html_escape module_function :html_escape diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 4aed10f640..564f12c955 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -21,7 +21,7 @@ module ActionView # Delegates to I18n.localize with no additional functionality. def localize(*args) - I18n.localize *args + I18n.localize(*args) end alias :l :localize diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index fc89726670..7006a5b968 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -71,12 +71,10 @@ module ActionView # In this case, the layout would receive the block passed into <tt>render :layout</tt>, # and the Struct specified in the layout would be passed into the block. The result # would be <html>Hello David</html>. - def _layout_for(name = nil) + def _layout_for(name = nil, &block) return @_content_for[name || :layout] if !block_given? || name - with_output_buffer do - return yield - end + capture(&block) end def _render_inline(inline, layout, options) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 8beda24aba..86bbad822d 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -120,6 +120,7 @@ module ActionView def _view view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) view.class.send :include, _helpers + view.output_buffer = self.output_buffer view end |