Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 98 lines (82 sloc) 2.533 kb
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored
1 require 'active_support/core_ext/class/attribute'
76f024a @fxn adds missing requires for Object#blank? and Object#present?
fxn authored
2 require 'active_support/core_ext/object/blank'
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored
3
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
4 module ActionController
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
5 def self.add_renderer(key, &block)
36c13cc @dhh Rename RenderOptions to Renderers
dhh authored
6 Renderers.add(key, &block)
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
7 end
8
36c13cc @dhh Rename RenderOptions to Renderers
dhh authored
9 module Renderers
4e50a35 @josh Break up DependencyModule's dual function of providing a "depend_on" DSL...
josh authored
10 extend ActiveSupport::Concern
de20324 @josh Revert "Revert "Whitespace!""
josh authored
11
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
12 included do
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored
13 class_attribute :_renderers
14 self._renderers = {}.freeze
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
15 end
de20324 @josh Revert "Revert "Whitespace!""
josh authored
16
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
17 module ClassMethods
18 def _write_render_options
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
19 renderers = _renderers.map do |name, value|
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
20 <<-RUBY_EVAL
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
21 if options.key?(:#{name})
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
22 _process_options(options)
60ca754 @josevalim Remove the renderer option from the hash.
josevalim authored
23 return _render_option_#{name}(options.delete(:#{name}), options)
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
24 end
25 RUBY_EVAL
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
26 end
de20324 @josh Revert "Revert "Whitespace!""
josh authored
27
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
28 class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
29 def _handle_render_options(options)
30 #{renderers.join}
31 end
32 RUBY_EVAL
33 end
de20324 @josh Revert "Revert "Whitespace!""
josh authored
34
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
35 def use_renderers(*args)
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored
36 new = _renderers.dup
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
37 args.each do |key|
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored
38 new[key] = RENDERERS[key]
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
39 end
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored
40 self._renderers = new.freeze
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
41 _write_render_options
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
42 end
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
43 alias use_renderer use_renderers
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
44 end
de20324 @josh Revert "Revert "Whitespace!""
josh authored
45
9d3d774 Update render options to remove performance implications of many render ...
Yehuda Katz + Carl Lerche authored
46 def render_to_body(options)
47 _handle_render_options(options) || super
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
48 end
ad1c90d Added the :xml render option
Yehuda Katz + Carl Lerche authored
49
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
50 RENDERERS = {}
51 def self.add(key, &block)
52 define_method("_render_option_#{key}", &block)
53 RENDERERS[key] = block
54 All._write_render_options
ad1c90d Added the :xml render option
Yehuda Katz + Carl Lerche authored
55 end
56
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
57 module All
58 extend ActiveSupport::Concern
36c13cc @dhh Rename RenderOptions to Renderers
dhh authored
59 include Renderers
de20324 @josh Revert "Revert "Whitespace!""
josh authored
60
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
61 INCLUDED = []
62 included do
63 self._renderers = RENDERERS
64 _write_render_options
65 INCLUDED << self
de20324 @josh Revert "Revert "Whitespace!""
josh authored
66 end
7b3fb1d Got controller/render_js_test.rb to pass on new base
Yehuda Katz + Carl Lerche authored
67
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
68 def self._write_render_options
69 INCLUDED.each(&:_write_render_options)
7b3fb1d Got controller/render_js_test.rb to pass on new base
Yehuda Katz + Carl Lerche authored
70 end
71 end
72
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
73 add :json do |json, options|
4e2a981 @neerajdotname If a user wants json output then try best to render json output. In such...
neerajdotname authored
74 json = json.to_json(options) unless json.kind_of?(String)
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
75 json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
76 self.content_type ||= Mime::JSON
77 self.response_body = json
ad1c90d Added the :xml render option
Yehuda Katz + Carl Lerche authored
78 end
6923b39 Added the :rjs render option
Yehuda Katz + Carl Lerche authored
79
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
80 add :js do |js, options|
81 self.content_type ||= Mime::JS
81fb742 @josevalim Always downstream given options in :json, :xml and :js renderers and add...
josevalim authored
82 self.response_body = js.respond_to?(:to_js) ? js.to_js(options) : js
6923b39 Added the :rjs render option
Yehuda Katz + Carl Lerche authored
83 end
69a1ea8 Created an ActionController::Renderers::All that includes all the defaul...
Yehuda Katz + Carl Lerche authored
84
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
85 add :xml do |xml, options|
86 self.content_type ||= Mime::XML
81fb742 @josevalim Always downstream given options in :json, :xml and :js renderers and add...
josevalim authored
87 self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml(options) : xml
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
88 end
69a1ea8 Created an ActionController::Renderers::All that includes all the defaul...
Yehuda Katz + Carl Lerche authored
89
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
90 add :update do |proc, options|
71c9337 All tests pass without memoizing view_context
Carlhuda authored
91 view_context = self.view_context
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
92 generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
f2c0a35 @josevalim Finish cleaning up rendering stack from views and move assigns evaluatio...
josevalim authored
93 self.content_type = Mime::JS
f9d570b Simpler RenderOption API -- removes the need for registering the types a...
Carlhuda authored
94 self.response_body = generator.to_s
69a1ea8 Created an ActionController::Renderers::All that includes all the defaul...
Yehuda Katz + Carl Lerche authored
95 end
2daac47 Added the ability to register methods to handle specific render option k...
Yehuda Katz + Carl Lerche authored
96 end
1fa7e33 @jeremy Ruby 1.9 compat: don't rely on lexical scoping since the included block ...
jeremy authored
97 end
Something went wrong with that request. Please try again.