Permalink
Browse files

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
Yehuda Katz Yehuda Katz
Yehuda Katz authored and Yehuda Katz committed Dec 10, 2009
2 parents 2ecfa81 + ec5434c commit 8b9275340f6845f1fd3ad8fc43d66a95a73b0c2d
Showing with 520 additions and 501 deletions.
  1. +45 −56 actionpack/lib/action_controller/metal/render_options.rb
  2. +307 −292 actionpack/lib/action_dispatch/routing/mapper.rb
  3. +8 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  4. +1 −1 actionpack/test/abstract_unit.rb
  5. +1 −1 actionpack/test/activerecord/active_record_store_test.rb
  6. +11 −11 actionpack/test/controller/action_pack_assertions_test.rb
  7. +3 −3 actionpack/test/controller/base_test.rb
  8. +3 −4 actionpack/test/controller/caching_test.rb
  9. +5 −3 actionpack/test/controller/mime_responds_test.rb
  10. +2 −2 actionpack/test/controller/redirect_test.rb
  11. +14 −0 actionpack/test/controller/render_other_test.rb
  12. +15 −15 actionpack/test/controller/render_test.rb
  13. +2 −2 actionpack/test/controller/render_xml_test.rb
  14. +3 −14 actionpack/test/controller/test_test.rb
  15. +5 −5 actionpack/test/controller/url_rewriter_test.rb
  16. +1 −3 actionpack/test/controller/webservice_test.rb
  17. +1 −1 actionpack/test/dispatch/request/multipart_params_parsing_test.rb
  18. +33 −44 actionpack/test/dispatch/routing_test.rb
  19. +6 −6 actionpack/test/template/atom_feed_helper_test.rb
  20. +2 −2 actionpack/test/template/test_case_test.rb
  21. +4 −4 actionpack/test/template/url_helper_test.rb
  22. +1 −1 railties/lib/rails/generators/actions.rb
  23. +37 −20 railties/lib/rails/generators/rails/app/templates/config/routes.rb
  24. +1 −1 railties/lib/rails/generators/rails/resource/resource_generator.rb
  25. +1 −1 railties/lib/rails/generators/rails/scaffold/USAGE
  26. +1 −1 railties/test/fixtures/plugins/engines/engine/config/routes.rb
  27. +1 −1 railties/test/generators/actions_test.rb
  28. +3 −3 railties/test/generators/resource_generator_test.rb
  29. +2 −2 railties/test/generators/scaffold_generator_test.rb
  30. +1 −1 railties/test/rails_info_controller_test.rb
@@ -1,19 +1,24 @@
module ActionController
+
+ def self.add_renderer(key, &block)
+ RenderOptions.add(key, &block)
+ end
+
module RenderOptions
extend ActiveSupport::Concern
included do
extlib_inheritable_accessor :_renderers
- self._renderers = []
+ self._renderers = {}
end
module ClassMethods
def _write_render_options
- renderers = _renderers.map do |r|
+ renderers = _renderers.map do |name, value|
<<-RUBY_EVAL
- if options.key?(:#{r})
+ if options.key?(:#{name})
_process_options(options)
- return render_#{r}(options[:#{r}], options)
+ return _render_option_#{name}(options[:#{name}], options)
end
RUBY_EVAL
end
@@ -25,79 +30,63 @@ def _handle_render_options(options)
RUBY_EVAL
end
- def _add_render_option(name)
- _renderers << name
+ def use_renderers(*args)
+ args.each do |key|
+ _renderers[key] = RENDERERS[key]
+ end
_write_render_options
end
+ alias use_renderer use_renderers
end
def render_to_body(options)
_handle_render_options(options) || super
end
- end
-
- module RenderOption #:nodoc:
- def self.extended(base)
- base.extend ActiveSupport::Concern
- base.send :include, ::ActionController::RenderOptions
- def base.register_renderer(name)
- included { _add_render_option(name) }
- end
+ RENDERERS = {}
+ def self.add(key, &block)
+ define_method("_render_option_#{key}", &block)
+ RENDERERS[key] = block
+ All._write_render_options
end
- end
- module RenderOptions
- module Json
- extend RenderOption
- register_renderer :json
+ module All
+ extend ActiveSupport::Concern
+ include RenderOptions
- 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
+ INCLUDED = []
+ included do
+ self._renderers = RENDERERS
+ _write_render_options
+ INCLUDED << self
end
- end
-
- module Js
- extend RenderOption
- register_renderer :js
- def render_js(js, options)
- self.content_type ||= Mime::JS
- self.response_body = js.respond_to?(:to_js) ? js.to_js : js
+ def self._write_render_options
+ INCLUDED.each(&:_write_render_options)
end
end
- module Xml
- extend RenderOption
- register_renderer :xml
-
- def render_xml(xml, options)
- self.content_type ||= Mime::XML
- self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
- end
+ add :json do |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
- module RJS
- extend RenderOption
- register_renderer :update
-
- def render_update(proc, options)
- generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
- self.content_type = Mime::JS
- self.response_body = generator.to_s
- end
+ add :js do |js, options|
+ self.content_type ||= Mime::JS
+ self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
- module All
- extend ActiveSupport::Concern
+ add :xml do |xml, options|
+ self.content_type ||= Mime::XML
+ self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
+ end
- include ActionController::RenderOptions::Json
- include ActionController::RenderOptions::Js
- include ActionController::RenderOptions::Xml
- include ActionController::RenderOptions::RJS
+ add :update do |proc, options|
+ generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
+ self.content_type = Mime::JS
+ self.response_body = generator.to_s
end
end
end
Oops, something went wrong.

0 comments on commit 8b92753

Please sign in to comment.