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.
- data/CHANGELOG +149 -7
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +5 -6
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions/model_assertions.rb +2 -1
- data/lib/action_controller/assertions/response_assertions.rb +4 -2
- data/lib/action_controller/assertions/routing_assertions.rb +3 -3
- data/lib/action_controller/assertions/selector_assertions.rb +30 -27
- data/lib/action_controller/assertions/tag_assertions.rb +3 -3
- data/lib/action_controller/base.rb +103 -129
- data/lib/action_controller/benchmarking.rb +3 -3
- data/lib/action_controller/caching.rb +41 -652
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext/cookie.rb +27 -23
- data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
- data/lib/action_controller/cgi_process.rb +6 -4
- data/lib/action_controller/components.rb +7 -6
- data/lib/action_controller/cookies.rb +31 -19
- data/lib/action_controller/dispatcher.rb +51 -84
- data/lib/action_controller/filters.rb +295 -421
- data/lib/action_controller/flash.rb +1 -6
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +26 -9
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +65 -13
- data/lib/action_controller/layout.rb +24 -39
- data/lib/action_controller/mime_responds.rb +7 -3
- data/lib/action_controller/mime_type.rb +25 -9
- data/lib/action_controller/mime_types.rb +1 -1
- data/lib/action_controller/polymorphic_routes.rb +32 -17
- data/lib/action_controller/record_identifier.rb +10 -4
- data/lib/action_controller/request.rb +46 -30
- data/lib/action_controller/request_forgery_protection.rb +10 -9
- data/lib/action_controller/request_profiler.rb +29 -8
- data/lib/action_controller/rescue.rb +24 -24
- data/lib/action_controller/resources.rb +66 -23
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing.rb +113 -1229
- data/lib/action_controller/routing/builder.rb +204 -0
- data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
- data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +435 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +13 -8
- data/lib/action_controller/session/cookie_store.rb +20 -17
- data/lib/action_controller/session_management.rb +10 -3
- data/lib/action_controller/streaming.rb +45 -31
- data/lib/action_controller/test_case.rb +33 -23
- data/lib/action_controller/test_process.rb +39 -35
- data/lib/action_controller/url_rewriter.rb +18 -12
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +11 -3
- data/lib/action_view/base.rb +73 -390
- data/lib/action_view/helpers/active_record_helper.rb +83 -62
- data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
- data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
- data/lib/action_view/helpers/benchmark_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +3 -2
- data/lib/action_view/helpers/capture_helper.rb +1 -2
- data/lib/action_view/helpers/date_helper.rb +104 -82
- data/lib/action_view/helpers/form_helper.rb +148 -75
- data/lib/action_view/helpers/form_options_helper.rb +44 -23
- data/lib/action_view/helpers/form_tag_helper.rb +22 -13
- data/lib/action_view/helpers/javascripts/controls.js +1 -1
- data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
- data/lib/action_view/helpers/javascripts/effects.js +1 -1
- data/lib/action_view/helpers/number_helper.rb +10 -3
- data/lib/action_view/helpers/prototype_helper.rb +61 -29
- data/lib/action_view/helpers/record_tag_helper.rb +3 -3
- data/lib/action_view/helpers/sanitize_helper.rb +23 -17
- data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
- data/lib/action_view/helpers/text_helper.rb +153 -125
- data/lib/action_view/helpers/url_helper.rb +83 -28
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +31 -73
- data/lib/action_view/template.rb +127 -0
- data/lib/action_view/template_error.rb +8 -7
- data/lib/action_view/template_finder.rb +177 -0
- data/lib/action_view/template_handler.rb +18 -1
- data/lib/action_view/template_handlers/builder.rb +10 -2
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +37 -2
- data/lib/action_view/template_handlers/rjs.rb +14 -1
- data/lib/action_view/test_case.rb +58 -0
- data/test/abstract_unit.rb +1 -1
- data/test/active_record_unit.rb +3 -6
- data/test/activerecord/active_record_store_test.rb +1 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +16 -19
- data/test/controller/addresses_render_test.rb +1 -1
- data/test/controller/assert_select_test.rb +13 -6
- data/test/controller/base_test.rb +48 -2
- data/test/controller/benchmark_test.rb +1 -2
- data/test/controller/caching_test.rb +282 -21
- data/test/controller/capture_test.rb +1 -1
- data/test/controller/cgi_test.rb +1 -1
- data/test/controller/components_test.rb +1 -1
- data/test/controller/content_type_test.rb +2 -2
- data/test/controller/cookie_test.rb +13 -2
- data/test/controller/custom_handler_test.rb +14 -10
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
- data/test/controller/dispatcher_test.rb +31 -49
- data/test/controller/fake_controllers.rb +17 -0
- data/test/controller/fake_models.rb +6 -0
- data/test/controller/filter_params_test.rb +14 -8
- data/test/controller/filters_test.rb +44 -16
- data/test/controller/flash_test.rb +2 -2
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +19 -15
- data/test/controller/html-scanner/document_test.rb +1 -2
- data/test/controller/html-scanner/node_test.rb +1 -2
- data/test/controller/html-scanner/sanitizer_test.rb +8 -5
- data/test/controller/html-scanner/tag_node_test.rb +1 -2
- data/test/controller/html-scanner/text_node_test.rb +2 -3
- data/test/controller/html-scanner/tokenizer_test.rb +8 -2
- data/test/controller/http_authentication_test.rb +1 -1
- data/test/controller/integration_test.rb +14 -16
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +26 -6
- data/test/controller/mime_responds_test.rb +39 -7
- data/test/controller/mime_type_test.rb +29 -5
- data/test/controller/new_render_test.rb +105 -34
- data/test/controller/polymorphic_routes_test.rb +32 -20
- data/test/controller/record_identifier_test.rb +38 -2
- data/test/controller/redirect_test.rb +21 -1
- data/test/controller/render_test.rb +59 -15
- data/test/controller/request_forgery_protection_test.rb +92 -5
- data/test/controller/request_test.rb +64 -6
- data/test/controller/rescue_test.rb +22 -6
- data/test/controller/resources_test.rb +102 -14
- data/test/controller/routing_test.rb +231 -19
- data/test/controller/selector_test.rb +2 -2
- data/test/controller/send_file_test.rb +14 -3
- data/test/controller/session/cookie_store_test.rb +16 -4
- data/test/controller/session/mem_cache_store_test.rb +3 -4
- data/test/controller/session_fixation_test.rb +1 -1
- data/test/controller/session_management_test.rb +23 -1
- data/test/controller/test_test.rb +39 -18
- data/test/controller/url_rewriter_test.rb +35 -1
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -12
- data/test/controller/webservice_test.rb +48 -3
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/company.rb +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/controls.js +1 -0
- data/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/test/fixtures/public/javascripts/effects.js +1 -0
- data/test/fixtures/public/javascripts/prototype.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/reply.rb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +25 -8
- data/test/template/asset_tag_helper_test.rb +100 -17
- data/test/template/atom_feed_helper_test.rb +29 -1
- data/test/template/benchmark_helper_test.rb +10 -22
- data/test/template/date_helper_test.rb +455 -153
- data/test/template/erb_util_test.rb +10 -42
- data/test/template/form_helper_test.rb +192 -66
- data/test/template/form_options_helper_test.rb +19 -8
- data/test/template/form_tag_helper_test.rb +11 -8
- data/test/template/javascript_helper_test.rb +3 -9
- data/test/template/number_helper_test.rb +6 -3
- data/test/template/prototype_helper_test.rb +27 -40
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +5 -6
- data/test/template/scriptaculous_helper_test.rb +7 -13
- data/test/template/tag_helper_test.rb +3 -6
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +46 -33
- data/test/template/url_helper_test.rb +8 -10
- metadata +65 -12
- data/lib/action_view/compiled_templates.rb +0 -69
- data/test/action_view_test.rb +0 -44
- data/test/activerecord/fixtures_test.rb +0 -24
- data/test/controller/fragment_store_setting_test.rb +0 -47
- data/test/template/compiled_templates_test.rb +0 -197
- 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
|
|
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
|
|
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
|
|
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
|
|
165
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
|
175
|
-
#
|
|
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
|
-
#
|
|
179
|
+
# config.action_controller.session_store = :active_record_store
|
|
178
180
|
#
|
|
179
|
-
#
|
|
181
|
+
# in your <tt>config/environment.rb</tt> and run <tt>rake db:sessions:create</tt>.
|
|
180
182
|
#
|
|
181
|
-
# MemCacheStore
|
|
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
|
-
#
|
|
186
|
+
# config.action_controller.session_store = :mem_cache_store
|
|
184
187
|
#
|
|
185
|
-
#
|
|
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
|
-
#
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
#
|
|
287
|
-
#
|
|
288
|
-
#
|
|
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
|
|
294
|
-
# <tt>params</tt> hash. These handlers are invoked for
|
|
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]
|
|
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
|
|
319
|
+
@@param_parsers = { Mime::MULTIPART_FORM => :multipart_form,
|
|
319
320
|
Mime::URL_ENCODED_FORM => :url_encoded_form,
|
|
320
|
-
Mime::XML
|
|
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
|
-
#
|
|
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>
|
|
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>
|
|
545
|
-
# * <tt>:trailing_slash</tt>
|
|
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>
|
|
548
|
-
# * <tt>:protocol</tt>
|
|
549
|
-
# * <tt>:port</tt>
|
|
550
|
-
# * <tt>:user</tt>
|
|
551
|
-
# * <tt>:password</tt>
|
|
552
|
-
# * <tt>:skip_relative_url_root</tt>
|
|
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
|
-
#
|
|
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
|
-
|
|
650
|
+
@template.finder.view_paths
|
|
646
651
|
end
|
|
647
|
-
|
|
652
|
+
|
|
648
653
|
def view_paths=(value)
|
|
649
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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)
|
|
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
|
-
|
|
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
|
-
@@
|
|
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
|