Skip to content
This repository
Newer
Older
100644 179 lines (151 sloc) 5.533 kb
39b708be » josh
2009-12-12 rendering controller needs base
1 require "abstract_controller/base"
ffe001f1 » wycats
2010-06-02 Changes made while working on upgrading cells to Rails 3
2 require "action_view"
0f8a6ebb » sikachu
2011-04-14 Fix missing requires in Action Mailer
3 require "active_support/core_ext/object/instance_variables"
d1157e72 » wycats
2009-02-27 AbstractController now supports layouts and rendering
4
b1f078bd » wycats
2009-02-24 First, very early, AbstractController code. More to come
5 module AbstractController
4b4e517b » josh
2009-12-12 Relocate AbstractController exceptions into their proper parent modules
6 class DoubleRenderError < Error
7 DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
8
9 def initialize(message = nil)
10 super(message || DEFAULT_MESSAGE)
11 end
12 end
13
07cf49aa » josevalim
2010-03-10 Optimize and clean up how details key get expired.
14 # This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
15 # it will trigger the lookup_context and consequently expire the cache.
16 class I18nProxy < ::I18n::Config #:nodoc:
262b2ea8 » josevalim
2011-01-19 Solve SystemStackError when changing locale inside ActionMailer [#5329
17 attr_reader :original_config, :lookup_context
07cf49aa » josevalim
2010-03-10 Optimize and clean up how details key get expired.
18
262b2ea8 » josevalim
2011-01-19 Solve SystemStackError when changing locale inside ActionMailer [#5329
19 def initialize(original_config, lookup_context)
20 original_config = original_config.original_config if original_config.respond_to?(:original_config)
21 @original_config, @lookup_context = original_config, lookup_context
07cf49aa » josevalim
2010-03-10 Optimize and clean up how details key get expired.
22 end
23
24 def locale
262b2ea8 » josevalim
2011-01-19 Solve SystemStackError when changing locale inside ActionMailer [#5329
25 @original_config.locale
07cf49aa » josevalim
2010-03-10 Optimize and clean up how details key get expired.
26 end
27
28 def locale=(value)
3fc609ee » josevalim
2010-04-12 Fix ActionMailer test broken in 99d5459
29 @lookup_context.locale = value
07cf49aa » josevalim
2010-03-10 Optimize and clean up how details key get expired.
30 end
31 end
32
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
33 module Rendering
34 extend ActiveSupport::Concern
35 include AbstractController::ViewPaths
36
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
37 included do
c4ef3d34 » josevalim
2011-12-24 Remove unecessary config_accessors.
38 class_attribute :protected_instance_variables
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
39 self.protected_instance_variables = []
40 end
41
07cf49aa » josevalim
2010-03-10 Optimize and clean up how details key get expired.
42 # Overwrite process to setup I18n proxy.
43 def process(*) #:nodoc:
44 old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
45 super
46 ensure
47 I18n.config = old_config
48 end
49
a5d80f84 » Carlhuda
2010-03-18 Each controller class has it's own view context subclass. This remove…
50 module ClassMethods
51 def view_context_class
52 @view_context_class ||= begin
1632a3a4 » josevalim
2011-05-04 More AV::Base cleanup.
53 routes = _routes if respond_to?(:_routes)
54 helpers = _helpers if respond_to?(:_helpers)
55 ActionView::Base.prepare(routes, helpers)
a5d80f84 » Carlhuda
2010-03-18 Each controller class has it's own view context subclass. This remove…
56 end
57 end
58 end
59
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
60 attr_internal_writer :view_context_class
61
a5d80f84 » Carlhuda
2010-03-18 Each controller class has it's own view context subclass. This remove…
62 def view_context_class
efc28a7f » josevalim
2011-12-08 Some small optimizations and improvements to benchmark code.
63 @_view_context_class ||= self.class.view_context_class
995f5703 » wycats
2010-03-18 We seem to have removed the URL helpers from ActionView subclasses...
64 end
65
be371993 » Yehuda Katz + Carl Lerche
2009-06-08 More documentation work on AbstractController
66 # An instance of a view class. The default view class is ActionView::Base
67 #
68 # The view class must have the following methods:
a5d80f84 » Carlhuda
2010-03-18 Each controller class has it's own view context subclass. This remove…
69 # View.new[lookup_context, assigns, controller]
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
70 # Create a new ActionView instance for a controller
a5d80f84 » Carlhuda
2010-03-18 Each controller class has it's own view context subclass. This remove…
71 # View#render[options]
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
72 # Returns String with the rendered template
be371993 » Yehuda Katz + Carl Lerche
2009-06-08 More documentation work on AbstractController
73 #
ac956c4a » Yehuda Katz
2010-02-16 Update AP to start locking down a public API. This work is parallel t…
74 # Override this method in a module to change the default behavior.
af375a5e » wycats
2009-08-06 Replace _action_view with view_context to reflect that it is public a…
75 def view_context
b7357613 » josevalim
2011-05-01 Introduce view renderer.
76 view_context_class.new(view_renderer, view_assigns, self)
77 end
78
79 # Returns an object that is able to render templates.
80 def view_renderer
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
81 @_view_renderer ||= ActionView::Renderer.new(lookup_context)
b1f078bd » wycats
2009-02-24 First, very early, AbstractController code. More to come
82 end
de203245 » josh
2009-05-28 Revert "Revert "Whitespace!""
83
f2c0a353 » josevalim
2010-03-12 Finish cleaning up rendering stack from views and move assigns evalua…
84 # Normalize arguments, options and then delegates render_to_body and
85 # sticks the result in self.response_body.
8e2fd54b » josevalim
2010-01-20 Bring normalize behavior to AbstractController::Rendering
86 def render(*args, &block)
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
87 options = _normalize_render(*args, &block)
88 self.response_body = render_to_body(options)
209fb519 » wycats
2010-04-04 render_to_string should have the identical signature as render
89 end
90
91 # Raw rendering of a template to a string. Just convert the results of
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
92 # render_response into a String.
209fb519 » wycats
2010-04-04 render_to_string should have the identical signature as render
93 # :api: plugin
94 def render_to_string(*args, &block)
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
95 options = _normalize_render(*args, &block)
a66c9172 » josevalim
2011-04-19 Do not inherit from Rack::Response, remove a shit-ton of unused code.
96 render_to_body(options)
e0447023 » wycats
2009-03-18 Implemented basic template rendering in AC::Base2:
97 end
de203245 » josh
2009-05-28 Revert "Revert "Whitespace!""
98
f49e3441 » jeremy
2009-04-21 Reinstate Base#render_to_string. Introduce AbstractController#render_…
99 # Raw rendering of a template to a Rack-compatible body.
890321e5 » wycats
2009-03-19 Get very basic layouts working.
100 # :api: plugin
df42d26f » jeremy
2009-04-17 Rename render_to_string to render_to_body since it may return any Rac…
101 def render_to_body(options = {})
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
102 _process_options(options)
103 _render_template(options)
d1157e72 » wycats
2009-02-27 AbstractController now supports layouts and rendering
104 end
105
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
106 # Find and renders a template based on the options given.
f2c0a353 » josevalim
2010-03-12 Finish cleaning up rendering stack from views and move assigns evalua…
107 # :api: private
108 def _render_template(options) #:nodoc:
1eb61894 » drogus
2012-03-15 Fix #5440 - multiple render_to_string breaks partials formats
109 lookup_context.rendered_format = nil if options[:formats]
f9849070 » josevalim
2011-05-03 Add a shared entry point for AV and AC render which can be used as ex…
110 view_renderer.render(view_context, options)
de203245 » josh
2009-05-28 Revert "Revert "Whitespace!""
111 end
d1157e72 » wycats
2009-02-27 AbstractController now supports layouts and rendering
112
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
113 DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
d42bb684 » josevalim
2011-05-06 More updates to ivars list.
114 @_action_name @_response_body @_formats @_prefixes @_config
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
115 @_view_context_class @_view_renderer @_lookup_context
116 )
117
71c9337f » Carlhuda
2010-03-18 All tests pass without memoizing view_context
118 # This method should return a hash with assigns.
119 # You can overwrite this configuration per controller.
120 # :api: public
121 def view_assigns
122 hash = {}
123 variables = instance_variable_names
894bdbd5 » josevalim
2011-05-06 Move variables to underscore format, update protected instance variab…
124 variables -= protected_instance_variables
125 variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
d3f87654 » spastorino
2010-11-20 Avoid range object creation
126 variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) }
71c9337f » Carlhuda
2010-03-18 All tests pass without memoizing view_context
127 hash
128 end
129
6e8fe1bf » josevalim
2011-10-02 TestCase should respect the view_assigns API instead of pulling varia…
130 private
131
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
132 # Normalize args and options.
133 # :api: private
134 def _normalize_render(*args, &block)
135 options = _normalize_args(*args, &block)
136 _normalize_options(options)
137 options
138 end
139
140 # Normalize args by converting render "foo" to render :action => "foo" and
68cda695 » josevalim
2010-03-08 Speed up performance in resolvers by adding fallbacks just when requi…
141 # render "foo/bar" to render :file => "foo/bar".
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
142 # :api: plugin
34b21804 » josevalim
2010-03-08 More refactoring. Split _normalize_args and _normalize_options concerns.
143 def _normalize_args(action=nil, options={})
d618b7e3 » josevalim
2010-01-22 Ensure strings given to render with slash are rendered relative to th…
144 case action
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
145 when NilClass
d618b7e3 » josevalim
2010-01-22 Ensure strings given to render with slash are rendered relative to th…
146 when Hash
b1ffd65b » spastorino
2010-11-18 Useless assignation
147 options = action
d618b7e3 » josevalim
2010-01-22 Ensure strings given to render with slash are rendered relative to th…
148 when String, Symbol
149 action = action.to_s
68cda695 » josevalim
2010-03-08 Speed up performance in resolvers by adding fallbacks just when requi…
150 key = action.include?(?/) ? :file : :action
151 options[key] = action
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
152 else
555b7cd0 » spastorino
2010-11-18 Don't merge just directly add to the action to the :partial key
153 options[:partial] = action
d618b7e3 » josevalim
2010-01-22 Ensure strings given to render with slash are rendered relative to th…
154 end
155
156 options
157 end
158
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
159 # Normalize options.
160 # :api: plugin
34b21804 » josevalim
2010-03-08 More refactoring. Split _normalize_args and _normalize_options concerns.
161 def _normalize_options(options)
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
162 if options[:partial] == true
163 options[:partial] = action_name
164 end
34b21804 » josevalim
2010-03-08 More refactoring. Split _normalize_args and _normalize_options concerns.
165
d6bd606b » josevalim
2011-04-15 render :once, YAGNI.
166 if (options.keys & [:partial, :file, :template]).empty?
ddd85ef9 » artemave
2010-09-17 #948 template_inheritance
167 options[:prefixes] ||= _prefixes
43d5504f » josevalim
2009-10-18 Move all render and layout pieces required in ActionMailer from Actio…
168 end
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
169
170 options[:template] ||= (options[:action] || action_name).to_s
171 options
df85ab41 » josevalim
2010-02-24 Renamed LocalizedCache to DetailsCache.
172 end
173
4f044528 » josevalim
2011-04-18 Slightly reorganize rendering stack.
174 # Process extra options.
175 # :api: plugin
0a853809 » josevalim
2010-03-08 Finally moved the find template logic to the views.
176 def _process_options(options)
0cf16ddb » josevalim
2009-10-21 Improve AbstractController layouts coverage.
177 end
b1f078bd » wycats
2009-02-24 First, very early, AbstractController code. More to come
178 end
e5ab4b0d » jeremy
2010-01-31 Convert to class_attribute
179 end
Something went wrong with that request. Please try again.