diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-21 14:34:42 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-21 14:36:00 -0700 |
commit | 2daac47d585c5b8f37e4749d6a9a3aea4b989bd0 (patch) | |
tree | c6c7f7f66ca69f0f8012d7672645bfbcd86c6b3d /actionpack/lib/action_controller | |
parent | e693f45e155a81b6c337b8766870b56716a05105 (diff) | |
download | rails-2daac47d585c5b8f37e4749d6a9a3aea4b989bd0.tar.gz rails-2daac47d585c5b8f37e4749d6a9a3aea4b989bd0.tar.bz2 rails-2daac47d585c5b8f37e4749d6a9a3aea4b989bd0.zip |
Added the ability to register methods to handle specific render option keys and render :json
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/new_base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/render_options.rb | 39 |
3 files changed, 43 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb index 58c7382661..95808decd5 100644 --- a/actionpack/lib/action_controller/new_base.rb +++ b/actionpack/lib/action_controller/new_base.rb @@ -7,6 +7,8 @@ module ActionController autoload :Rails2Compatibility, "action_controller/new_base/compatibility" autoload :Redirector, "action_controller/new_base/redirector" autoload :Renderer, "action_controller/new_base/renderer" + autoload :RenderOptions, "action_controller/new_base/render_options" + autoload :Renderers, "action_controller/new_base/render_options" autoload :Rescue, "action_controller/new_base/rescuable" autoload :Testing, "action_controller/new_base/testing" autoload :UrlFor, "action_controller/new_base/url_for" diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index b8674d5099..6e1f92c45d 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -11,6 +11,8 @@ module ActionController include ActionController::UrlFor include ActionController::Redirector include ActionController::Renderer + include ActionController::RenderOptions + include ActionController::Renderers::Json include ActionController::Layouts include ActionController::ConditionalGet diff --git a/actionpack/lib/action_controller/new_base/render_options.rb b/actionpack/lib/action_controller/new_base/render_options.rb new file mode 100644 index 0000000000..e7ed2bd278 --- /dev/null +++ b/actionpack/lib/action_controller/new_base/render_options.rb @@ -0,0 +1,39 @@ +module ActionController + module RenderOptions + extend ActiveSupport::DependencyModule + + included do + extlib_inheritable_accessor :_renderers + self._renderers = [] + end + + def render_to_body(options) + _renderers.each do |renderer| + if options.key?(renderer) + _process_options(options) + return send("_render_#{renderer}", options[renderer], options) + end + end + super + end + end + + module Renderers + module Json + extend ActiveSupport::DependencyModule + + depends_on RenderOptions + + included do + _renderers << :json + end + + 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.response_body = json + end + end + end +end
\ No newline at end of file |