aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/new_base
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-21 14:34:42 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-21 14:36:00 -0700
commit2daac47d585c5b8f37e4749d6a9a3aea4b989bd0 (patch)
treec6c7f7f66ca69f0f8012d7672645bfbcd86c6b3d /actionpack/lib/action_controller/new_base
parente693f45e155a81b6c337b8766870b56716a05105 (diff)
downloadrails-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/new_base')
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb2
-rw-r--r--actionpack/lib/action_controller/new_base/render_options.rb39
2 files changed, 41 insertions, 0 deletions
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