actionpack 2.0.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. data/CHANGELOG +149 -7
  2. data/MIT-LICENSE +1 -1
  3. data/README +1 -1
  4. data/Rakefile +5 -6
  5. data/lib/action_controller.rb +2 -2
  6. data/lib/action_controller/assertions/model_assertions.rb +2 -1
  7. data/lib/action_controller/assertions/response_assertions.rb +4 -2
  8. data/lib/action_controller/assertions/routing_assertions.rb +3 -3
  9. data/lib/action_controller/assertions/selector_assertions.rb +30 -27
  10. data/lib/action_controller/assertions/tag_assertions.rb +3 -3
  11. data/lib/action_controller/base.rb +103 -129
  12. data/lib/action_controller/benchmarking.rb +3 -3
  13. data/lib/action_controller/caching.rb +41 -652
  14. data/lib/action_controller/caching/actions.rb +144 -0
  15. data/lib/action_controller/caching/fragments.rb +138 -0
  16. data/lib/action_controller/caching/pages.rb +154 -0
  17. data/lib/action_controller/caching/sql_cache.rb +18 -0
  18. data/lib/action_controller/caching/sweeping.rb +97 -0
  19. data/lib/action_controller/cgi_ext/cookie.rb +27 -23
  20. data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
  21. data/lib/action_controller/cgi_process.rb +6 -4
  22. data/lib/action_controller/components.rb +7 -6
  23. data/lib/action_controller/cookies.rb +31 -19
  24. data/lib/action_controller/dispatcher.rb +51 -84
  25. data/lib/action_controller/filters.rb +295 -421
  26. data/lib/action_controller/flash.rb +1 -6
  27. data/lib/action_controller/headers.rb +31 -0
  28. data/lib/action_controller/helpers.rb +26 -9
  29. data/lib/action_controller/http_authentication.rb +1 -1
  30. data/lib/action_controller/integration.rb +65 -13
  31. data/lib/action_controller/layout.rb +24 -39
  32. data/lib/action_controller/mime_responds.rb +7 -3
  33. data/lib/action_controller/mime_type.rb +25 -9
  34. data/lib/action_controller/mime_types.rb +1 -1
  35. data/lib/action_controller/polymorphic_routes.rb +32 -17
  36. data/lib/action_controller/record_identifier.rb +10 -4
  37. data/lib/action_controller/request.rb +46 -30
  38. data/lib/action_controller/request_forgery_protection.rb +10 -9
  39. data/lib/action_controller/request_profiler.rb +29 -8
  40. data/lib/action_controller/rescue.rb +24 -24
  41. data/lib/action_controller/resources.rb +66 -23
  42. data/lib/action_controller/response.rb +2 -2
  43. data/lib/action_controller/routing.rb +113 -1229
  44. data/lib/action_controller/routing/builder.rb +204 -0
  45. data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
  46. data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
  47. data/lib/action_controller/routing/route.rb +240 -0
  48. data/lib/action_controller/routing/route_set.rb +435 -0
  49. data/lib/action_controller/routing/routing_ext.rb +46 -0
  50. data/lib/action_controller/routing/segments.rb +283 -0
  51. data/lib/action_controller/session/active_record_store.rb +13 -8
  52. data/lib/action_controller/session/cookie_store.rb +20 -17
  53. data/lib/action_controller/session_management.rb +10 -3
  54. data/lib/action_controller/streaming.rb +45 -31
  55. data/lib/action_controller/test_case.rb +33 -23
  56. data/lib/action_controller/test_process.rb +39 -35
  57. data/lib/action_controller/url_rewriter.rb +18 -12
  58. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
  59. data/lib/action_pack.rb +1 -1
  60. data/lib/action_pack/version.rb +2 -2
  61. data/lib/action_view.rb +11 -3
  62. data/lib/action_view/base.rb +73 -390
  63. data/lib/action_view/helpers/active_record_helper.rb +83 -62
  64. data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
  65. data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
  66. data/lib/action_view/helpers/benchmark_helper.rb +5 -3
  67. data/lib/action_view/helpers/cache_helper.rb +3 -2
  68. data/lib/action_view/helpers/capture_helper.rb +1 -2
  69. data/lib/action_view/helpers/date_helper.rb +104 -82
  70. data/lib/action_view/helpers/form_helper.rb +148 -75
  71. data/lib/action_view/helpers/form_options_helper.rb +44 -23
  72. data/lib/action_view/helpers/form_tag_helper.rb +22 -13
  73. data/lib/action_view/helpers/javascripts/controls.js +1 -1
  74. data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
  75. data/lib/action_view/helpers/javascripts/effects.js +1 -1
  76. data/lib/action_view/helpers/number_helper.rb +10 -3
  77. data/lib/action_view/helpers/prototype_helper.rb +61 -29
  78. data/lib/action_view/helpers/record_tag_helper.rb +3 -3
  79. data/lib/action_view/helpers/sanitize_helper.rb +23 -17
  80. data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
  81. data/lib/action_view/helpers/text_helper.rb +153 -125
  82. data/lib/action_view/helpers/url_helper.rb +83 -28
  83. data/lib/action_view/inline_template.rb +20 -0
  84. data/lib/action_view/partial_template.rb +70 -0
  85. data/lib/action_view/partials.rb +31 -73
  86. data/lib/action_view/template.rb +127 -0
  87. data/lib/action_view/template_error.rb +8 -7
  88. data/lib/action_view/template_finder.rb +177 -0
  89. data/lib/action_view/template_handler.rb +18 -1
  90. data/lib/action_view/template_handlers/builder.rb +10 -2
  91. data/lib/action_view/template_handlers/compilable.rb +128 -0
  92. data/lib/action_view/template_handlers/erb.rb +37 -2
  93. data/lib/action_view/template_handlers/rjs.rb +14 -1
  94. data/lib/action_view/test_case.rb +58 -0
  95. data/test/abstract_unit.rb +1 -1
  96. data/test/active_record_unit.rb +3 -6
  97. data/test/activerecord/active_record_store_test.rb +1 -2
  98. data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
  99. data/test/adv_attr_test.rb +20 -0
  100. data/test/controller/action_pack_assertions_test.rb +16 -19
  101. data/test/controller/addresses_render_test.rb +1 -1
  102. data/test/controller/assert_select_test.rb +13 -6
  103. data/test/controller/base_test.rb +48 -2
  104. data/test/controller/benchmark_test.rb +1 -2
  105. data/test/controller/caching_test.rb +282 -21
  106. data/test/controller/capture_test.rb +1 -1
  107. data/test/controller/cgi_test.rb +1 -1
  108. data/test/controller/components_test.rb +1 -1
  109. data/test/controller/content_type_test.rb +2 -2
  110. data/test/controller/cookie_test.rb +13 -2
  111. data/test/controller/custom_handler_test.rb +14 -10
  112. data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
  113. data/test/controller/dispatcher_test.rb +31 -49
  114. data/test/controller/fake_controllers.rb +17 -0
  115. data/test/controller/fake_models.rb +6 -0
  116. data/test/controller/filter_params_test.rb +14 -8
  117. data/test/controller/filters_test.rb +44 -16
  118. data/test/controller/flash_test.rb +2 -2
  119. data/test/controller/header_test.rb +14 -0
  120. data/test/controller/helper_test.rb +19 -15
  121. data/test/controller/html-scanner/document_test.rb +1 -2
  122. data/test/controller/html-scanner/node_test.rb +1 -2
  123. data/test/controller/html-scanner/sanitizer_test.rb +8 -5
  124. data/test/controller/html-scanner/tag_node_test.rb +1 -2
  125. data/test/controller/html-scanner/text_node_test.rb +2 -3
  126. data/test/controller/html-scanner/tokenizer_test.rb +8 -2
  127. data/test/controller/http_authentication_test.rb +1 -1
  128. data/test/controller/integration_test.rb +14 -16
  129. data/test/controller/integration_upload_test.rb +43 -0
  130. data/test/controller/layout_test.rb +26 -6
  131. data/test/controller/mime_responds_test.rb +39 -7
  132. data/test/controller/mime_type_test.rb +29 -5
  133. data/test/controller/new_render_test.rb +105 -34
  134. data/test/controller/polymorphic_routes_test.rb +32 -20
  135. data/test/controller/record_identifier_test.rb +38 -2
  136. data/test/controller/redirect_test.rb +21 -1
  137. data/test/controller/render_test.rb +59 -15
  138. data/test/controller/request_forgery_protection_test.rb +92 -5
  139. data/test/controller/request_test.rb +64 -6
  140. data/test/controller/rescue_test.rb +22 -6
  141. data/test/controller/resources_test.rb +102 -14
  142. data/test/controller/routing_test.rb +231 -19
  143. data/test/controller/selector_test.rb +2 -2
  144. data/test/controller/send_file_test.rb +14 -3
  145. data/test/controller/session/cookie_store_test.rb +16 -4
  146. data/test/controller/session/mem_cache_store_test.rb +3 -4
  147. data/test/controller/session_fixation_test.rb +1 -1
  148. data/test/controller/session_management_test.rb +23 -1
  149. data/test/controller/test_test.rb +39 -18
  150. data/test/controller/url_rewriter_test.rb +35 -1
  151. data/test/controller/verification_test.rb +1 -1
  152. data/test/controller/view_paths_test.rb +15 -12
  153. data/test/controller/webservice_test.rb +48 -3
  154. data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
  155. data/test/fixtures/company.rb +1 -0
  156. data/test/fixtures/customers/_customer.html.erb +1 -0
  157. data/test/fixtures/db_definitions/sqlite.sql +6 -0
  158. data/test/fixtures/functional_caching/_partial.erb +3 -0
  159. data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
  160. data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
  161. data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
  162. data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
  163. data/test/fixtures/mascot.rb +3 -0
  164. data/test/fixtures/mascots.yml +4 -0
  165. data/test/fixtures/mascots/_mascot.html.erb +1 -0
  166. data/test/fixtures/multipart/boundary_problem_file +10 -0
  167. data/test/fixtures/public/javascripts/application.js +1 -0
  168. data/test/fixtures/public/javascripts/controls.js +1 -0
  169. data/test/fixtures/public/javascripts/dragdrop.js +1 -0
  170. data/test/fixtures/public/javascripts/effects.js +1 -0
  171. data/test/fixtures/public/javascripts/prototype.js +1 -0
  172. data/test/fixtures/public/javascripts/version.1.0.js +1 -0
  173. data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
  174. data/test/fixtures/reply.rb +1 -0
  175. data/test/fixtures/shared.html.erb +1 -0
  176. data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
  177. data/test/fixtures/test/_customer_counter.erb +1 -0
  178. data/test/fixtures/test/_form.erb +1 -0
  179. data/test/fixtures/test/_labelling_form.erb +1 -0
  180. data/test/fixtures/test/_raise.html.erb +1 -0
  181. data/test/fixtures/test/greeting.js.rjs +1 -0
  182. data/test/fixtures/topics/_topic.html.erb +1 -0
  183. data/test/template/active_record_helper_test.rb +25 -8
  184. data/test/template/asset_tag_helper_test.rb +100 -17
  185. data/test/template/atom_feed_helper_test.rb +29 -1
  186. data/test/template/benchmark_helper_test.rb +10 -22
  187. data/test/template/date_helper_test.rb +455 -153
  188. data/test/template/erb_util_test.rb +10 -42
  189. data/test/template/form_helper_test.rb +192 -66
  190. data/test/template/form_options_helper_test.rb +19 -8
  191. data/test/template/form_tag_helper_test.rb +11 -8
  192. data/test/template/javascript_helper_test.rb +3 -9
  193. data/test/template/number_helper_test.rb +6 -3
  194. data/test/template/prototype_helper_test.rb +27 -40
  195. data/test/template/record_tag_helper_test.rb +54 -0
  196. data/test/template/sanitize_helper_test.rb +5 -6
  197. data/test/template/scriptaculous_helper_test.rb +7 -13
  198. data/test/template/tag_helper_test.rb +3 -6
  199. data/test/template/template_finder_test.rb +73 -0
  200. data/test/template/template_object_test.rb +95 -0
  201. data/test/template/test_test.rb +56 -0
  202. data/test/template/text_helper_test.rb +46 -33
  203. data/test/template/url_helper_test.rb +8 -10
  204. metadata +65 -12
  205. data/lib/action_view/compiled_templates.rb +0 -69
  206. data/test/action_view_test.rb +0 -44
  207. data/test/activerecord/fixtures_test.rb +0 -24
  208. data/test/controller/fragment_store_setting_test.rb +0 -47
  209. data/test/template/compiled_templates_test.rb +0 -197
  210. data/test/template/deprecate_ivars_test.rb +0 -51
@@ -5,6 +5,7 @@ require 'action_controller/routing'
5
5
  require 'action_controller/resources'
6
6
  require 'action_controller/url_rewriter'
7
7
  require 'action_controller/status_codes'
8
+ require 'action_view'
8
9
  require 'drb'
9
10
  require 'set'
10
11
 
@@ -15,9 +16,6 @@ module ActionController #:nodoc:
15
16
  class SessionRestoreError < ActionControllerError #:nodoc:
16
17
  end
17
18
 
18
- class MissingTemplate < ActionControllerError #:nodoc:
19
- end
20
-
21
19
  class RenderError < ActionControllerError #:nodoc:
22
20
  end
23
21
 
@@ -106,7 +104,7 @@ module ActionController #:nodoc:
106
104
  # end
107
105
  #
108
106
  # Actions, by default, render a template in the <tt>app/views</tt> directory corresponding to the name of the controller and action
109
- # after executing code in the action. For example, the +index+ action of the +GuestBookController+ would render the
107
+ # after executing code in the action. For example, the +index+ action of the GuestBookController would render the
110
108
  # template <tt>app/views/guestbook/index.erb</tt> by default after populating the <tt>@entries</tt> instance variable.
111
109
  #
112
110
  # Unlike index, the sign action will not render a template. After performing its main purpose (creating a
@@ -120,10 +118,10 @@ module ActionController #:nodoc:
120
118
  #
121
119
  # Requests are processed by the Action Controller framework by extracting the value of the "action" key in the request parameters.
122
120
  # This value should hold the name of the action to be performed. Once the action has been identified, the remaining
123
- # request parameters, the session (if one is available), and the full request with all the http headers are made available to
121
+ # request parameters, the session (if one is available), and the full request with all the HTTP headers are made available to
124
122
  # the action through instance variables. Then the action is performed.
125
123
  #
126
- # The full request object is available with the request accessor and is primarily used to query for http headers. These queries
124
+ # The full request object is available with the request accessor and is primarily used to query for HTTP headers. These queries
127
125
  # are made by accessing the environment hash, like this:
128
126
  #
129
127
  # def server_ip
@@ -161,28 +159,34 @@ module ActionController #:nodoc:
161
159
  #
162
160
  # Hello #{session[:person]}
163
161
  #
164
- # For removing objects from the session, you can either assign a single key to nil, like <tt>session[:person] = nil</tt>, or you can
165
- # remove the entire session with reset_session.
162
+ # For removing objects from the session, you can either assign a single key to +nil+:
163
+ #
164
+ # # removes :person from session
165
+ # session[:person] = nil
166
166
  #
167
- # Sessions are stored in a browser cookie that's cryptographically signed, but unencrypted, by default. This prevents
168
- # the user from tampering with the session but also allows him to see its contents.
167
+ # or you can remove the entire session with +reset_session+.
169
168
  #
170
- # Do not put secret information in session!
169
+ # Sessions are stored by default in a browser cookie that's cryptographically signed, but unencrypted.
170
+ # This prevents the user from tampering with the session but also allows him to see its contents.
171
+ #
172
+ # Do not put secret information in cookie-based sessions!
171
173
  #
172
174
  # Other options for session storage are:
173
175
  #
174
- # ActiveRecordStore: sessions are stored in your database, which works better than PStore with multiple app servers and,
175
- # unlike CookieStore, hides your session contents from the user. To use ActiveRecordStore, set
176
+ # * ActiveRecordStore - Sessions are stored in your database, which works better than PStore with multiple app servers and,
177
+ # unlike CookieStore, hides your session contents from the user. To use ActiveRecordStore, set
176
178
  #
177
- # config.action_controller.session_store = :active_record_store
179
+ # config.action_controller.session_store = :active_record_store
178
180
  #
179
- # in your <tt>environment.rb</tt> and run <tt>rake db:sessions:create</tt>.
181
+ # in your <tt>config/environment.rb</tt> and run <tt>rake db:sessions:create</tt>.
180
182
  #
181
- # MemCacheStore: sessions are stored as entries in your memcached cache. Set the session store type in <tt>environment.rb</tt>:
183
+ # * MemCacheStore - Sessions are stored as entries in your memcached cache.
184
+ # Set the session store type in <tt>config/environment.rb</tt>:
182
185
  #
183
- # config.action_controller.session_store = :mem_cache_store
186
+ # config.action_controller.session_store = :mem_cache_store
184
187
  #
185
- # This assumes that memcached has been installed and configured properly. See the MemCacheStore docs for more information.
188
+ # This assumes that memcached has been installed and configured properly.
189
+ # See the MemCacheStore docs for more information.
186
190
  #
187
191
  # == Responses
188
192
  #
@@ -256,14 +260,10 @@ module ActionController #:nodoc:
256
260
 
257
261
  include StatusCodes
258
262
 
259
- # Determines whether the view has access to controller internals @request, @response, @session, and @template.
260
- # By default, it does.
261
- @@view_controller_internals = true
262
- cattr_accessor :view_controller_internals
263
-
264
- # Protected instance variable cache
265
- @@protected_variables_cache = nil
266
- cattr_accessor :protected_variables_cache
263
+ # Controller specific instance variables which will not be accessible inside views.
264
+ @@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
265
+ @action_name @before_filter_chain_aborted @action_cache_path @_session @_cookies @_headers @_params
266
+ @_flash @_response)
267
267
 
268
268
  # Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
269
269
  # and images to a dedicated asset server away from the main web server. Example:
@@ -283,17 +283,18 @@ module ActionController #:nodoc:
283
283
  @@debug_routes = true
284
284
  cattr_accessor :debug_routes
285
285
 
286
- # Controls whether the application is thread-safe, so multi-threaded servers like WEBrick know whether to apply a mutex
287
- # around the performance of each action. Action Pack and Active Record are by default thread-safe, but many applications
288
- # may not be. Turned off by default.
286
+ # Indicates to Mongrel or Webrick whether to allow concurrent action
287
+ # processing. Your controller actions and any other code they call must
288
+ # also behave well when called from concurrent threads. Turned off by
289
+ # default.
289
290
  @@allow_concurrency = false
290
291
  cattr_accessor :allow_concurrency
291
292
 
292
293
  # Modern REST web services often need to submit complex data to the web application.
293
- # The param_parsers hash lets you register handlers which will process the http body and add parameters to the
294
- # <tt>params</tt> hash. These handlers are invoked for post and put requests.
294
+ # The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
295
+ # <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
295
296
  #
296
- # By default application/xml is enabled. A XmlSimple class with the same param name as the root will be instantiated
297
+ # By default <tt>application/xml</tt> is enabled. A XmlSimple class with the same param name as the root will be instantiated
297
298
  # in the <tt>params</tt>. This allows XML requests to mask themselves as regular form submissions, so you can have one
298
299
  # action serve both regular forms and web service requests.
299
300
  #
@@ -306,7 +307,7 @@ module ActionController #:nodoc:
306
307
  #
307
308
  # Note: Up until release 1.1 of Rails, Action Controller would default to using XmlSimple configured to discard the
308
309
  # root node for such requests. The new default is to keep the root, such that "<r><name>David</name></r>" results
309
- # in params[:r][:name] for "David" instead of params[:name]. To get the old behavior, you can
310
+ # in <tt>params[:r][:name]</tt> for "David" instead of <tt>params[:name]</tt>. To get the old behavior, you can
310
311
  # re-register XmlSimple as application/xml handler ike this:
311
312
  #
312
313
  # ActionController::Base.param_parsers[Mime::XML] =
@@ -315,30 +316,30 @@ module ActionController #:nodoc:
315
316
  # A YAML parser is also available and can be turned on with:
316
317
  #
317
318
  # ActionController::Base.param_parsers[Mime::YAML] = :yaml
318
- @@param_parsers = { Mime::MULTIPART_FORM => :multipart_form,
319
+ @@param_parsers = { Mime::MULTIPART_FORM => :multipart_form,
319
320
  Mime::URL_ENCODED_FORM => :url_encoded_form,
320
- Mime::XML => :xml_simple }
321
+ Mime::XML => :xml_simple,
322
+ Mime::JSON => :json }
321
323
  cattr_accessor :param_parsers
322
324
 
323
325
  # Controls the default charset for all renders.
324
326
  @@default_charset = "utf-8"
325
327
  cattr_accessor :default_charset
326
-
328
+
327
329
  # The logger is used for generating information on the action run-time (including benchmarking) if available.
328
330
  # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
329
331
  cattr_accessor :logger
330
332
 
331
- # Determines which template class should be used by ActionController.
332
- cattr_accessor :template_class
333
-
334
- # Turn on +ignore_missing_templates+ if you want to unit test actions without making the associated templates.
335
- cattr_accessor :ignore_missing_templates
336
-
337
333
  # Controls the resource action separator
338
334
  @@resource_action_separator = "/"
339
335
  cattr_accessor :resource_action_separator
340
-
341
- # Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default
336
+
337
+ # Allow to override path names for default resources' actions
338
+ @@resources_path_names = { :new => 'new', :edit => 'edit' }
339
+ cattr_accessor :resources_path_names
340
+
341
+ # Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+
342
+ # sets it to <tt>:authenticity_token</tt> by default.
342
343
  cattr_accessor :request_forgery_protection_token
343
344
 
344
345
  # Indicates whether or not optimise the generated named
@@ -428,10 +429,11 @@ module ActionController #:nodoc:
428
429
 
429
430
  def view_paths=(value)
430
431
  @view_paths = value
432
+ ActionView::TemplateFinder.process_view_paths(value)
431
433
  end
432
434
 
433
435
  # Adds a view_path to the front of the view_paths array.
434
- # If the current class has no view paths, copy them from
436
+ # If the current class has no view paths, copy them from
435
437
  # the superclass. This change will be visible for all future requests.
436
438
  #
437
439
  # ArticleController.prepend_view_path("views/default")
@@ -440,10 +442,11 @@ module ActionController #:nodoc:
440
442
  def prepend_view_path(path)
441
443
  @view_paths = superclass.view_paths.dup if @view_paths.nil?
442
444
  view_paths.unshift(*path)
445
+ ActionView::TemplateFinder.process_view_paths(path)
443
446
  end
444
-
447
+
445
448
  # Adds a view_path to the end of the view_paths array.
446
- # If the current class has no view paths, copy them from
449
+ # If the current class has no view paths, copy them from
447
450
  # the superclass. This change will be visible for all future requests.
448
451
  #
449
452
  # ArticleController.append_view_path("views/default")
@@ -452,8 +455,9 @@ module ActionController #:nodoc:
452
455
  def append_view_path(path)
453
456
  @view_paths = superclass.view_paths.dup if @view_paths.nil?
454
457
  view_paths.push(*path)
458
+ ActionView::TemplateFinder.process_view_paths(path)
455
459
  end
456
-
460
+
457
461
  # Replace sensitive parameter data from the request log.
458
462
  # Filters parameters that have any of the arguments as a substring.
459
463
  # Looks in all subhashes of the param hash for keys to filter.
@@ -500,6 +504,7 @@ module ActionController #:nodoc:
500
504
 
501
505
  filtered_parameters
502
506
  end
507
+ protected :filter_parameters
503
508
  end
504
509
 
505
510
  # Don't render layouts for templates with the given extensions.
@@ -534,23 +539,23 @@ module ActionController #:nodoc:
534
539
 
535
540
  # Returns a URL that has been rewritten according to the options hash and the defined Routes.
536
541
  # (For doing a complete redirect, use redirect_to).
537
- #  
542
+ #
538
543
  # <tt>url_for</tt> is used to:
539
- #  
540
- # All keys given to url_for are forwarded to the Route module, save for the following:
541
- # * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path. For example,
544
+ #
545
+ # All keys given to +url_for+ are forwarded to the Route module, save for the following:
546
+ # * <tt>:anchor</tt> - Specifies the anchor name to be appended to the path. For example,
542
547
  # <tt>url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments'</tt>
543
548
  # will produce "/posts/show/10#comments".
544
- # * <tt>:only_path</tt> -- if true, returns the relative URL (omitting the protocol, host name, and port) (<tt>false</tt> by default)
545
- # * <tt>:trailing_slash</tt> -- if true, adds a trailing slash, as in "/archive/2005/". Note that this
549
+ # * <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>false</tt> by default).
550
+ # * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2005/". Note that this
546
551
  # is currently not recommended since it breaks caching.
547
- # * <tt>:host</tt> -- overrides the default (current) host if provided.
548
- # * <tt>:protocol</tt> -- overrides the default (current) protocol if provided.
549
- # * <tt>:port</tt> -- optionally specify the port to connect to.
550
- # * <tt>:user</tt> -- Inline HTTP authentication (only plucked out if :password is also present).
551
- # * <tt>:password</tt> -- Inline HTTP authentication (only plucked out if :user is also present).
552
- # * <tt>:skip_relative_url_root</tt> -- if true, the url is not constructed using the relative_url_root of the request so the path
553
- # will include the web server relative installation directory.
552
+ # * <tt>:host</tt> - Overrides the default (current) host if provided.
553
+ # * <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
554
+ # * <tt>:port</tt> - Optionally specify the port to connect to.
555
+ # * <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
556
+ # * <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
557
+ # * <tt>:skip_relative_url_root</tt> - If true, the url is not constructed using the +relative_url_root+
558
+ # of the request so the path will include the web server relative installation directory.
554
559
  #
555
560
  # The URL is generated from the remaining keys in the hash. A URL contains two key parts: the <base> and a query string.
556
561
  # Routes composes a query string as the key/value pairs not included in the <base>.
@@ -601,7 +606,7 @@ module ActionController #:nodoc:
601
606
  # url_for :controller => 'posts', :action => nil
602
607
  #
603
608
  # If you explicitly want to create a URL that's almost the same as the current URL, you can do so using the
604
- # :overwrite_params options. Say for your posts you have different views for showing and printing them.
609
+ # <tt>:overwrite_params</tt> options. Say for your posts you have different views for showing and printing them.
605
610
  # Then, in the show view, you get the URL for the print view like this
606
611
  #
607
612
  # url_for :overwrite_params => { :action => 'print' }
@@ -639,14 +644,14 @@ module ActionController #:nodoc:
639
644
  end
640
645
 
641
646
  self.view_paths = []
642
-
647
+
643
648
  # View load paths for controller.
644
649
  def view_paths
645
- (@template || self.class).view_paths
650
+ @template.finder.view_paths
646
651
  end
647
-
652
+
648
653
  def view_paths=(value)
649
- (@template || self.class).view_paths = value
654
+ @template.finder.view_paths = value # Mutex needed
650
655
  end
651
656
 
652
657
  # Adds a view_path to the front of the view_paths array.
@@ -656,9 +661,9 @@ module ActionController #:nodoc:
656
661
  # self.prepend_view_path(["views/default", "views/custom"])
657
662
  #
658
663
  def prepend_view_path(path)
659
- (@template || self.class).prepend_view_path(path)
664
+ @template.finder.prepend_view_path(path) # Mutex needed
660
665
  end
661
-
666
+
662
667
  # Adds a view_path to the end of the view_paths array.
663
668
  # This change affects the current request only.
664
669
  #
@@ -666,7 +671,7 @@ module ActionController #:nodoc:
666
671
  # self.append_view_path(["views/default", "views/custom"])
667
672
  #
668
673
  def append_view_path(path)
669
- (@template || self.class).append_view_path(path)
674
+ @template.finder.append_view_path(path) # Mutex needed
670
675
  end
671
676
 
672
677
  protected
@@ -772,7 +777,7 @@ module ActionController #:nodoc:
772
777
  # # placed in "app/views/layouts/special.r(html|xml)"
773
778
  # render :text => "Hi there!", :layout => "special"
774
779
  #
775
- # The :text option can also accept a Proc object, which can be used to manually control the page generation. This should
780
+ # The <tt>:text</tt> option can also accept a Proc object, which can be used to manually control the page generation. This should
776
781
  # generally be avoided, as it violates the separation between code and content, and because almost everything that can be
777
782
  # done with this method can also be done more cleanly using one of the other rendering methods, most notably templates.
778
783
  #
@@ -826,19 +831,21 @@ module ActionController #:nodoc:
826
831
  #
827
832
  # === Rendering with status and location headers
828
833
  #
829
- # All renders take the :status and :location options and turn them into headers. They can even be used together:
834
+ # All renders take the <tt>:status</tt> and <tt>:location</tt> options and turn them into headers. They can even be used together:
830
835
  #
831
836
  # render :xml => post.to_xml, :status => :created, :location => post_url(post)
832
- def render(options = nil, &block) #:doc:
837
+ def render(options = nil, extra_options = {}, &block) #:doc:
833
838
  raise DoubleRenderError, "Can only render or redirect once per action" if performed?
834
839
 
835
840
  if options.nil?
836
841
  return render_for_file(default_template_name, nil, true)
842
+ elsif !extra_options.is_a?(Hash)
843
+ raise RenderError, "You called render with invalid options : #{options.inspect}, #{extra_options.inspect}"
837
844
  else
838
845
  if options == :update
839
- options = { :update => true }
846
+ options = extra_options.merge({ :update => true })
840
847
  elsif !options.is_a?(Hash)
841
- raise RenderError, "You called render with invalid options : #{options}"
848
+ raise RenderError, "You called render with invalid options : #{options.inspect}"
842
849
  end
843
850
  end
844
851
 
@@ -862,15 +869,16 @@ module ActionController #:nodoc:
862
869
 
863
870
  elsif inline = options[:inline]
864
871
  add_variables_to_assigns
865
- render_for_text(@template.render_template(options[:type], inline, nil, options[:locals] || {}), options[:status])
872
+ tmpl = ActionView::InlineTemplate.new(@template, options[:inline], options[:locals], options[:type])
873
+ render_for_text(@template.render_template(tmpl), options[:status])
866
874
 
867
875
  elsif action_name = options[:action]
868
876
  template = default_template_name(action_name.to_s)
869
877
  if options[:layout] && !template_exempt_from_layout?(template)
870
- render_with_a_layout(:file => template, :status => options[:status], :use_full_path => true, :layout => true)
878
+ render_with_a_layout(:file => template, :status => options[:status], :use_full_path => true, :layout => true)
871
879
  else
872
880
  render_with_no_layout(:file => template, :status => options[:status], :use_full_path => true)
873
- end
881
+ end
874
882
 
875
883
  elsif xml = options[:xml]
876
884
  response.content_type ||= Mime::XML
@@ -888,12 +896,12 @@ module ActionController #:nodoc:
888
896
 
889
897
  if collection = options[:collection]
890
898
  render_for_text(
891
- @template.send!(:render_partial_collection, partial, collection,
899
+ @template.send!(:render_partial_collection, partial, collection,
892
900
  options[:spacer_template], options[:locals]), options[:status]
893
901
  )
894
902
  else
895
903
  render_for_text(
896
- @template.send!(:render_partial, partial,
904
+ @template.send!(:render_partial, partial,
897
905
  ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]), options[:status]
898
906
  )
899
907
  end
@@ -904,7 +912,7 @@ module ActionController #:nodoc:
904
912
 
905
913
  generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
906
914
  response.content_type = Mime::JS
907
- render_for_text(generator.to_s)
915
+ render_for_text(generator.to_s, options[:status])
908
916
 
909
917
  elsif options[:nothing]
910
918
  # Safari doesn't pass the headers of the return if the response is zero length
@@ -997,7 +1005,7 @@ module ActionController #:nodoc:
997
1005
  # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
998
1006
  # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
999
1007
  # by this method.
1000
- def default_url_options(options) #:doc:
1008
+ def default_url_options(options = nil)
1001
1009
  end
1002
1010
 
1003
1011
  # Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
@@ -1017,7 +1025,7 @@ module ActionController #:nodoc:
1017
1025
  # redirect_to articles_url
1018
1026
  # redirect_to :back
1019
1027
  #
1020
- # The redirection happens as a "302 Moved" header unless otherwise specified.
1028
+ # The redirection happens as a "302 Moved" header unless otherwise specified.
1021
1029
  #
1022
1030
  # Examples:
1023
1031
  # redirect_to post_url(@post), :status=>:found
@@ -1028,17 +1036,17 @@ module ActionController #:nodoc:
1028
1036
  # When using <tt>redirect_to :back</tt>, if there is no referrer,
1029
1037
  # RedirectBackError will be raised. You may specify some fallback
1030
1038
  # behavior for this case by rescuing RedirectBackError.
1031
- def redirect_to(options = {}, response_status = {}) #:doc:
1039
+ def redirect_to(options = {}, response_status = {}) #:doc:
1032
1040
  raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
1033
1041
 
1034
- if options.is_a?(Hash) && options[:status]
1035
- status = options.delete(:status)
1036
- elsif response_status[:status]
1037
- status = response_status[:status]
1038
- else
1039
- status = 302
1042
+ if options.is_a?(Hash) && options[:status]
1043
+ status = options.delete(:status)
1044
+ elsif response_status[:status]
1045
+ status = response_status[:status]
1046
+ else
1047
+ status = 302
1040
1048
  end
1041
-
1049
+
1042
1050
  case options
1043
1051
  when %r{^\w+://.*}
1044
1052
  raise DoubleRenderError if performed?
@@ -1096,7 +1104,6 @@ module ActionController #:nodoc:
1096
1104
  private
1097
1105
  def render_for_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc:
1098
1106
  add_variables_to_assigns
1099
- assert_existence_of_template_file(template_path) if use_full_path
1100
1107
  logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
1101
1108
  render_for_text(@template.render_file(template_path, use_full_path, locals), status)
1102
1109
  end
@@ -1113,13 +1120,9 @@ module ActionController #:nodoc:
1113
1120
  response.body = text.is_a?(Proc) ? text : text.to_s
1114
1121
  end
1115
1122
  end
1116
-
1117
- def initialize_template_class(response)
1118
- unless @@template_class
1119
- raise "You must assign a template class through ActionController.template_class= before processing a request"
1120
- end
1121
1123
 
1122
- response.template = ActionView::Base.new(view_paths, {}, self)
1124
+ def initialize_template_class(response)
1125
+ response.template = ActionView::Base.new(self.class.view_paths, {}, self)
1123
1126
  response.template.extend self.class.master_helper_module
1124
1127
  response.redirected_to = nil
1125
1128
  @performed_render = @performed_redirect = false
@@ -1196,7 +1199,6 @@ module ActionController #:nodoc:
1196
1199
  def add_variables_to_assigns
1197
1200
  unless @variables_added
1198
1201
  add_instance_variables_to_assigns
1199
- add_class_variables_to_assigns if view_controller_internals
1200
1202
  @variables_added = true
1201
1203
  end
1202
1204
  end
@@ -1210,30 +1212,11 @@ module ActionController #:nodoc:
1210
1212
  end
1211
1213
 
1212
1214
  def add_instance_variables_to_assigns
1213
- @@protected_variables_cache ||= Set.new(protected_instance_variables)
1214
- instance_variables.each do |var|
1215
- next if @@protected_variables_cache.include?(var)
1215
+ (instance_variable_names - @@protected_view_variables).each do |var|
1216
1216
  @assigns[var[1..-1]] = instance_variable_get(var)
1217
1217
  end
1218
1218
  end
1219
1219
 
1220
- def add_class_variables_to_assigns
1221
- %w(view_paths logger template_class ignore_missing_templates).each do |cvar|
1222
- @assigns[cvar] = self.send(cvar)
1223
- end
1224
- end
1225
-
1226
- def protected_instance_variables
1227
- if view_controller_internals
1228
- %w(@assigns @performed_redirect @performed_render)
1229
- else
1230
- %w(@assigns @performed_redirect @performed_render
1231
- @_request @request @_response @response @_params @params
1232
- @_session @session @_cookies @cookies
1233
- @template @request_origin @parent_controller)
1234
- end
1235
- end
1236
-
1237
1220
  def request_origin
1238
1221
  # this *needs* to be cached!
1239
1222
  # otherwise you'd get different results if calling it more than once
@@ -1249,7 +1232,7 @@ module ActionController #:nodoc:
1249
1232
  end
1250
1233
 
1251
1234
  def template_exists?(template_name = default_template_name)
1252
- @template.file_exists?(template_name)
1235
+ @template.finder.file_exists?(template_name)
1253
1236
  end
1254
1237
 
1255
1238
  def template_public?(template_name = default_template_name)
@@ -1257,20 +1240,11 @@ module ActionController #:nodoc:
1257
1240
  end
1258
1241
 
1259
1242
  def template_exempt_from_layout?(template_name = default_template_name)
1260
- extension = @template && @template.pick_template_extension(template_name)
1243
+ extension = @template && @template.finder.pick_template_extension(template_name)
1261
1244
  name_with_extension = !template_name.include?('.') && extension ? "#{template_name}.#{extension}" : template_name
1262
1245
  @@exempt_from_layout.any? { |ext| name_with_extension =~ ext }
1263
1246
  end
1264
1247
 
1265
- def assert_existence_of_template_file(template_name)
1266
- unless template_exists?(template_name) || ignore_missing_templates
1267
- full_template_path = template_name.include?('.') ? template_name : "#{template_name}.#{@template.template_format}.erb"
1268
- display_paths = view_paths.join(':')
1269
- template_type = (template_name =~ /layouts/i) ? 'layout' : 'template'
1270
- raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}")
1271
- end
1272
- end
1273
-
1274
1248
  def default_template_name(action_name = self.action_name)
1275
1249
  if action_name
1276
1250
  action_name = action_name.to_s