actionpack 4.0.13 → 4.1.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +131 -1636
- data/README.rdoc +1 -6
- data/lib/abstract_controller.rb +1 -2
- data/lib/abstract_controller/base.rb +3 -25
- data/lib/abstract_controller/callbacks.rb +4 -2
- data/lib/abstract_controller/collector.rb +11 -1
- data/lib/abstract_controller/helpers.rb +18 -15
- data/lib/abstract_controller/rendering.rb +48 -127
- data/lib/action_controller.rb +1 -17
- data/lib/action_controller/base.rb +14 -6
- data/lib/action_controller/caching.rb +1 -11
- data/lib/action_controller/log_subscriber.rb +1 -1
- data/lib/action_controller/metal.rb +0 -4
- data/lib/action_controller/metal/flash.rb +17 -0
- data/lib/action_controller/metal/force_ssl.rb +1 -1
- data/lib/action_controller/metal/head.rb +1 -3
- data/lib/action_controller/metal/helpers.rb +6 -2
- data/lib/action_controller/metal/http_authentication.rb +7 -14
- data/lib/action_controller/metal/instrumentation.rb +1 -1
- data/lib/action_controller/metal/live.rb +74 -0
- data/lib/action_controller/metal/mime_responds.rb +93 -16
- data/lib/action_controller/metal/params_wrapper.rb +4 -11
- data/lib/action_controller/metal/rack_delegation.rb +1 -1
- data/lib/action_controller/metal/redirecting.rb +20 -20
- data/lib/action_controller/metal/renderers.rb +8 -5
- data/lib/action_controller/metal/rendering.rb +14 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +67 -13
- data/lib/action_controller/metal/responder.rb +12 -2
- data/lib/action_controller/metal/streaming.rb +18 -20
- data/lib/action_controller/metal/strong_parameters.rb +22 -34
- data/lib/action_controller/railtie.rb +0 -1
- data/lib/action_controller/test_case.rb +0 -15
- data/lib/action_dispatch.rb +1 -0
- data/lib/action_dispatch/http/headers.rb +1 -3
- data/lib/action_dispatch/http/mime_negotiation.rb +16 -2
- data/lib/action_dispatch/http/mime_type.rb +4 -22
- data/lib/action_dispatch/http/mime_types.rb +1 -0
- data/lib/action_dispatch/http/parameters.rb +18 -19
- data/lib/action_dispatch/http/request.rb +16 -25
- data/lib/action_dispatch/http/response.rb +21 -8
- data/lib/action_dispatch/http/upload.rb +0 -13
- data/lib/action_dispatch/http/url.rb +10 -18
- data/lib/action_dispatch/journey/formatter.rb +3 -3
- data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -5
- data/lib/action_dispatch/journey/parser.rb +1 -1
- data/lib/action_dispatch/journey/parser.y +1 -0
- data/lib/action_dispatch/journey/router.rb +7 -1
- data/lib/action_dispatch/journey/router/utils.rb +1 -1
- data/lib/action_dispatch/journey/visitors.rb +26 -47
- data/lib/action_dispatch/middleware/callbacks.rb +6 -6
- data/lib/action_dispatch/middleware/cookies.rb +15 -15
- data/lib/action_dispatch/middleware/debug_exceptions.rb +21 -13
- data/lib/action_dispatch/middleware/exception_wrapper.rb +1 -1
- data/lib/action_dispatch/middleware/flash.rb +5 -11
- data/lib/action_dispatch/middleware/params_parser.rb +1 -1
- data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +4 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +5 -2
- data/lib/action_dispatch/middleware/ssl.rb +1 -1
- data/lib/action_dispatch/middleware/static.rb +5 -25
- data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/{_trace.erb → _trace.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +15 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/{missing_template.erb → missing_template.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/{template_error.erb → template_error.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +3 -3
- data/lib/action_dispatch/railtie.rb +1 -2
- data/lib/action_dispatch/request/session.rb +12 -0
- data/lib/action_dispatch/request/utils.rb +24 -0
- data/lib/action_dispatch/routing.rb +7 -6
- data/lib/action_dispatch/routing/inspector.rb +4 -4
- data/lib/action_dispatch/routing/mapper.rb +81 -138
- data/lib/action_dispatch/routing/polymorphic_routes.rb +13 -0
- data/lib/action_dispatch/routing/redirection.rb +34 -27
- data/lib/action_dispatch/routing/route_set.rb +43 -37
- data/lib/action_dispatch/routing/url_for.rb +3 -1
- data/lib/action_dispatch/testing/assertions/response.rb +8 -15
- data/lib/action_dispatch/testing/assertions/selector.rb +4 -4
- data/lib/action_dispatch/testing/integration.rb +1 -7
- data/lib/action_pack/version.rb +1 -1
- metadata +43 -167
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/deprecated.rb +0 -7
- data/lib/action_controller/deprecated/integration_test.rb +0 -5
- data/lib/action_controller/record_identifier.rb +0 -31
- data/lib/action_controller/vendor/html-scanner.rb +0 -5
- data/lib/action_view.rb +0 -93
- data/lib/action_view/base.rb +0 -205
- data/lib/action_view/buffers.rb +0 -49
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/dependency_tracker.rb +0 -93
- data/lib/action_view/digestor.rb +0 -113
- data/lib/action_view/flows.rb +0 -76
- data/lib/action_view/helpers.rb +0 -58
- data/lib/action_view/helpers/active_model_helper.rb +0 -49
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
- data/lib/action_view/helpers/asset_url_helper.rb +0 -355
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
- data/lib/action_view/helpers/cache_helper.rb +0 -196
- data/lib/action_view/helpers/capture_helper.rb +0 -216
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1087
- data/lib/action_view/helpers/debug_helper.rb +0 -39
- data/lib/action_view/helpers/form_helper.rb +0 -1882
- data/lib/action_view/helpers/form_options_helper.rb +0 -838
- data/lib/action_view/helpers/form_tag_helper.rb +0 -785
- data/lib/action_view/helpers/javascript_helper.rb +0 -117
- data/lib/action_view/helpers/number_helper.rb +0 -451
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -106
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -256
- data/lib/action_view/helpers/tag_helper.rb +0 -173
- data/lib/action_view/helpers/tags.rb +0 -39
- data/lib/action_view/helpers/tags/base.rb +0 -148
- data/lib/action_view/helpers/tags/check_box.rb +0 -64
- data/lib/action_view/helpers/tags/checkable.rb +0 -16
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -53
- data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
- data/lib/action_view/helpers/tags/collection_select.rb +0 -28
- data/lib/action_view/helpers/tags/color_field.rb +0 -25
- data/lib/action_view/helpers/tags/date_field.rb +0 -13
- data/lib/action_view/helpers/tags/date_select.rb +0 -72
- data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
- data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
- data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
- data/lib/action_view/helpers/tags/email_field.rb +0 -8
- data/lib/action_view/helpers/tags/file_field.rb +0 -8
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
- data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
- data/lib/action_view/helpers/tags/label.rb +0 -65
- data/lib/action_view/helpers/tags/month_field.rb +0 -13
- data/lib/action_view/helpers/tags/number_field.rb +0 -18
- data/lib/action_view/helpers/tags/password_field.rb +0 -12
- data/lib/action_view/helpers/tags/radio_button.rb +0 -31
- data/lib/action_view/helpers/tags/range_field.rb +0 -8
- data/lib/action_view/helpers/tags/search_field.rb +0 -22
- data/lib/action_view/helpers/tags/select.rb +0 -40
- data/lib/action_view/helpers/tags/tel_field.rb +0 -8
- data/lib/action_view/helpers/tags/text_area.rb +0 -18
- data/lib/action_view/helpers/tags/text_field.rb +0 -30
- data/lib/action_view/helpers/tags/time_field.rb +0 -13
- data/lib/action_view/helpers/tags/time_select.rb +0 -8
- data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
- data/lib/action_view/helpers/tags/url_field.rb +0 -8
- data/lib/action_view/helpers/tags/week_field.rb +0 -13
- data/lib/action_view/helpers/text_helper.rb +0 -448
- data/lib/action_view/helpers/translation_helper.rb +0 -112
- data/lib/action_view/helpers/url_helper.rb +0 -635
- data/lib/action_view/locale/en.yml +0 -56
- data/lib/action_view/log_subscriber.rb +0 -30
- data/lib/action_view/lookup_context.rb +0 -248
- data/lib/action_view/model_naming.rb +0 -12
- data/lib/action_view/path_set.rb +0 -77
- data/lib/action_view/railtie.rb +0 -43
- data/lib/action_view/record_identifier.rb +0 -84
- data/lib/action_view/renderer/abstract_renderer.rb +0 -47
- data/lib/action_view/renderer/partial_renderer.rb +0 -500
- data/lib/action_view/renderer/renderer.rb +0 -50
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
- data/lib/action_view/renderer/template_renderer.rb +0 -96
- data/lib/action_view/routing_url_for.rb +0 -107
- data/lib/action_view/tasks/dependencies.rake +0 -17
- data/lib/action_view/template.rb +0 -339
- data/lib/action_view/template/error.rb +0 -138
- data/lib/action_view/template/handlers.rb +0 -53
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -146
- data/lib/action_view/template/handlers/raw.rb +0 -11
- data/lib/action_view/template/resolver.rb +0 -340
- data/lib/action_view/template/text.rb +0 -34
- data/lib/action_view/template/types.rb +0 -57
- data/lib/action_view/test_case.rb +0 -270
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view/vendor/html-scanner.rb +0 -20
- data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
- data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
data/README.rdoc
CHANGED
|
@@ -17,11 +17,6 @@ It consists of several modules:
|
|
|
17
17
|
subclassed to implement filters and actions to handle requests. The result
|
|
18
18
|
of an action is typically content generated from views.
|
|
19
19
|
|
|
20
|
-
* Action View, which handles view template lookup and rendering, and provides
|
|
21
|
-
view helpers that assist when building HTML forms, Atom feeds and more.
|
|
22
|
-
Template formats that Action View handles are ERB (embedded Ruby, typically
|
|
23
|
-
used to inline short Ruby snippets inside HTML), and XML Builder.
|
|
24
|
-
|
|
25
20
|
With the Ruby on Rails framework, users only directly interface with the
|
|
26
21
|
Action Controller module. Necessary Action Dispatch functionality is activated
|
|
27
22
|
by default and Action View rendering is implicitly triggered by Action
|
|
@@ -37,7 +32,7 @@ The latest version of Action Pack can be installed with RubyGems:
|
|
|
37
32
|
|
|
38
33
|
Source code can be downloaded as part of the Rails project on GitHub
|
|
39
34
|
|
|
40
|
-
* https://github.com/rails/rails/tree/
|
|
35
|
+
* https://github.com/rails/rails/tree/master/actionpack
|
|
41
36
|
|
|
42
37
|
|
|
43
38
|
== License
|
data/lib/abstract_controller.rb
CHANGED
|
@@ -10,12 +10,11 @@ module AbstractController
|
|
|
10
10
|
autoload :Base
|
|
11
11
|
autoload :Callbacks
|
|
12
12
|
autoload :Collector
|
|
13
|
+
autoload :DoubleRenderError, "abstract_controller/rendering"
|
|
13
14
|
autoload :Helpers
|
|
14
|
-
autoload :Layouts
|
|
15
15
|
autoload :Logger
|
|
16
16
|
autoload :Rendering
|
|
17
17
|
autoload :Translation
|
|
18
18
|
autoload :AssetPaths
|
|
19
|
-
autoload :ViewPaths
|
|
20
19
|
autoload :UrlFor
|
|
21
20
|
end
|
|
@@ -127,7 +127,7 @@ module AbstractController
|
|
|
127
127
|
def process(action, *args)
|
|
128
128
|
@_action_name = action_name = action.to_s
|
|
129
129
|
|
|
130
|
-
unless action_name =
|
|
130
|
+
unless action_name = method_for_action(action_name)
|
|
131
131
|
raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
|
|
132
132
|
end
|
|
133
133
|
|
|
@@ -160,7 +160,7 @@ module AbstractController
|
|
|
160
160
|
# ==== Returns
|
|
161
161
|
# * <tt>TrueClass</tt>, <tt>FalseClass</tt>
|
|
162
162
|
def available_action?(action_name)
|
|
163
|
-
|
|
163
|
+
method_for_action(action_name).present?
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
private
|
|
@@ -203,23 +203,6 @@ module AbstractController
|
|
|
203
203
|
action_missing(@_action_name, *args)
|
|
204
204
|
end
|
|
205
205
|
|
|
206
|
-
# Takes an action name and returns the name of the method that will
|
|
207
|
-
# handle the action.
|
|
208
|
-
#
|
|
209
|
-
# It checks if the action name is valid and returns false otherwise.
|
|
210
|
-
#
|
|
211
|
-
# See method_for_action for more information.
|
|
212
|
-
#
|
|
213
|
-
# ==== Parameters
|
|
214
|
-
# * <tt>action_name</tt> - An action name to find a method name for
|
|
215
|
-
#
|
|
216
|
-
# ==== Returns
|
|
217
|
-
# * <tt>string</tt> - The name of the method that handles the action
|
|
218
|
-
# * false - No valid method name could be found. Raise ActionNotFound.
|
|
219
|
-
def _find_action_name(action_name)
|
|
220
|
-
_valid_action_name?(action_name) && method_for_action(action_name)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
206
|
# Takes an action name and returns the name of the method that will
|
|
224
207
|
# handle the action. In normal cases, this method returns the same
|
|
225
208
|
# name as it receives. By default, if #method_for_action receives
|
|
@@ -242,7 +225,7 @@ module AbstractController
|
|
|
242
225
|
#
|
|
243
226
|
# ==== Returns
|
|
244
227
|
# * <tt>string</tt> - The name of the method that handles the action
|
|
245
|
-
# * <tt>nil</tt> - No method name could be found.
|
|
228
|
+
# * <tt>nil</tt> - No method name could be found. Raise ActionNotFound.
|
|
246
229
|
def method_for_action(action_name)
|
|
247
230
|
if action_method?(action_name)
|
|
248
231
|
action_name
|
|
@@ -250,10 +233,5 @@ module AbstractController
|
|
|
250
233
|
"_handle_action_missing"
|
|
251
234
|
end
|
|
252
235
|
end
|
|
253
|
-
|
|
254
|
-
# Checks if the action name is valid and returns false otherwise.
|
|
255
|
-
def _valid_action_name?(action_name)
|
|
256
|
-
!action_name.to_s.include? File::SEPARATOR
|
|
257
|
-
end
|
|
258
236
|
end
|
|
259
237
|
end
|
|
@@ -8,7 +8,9 @@ module AbstractController
|
|
|
8
8
|
include ActiveSupport::Callbacks
|
|
9
9
|
|
|
10
10
|
included do
|
|
11
|
-
define_callbacks :process_action,
|
|
11
|
+
define_callbacks :process_action,
|
|
12
|
+
terminator: ->(controller,_) { controller.response_body },
|
|
13
|
+
skip_after_callbacks_if_terminated: true
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
# Override AbstractController::Base's process_action to run the
|
|
@@ -69,7 +71,7 @@ module AbstractController
|
|
|
69
71
|
# * <tt>name</tt> - The callback to be added
|
|
70
72
|
# * <tt>options</tt> - A hash of options to be used when adding the callback
|
|
71
73
|
def _insert_callbacks(callbacks, block = nil)
|
|
72
|
-
options = callbacks.
|
|
74
|
+
options = callbacks.extract_options!
|
|
73
75
|
_normalize_callback_options(options)
|
|
74
76
|
callbacks.push(block) if block
|
|
75
77
|
callbacks.each do |callback|
|
|
@@ -23,7 +23,17 @@ module AbstractController
|
|
|
23
23
|
protected
|
|
24
24
|
|
|
25
25
|
def method_missing(symbol, &block)
|
|
26
|
-
|
|
26
|
+
const_name = symbol.upcase
|
|
27
|
+
|
|
28
|
+
unless Mime.const_defined?(const_name)
|
|
29
|
+
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
|
|
30
|
+
"http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
|
|
31
|
+
"If you meant to respond to a variant like :tablet or :phone, not a custom format, " \
|
|
32
|
+
"be sure to nest your variant response within a format response: " \
|
|
33
|
+
"format.html { |html| html.tablet { ... } }"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
mime_constant = Mime.const_get(const_name)
|
|
27
37
|
|
|
28
38
|
if Mime::SET.include?(mime_constant)
|
|
29
39
|
AbstractController::Collector.generate_method_for_mime(mime_constant)
|
|
@@ -12,7 +12,24 @@ module AbstractController
|
|
|
12
12
|
self._helper_methods = Array.new
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
class MissingHelperError < LoadError
|
|
16
|
+
def initialize(error, path)
|
|
17
|
+
@error = error
|
|
18
|
+
@path = "helpers/#{path}.rb"
|
|
19
|
+
set_backtrace error.backtrace
|
|
20
|
+
|
|
21
|
+
if error.path =~ /^#{path}(\.rb)?$/
|
|
22
|
+
super("Missing helper file helpers/%s.rb" % path)
|
|
23
|
+
else
|
|
24
|
+
raise error
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
15
29
|
module ClassMethods
|
|
30
|
+
MissingHelperError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('AbstractController::Helpers::ClassMethods::MissingHelperError',
|
|
31
|
+
'AbstractController::Helpers::MissingHelperError')
|
|
32
|
+
|
|
16
33
|
# When a class is inherited, wrap its helper module in a new module.
|
|
17
34
|
# This ensures that the parent class's module can be changed
|
|
18
35
|
# independently of the child class's.
|
|
@@ -134,7 +151,7 @@ module AbstractController
|
|
|
134
151
|
begin
|
|
135
152
|
require_dependency(file_name)
|
|
136
153
|
rescue LoadError => e
|
|
137
|
-
raise MissingHelperError.new(e, file_name)
|
|
154
|
+
raise AbstractController::Helpers::MissingHelperError.new(e, file_name)
|
|
138
155
|
end
|
|
139
156
|
file_name.camelize.constantize
|
|
140
157
|
when Module
|
|
@@ -145,20 +162,6 @@ module AbstractController
|
|
|
145
162
|
end
|
|
146
163
|
end
|
|
147
164
|
|
|
148
|
-
class MissingHelperError < LoadError
|
|
149
|
-
def initialize(error, path)
|
|
150
|
-
@error = error
|
|
151
|
-
@path = "helpers/#{path}.rb"
|
|
152
|
-
set_backtrace error.backtrace
|
|
153
|
-
|
|
154
|
-
if error.path =~ /^#{path}(\.rb)?$/
|
|
155
|
-
super("Missing helper file helpers/%s.rb" % path)
|
|
156
|
-
else
|
|
157
|
-
raise error
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
165
|
private
|
|
163
166
|
# Makes all the (instance) methods in the helper module available to templates
|
|
164
167
|
# rendered through this controller.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
require 'active_support/core_ext/class/attribute'
|
|
3
|
+
require 'action_view/view_paths'
|
|
4
|
+
require 'set'
|
|
3
5
|
|
|
4
6
|
module AbstractController
|
|
5
7
|
class DoubleRenderError < Error
|
|
@@ -10,91 +12,18 @@ module AbstractController
|
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
# This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
|
|
14
|
-
# it will trigger the lookup_context and consequently expire the cache.
|
|
15
|
-
class I18nProxy < ::I18n::Config #:nodoc:
|
|
16
|
-
attr_reader :original_config, :lookup_context
|
|
17
|
-
|
|
18
|
-
def initialize(original_config, lookup_context)
|
|
19
|
-
original_config = original_config.original_config if original_config.respond_to?(:original_config)
|
|
20
|
-
@original_config, @lookup_context = original_config, lookup_context
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def locale
|
|
24
|
-
@original_config.locale
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def locale=(value)
|
|
28
|
-
@lookup_context.locale = value
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
15
|
module Rendering
|
|
33
16
|
extend ActiveSupport::Concern
|
|
34
|
-
include
|
|
35
|
-
|
|
36
|
-
included do
|
|
37
|
-
class_attribute :protected_instance_variables
|
|
38
|
-
self.protected_instance_variables = []
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Overwrite process to setup I18n proxy.
|
|
42
|
-
def process(*) #:nodoc:
|
|
43
|
-
old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
|
|
44
|
-
super
|
|
45
|
-
ensure
|
|
46
|
-
I18n.config = old_config
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
module ClassMethods
|
|
50
|
-
def view_context_class
|
|
51
|
-
@view_context_class ||= begin
|
|
52
|
-
routes = respond_to?(:_routes) && _routes
|
|
53
|
-
helpers = respond_to?(:_helpers) && _helpers
|
|
54
|
-
|
|
55
|
-
Class.new(ActionView::Base) do
|
|
56
|
-
if routes
|
|
57
|
-
include routes.url_helpers
|
|
58
|
-
include routes.mounted_helpers
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
if helpers
|
|
62
|
-
include helpers
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
attr_internal_writer :view_context_class
|
|
70
|
-
|
|
71
|
-
def view_context_class
|
|
72
|
-
@_view_context_class ||= self.class.view_context_class
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# An instance of a view class. The default view class is ActionView::Base
|
|
76
|
-
#
|
|
77
|
-
# The view class must have the following methods:
|
|
78
|
-
# View.new[lookup_context, assigns, controller]
|
|
79
|
-
# Create a new ActionView instance for a controller
|
|
80
|
-
# View#render[options]
|
|
81
|
-
# Returns String with the rendered template
|
|
82
|
-
#
|
|
83
|
-
# Override this method in a module to change the default behavior.
|
|
84
|
-
def view_context
|
|
85
|
-
view_context_class.new(view_renderer, view_assigns, self)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Returns an object that is able to render templates.
|
|
89
|
-
def view_renderer
|
|
90
|
-
@_view_renderer ||= ActionView::Renderer.new(lookup_context)
|
|
91
|
-
end
|
|
17
|
+
include ActionView::ViewPaths
|
|
92
18
|
|
|
93
19
|
# Normalize arguments, options and then delegates render_to_body and
|
|
94
20
|
# sticks the result in self.response_body.
|
|
21
|
+
# :api: public
|
|
95
22
|
def render(*args, &block)
|
|
96
23
|
options = _normalize_render(*args, &block)
|
|
97
24
|
self.response_body = render_to_body(options)
|
|
25
|
+
_process_format(rendered_format)
|
|
26
|
+
self.response_body
|
|
98
27
|
end
|
|
99
28
|
|
|
100
29
|
# Raw rendering of a template to a string.
|
|
@@ -113,84 +42,76 @@ module AbstractController
|
|
|
113
42
|
render_to_body(options)
|
|
114
43
|
end
|
|
115
44
|
|
|
116
|
-
#
|
|
117
|
-
# :api:
|
|
45
|
+
# Performs the actual template rendering.
|
|
46
|
+
# :api: public
|
|
118
47
|
def render_to_body(options = {})
|
|
119
|
-
_process_options(options)
|
|
120
|
-
_render_template(options)
|
|
121
48
|
end
|
|
122
49
|
|
|
123
|
-
#
|
|
124
|
-
# :api:
|
|
125
|
-
def
|
|
126
|
-
|
|
127
|
-
view_renderer.render(view_context, options)
|
|
50
|
+
# Return Content-Type of rendered content
|
|
51
|
+
# :api: public
|
|
52
|
+
def rendered_format
|
|
53
|
+
Mime::TEXT
|
|
128
54
|
end
|
|
129
55
|
|
|
130
|
-
DEFAULT_PROTECTED_INSTANCE_VARIABLES =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
56
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %w(
|
|
57
|
+
@_action_name @_response_body @_formats @_prefixes @_config
|
|
58
|
+
@_view_context_class @_view_renderer @_lookup_context
|
|
59
|
+
@_routes @_db_runtime
|
|
60
|
+
).map(&:to_sym)
|
|
134
61
|
|
|
135
62
|
# This method should return a hash with assigns.
|
|
136
63
|
# You can overwrite this configuration per controller.
|
|
137
64
|
# :api: public
|
|
138
65
|
def view_assigns
|
|
139
|
-
|
|
140
|
-
variables
|
|
141
|
-
variables -= protected_instance_variables
|
|
142
|
-
variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
|
|
143
|
-
variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) }
|
|
144
|
-
hash
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
private
|
|
66
|
+
protected_vars = _protected_ivars
|
|
67
|
+
variables = instance_variables
|
|
148
68
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
_normalize_options(options)
|
|
154
|
-
options
|
|
69
|
+
variables.reject! { |s| protected_vars.include? s }
|
|
70
|
+
variables.each_with_object({}) { |name, hash|
|
|
71
|
+
hash[name.slice(1, name.length)] = instance_variable_get(name)
|
|
72
|
+
}
|
|
155
73
|
end
|
|
156
74
|
|
|
157
75
|
# Normalize args by converting render "foo" to render :action => "foo" and
|
|
158
76
|
# render "foo/bar" to render :file => "foo/bar".
|
|
159
77
|
# :api: plugin
|
|
160
78
|
def _normalize_args(action=nil, options={})
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
when Hash
|
|
164
|
-
options = action
|
|
165
|
-
when String, Symbol
|
|
166
|
-
action = action.to_s
|
|
167
|
-
key = action.include?(?/) ? :file : :action
|
|
168
|
-
options[key] = action
|
|
79
|
+
if action.is_a? Hash
|
|
80
|
+
action
|
|
169
81
|
else
|
|
170
|
-
options
|
|
82
|
+
options
|
|
171
83
|
end
|
|
172
|
-
|
|
173
|
-
options
|
|
174
84
|
end
|
|
175
85
|
|
|
176
86
|
# Normalize options.
|
|
177
87
|
# :api: plugin
|
|
178
88
|
def _normalize_options(options)
|
|
179
|
-
if options[:partial] == true
|
|
180
|
-
options[:partial] = action_name
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
if (options.keys & [:partial, :file, :template]).empty?
|
|
184
|
-
options[:prefixes] ||= _prefixes
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
options[:template] ||= (options[:action] || action_name).to_s
|
|
188
89
|
options
|
|
189
90
|
end
|
|
190
91
|
|
|
191
92
|
# Process extra options.
|
|
192
93
|
# :api: plugin
|
|
193
94
|
def _process_options(options)
|
|
95
|
+
options
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Process the rendered format.
|
|
99
|
+
# :api: private
|
|
100
|
+
def _process_format(format)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Normalize args and options.
|
|
104
|
+
# :api: private
|
|
105
|
+
def _normalize_render(*args, &block)
|
|
106
|
+
options = _normalize_args(*args, &block)
|
|
107
|
+
#TODO: remove defined? when we restore AP <=> AV dependency
|
|
108
|
+
options[:variant] = request.variant if defined?(request) && request.variant.present?
|
|
109
|
+
_normalize_options(options)
|
|
110
|
+
options
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def _protected_ivars # :nodoc:
|
|
114
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES
|
|
194
115
|
end
|
|
195
116
|
end
|
|
196
117
|
end
|
data/lib/action_controller.rb
CHANGED
|
@@ -40,33 +40,17 @@ module ActionController
|
|
|
40
40
|
autoload :UrlFor
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
autoload :Integration, 'action_controller/deprecated/integration_test'
|
|
44
|
-
autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
|
|
45
|
-
autoload :Routing, 'action_controller/deprecated'
|
|
46
43
|
autoload :TestCase, 'action_controller/test_case'
|
|
47
44
|
autoload :TemplateAssertions, 'action_controller/test_case'
|
|
48
45
|
|
|
49
|
-
eager_autoload do
|
|
50
|
-
autoload :RecordIdentifier
|
|
51
|
-
end
|
|
52
|
-
|
|
53
46
|
def self.eager_load!
|
|
54
47
|
super
|
|
55
48
|
ActionController::Caching.eager_load!
|
|
56
|
-
HTML.eager_load!
|
|
57
49
|
end
|
|
58
50
|
end
|
|
59
51
|
|
|
60
|
-
# All of these simply register additional autoloads
|
|
61
|
-
require 'action_view'
|
|
62
|
-
require 'action_view/vendor/html-scanner'
|
|
63
|
-
|
|
64
|
-
ActiveSupport.on_load(:action_view) do
|
|
65
|
-
ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
52
|
# Common Active Support usage in Action Controller
|
|
69
|
-
require 'active_support/core_ext/
|
|
53
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
|
70
54
|
require 'active_support/core_ext/load_error'
|
|
71
55
|
require 'active_support/core_ext/module/attr_internal'
|
|
72
56
|
require 'active_support/core_ext/name_error'
|