actionpack 3.2.22.5 → 5.2.4
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 +5 -5
- data/CHANGELOG.md +279 -603
- data/MIT-LICENSE +1 -1
- data/README.rdoc +13 -297
- data/lib/abstract_controller/asset_paths.rb +4 -2
- data/lib/abstract_controller/base.rb +82 -52
- data/lib/abstract_controller/caching/fragments.rb +166 -0
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/abstract_controller/callbacks.rb +117 -103
- data/lib/abstract_controller/collector.rb +18 -7
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +65 -38
- data/lib/abstract_controller/logger.rb +3 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
- data/lib/abstract_controller/rendering.rb +77 -129
- data/lib/abstract_controller/translation.rb +21 -3
- data/lib/abstract_controller/url_for.rb +9 -7
- data/lib/abstract_controller.rb +12 -13
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/base.rb +81 -40
- data/lib/action_controller/caching.rb +22 -62
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +30 -18
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +190 -47
- data/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/lib/action_controller/metal/cookies.rb +3 -3
- data/lib/action_controller/metal/data_streaming.rb +40 -65
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
- data/lib/action_controller/metal/exceptions.rb +19 -12
- data/lib/action_controller/metal/flash.rb +42 -9
- data/lib/action_controller/metal/force_ssl.rb +79 -19
- data/lib/action_controller/metal/head.rb +35 -10
- data/lib/action_controller/metal/helpers.rb +31 -21
- data/lib/action_controller/metal/http_authentication.rb +182 -134
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +28 -26
- data/lib/action_controller/metal/live.rb +312 -0
- data/lib/action_controller/metal/mime_responds.rb +159 -163
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +146 -93
- data/lib/action_controller/metal/redirecting.rb +80 -56
- data/lib/action_controller/metal/renderers.rb +119 -47
- data/lib/action_controller/metal/rendering.rb +89 -32
- data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +39 -45
- data/lib/action_controller/metal/strong_parameters.rb +1086 -0
- data/lib/action_controller/metal/testing.rb +8 -29
- data/lib/action_controller/metal/url_for.rb +43 -32
- data/lib/action_controller/metal.rb +112 -106
- data/lib/action_controller/railtie.rb +56 -18
- data/lib/action_controller/railties/helpers.rb +24 -0
- data/lib/action_controller/renderer.rb +117 -0
- data/lib/action_controller/template_assertions.rb +11 -0
- data/lib/action_controller/test_case.rb +402 -347
- data/lib/action_controller.rb +31 -30
- data/lib/action_dispatch/http/cache.rb +133 -34
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +40 -24
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +117 -16
- data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
- data/lib/action_dispatch/http/mime_type.rb +198 -146
- data/lib/action_dispatch/http/mime_types.rb +22 -7
- data/lib/action_dispatch/http/parameter_filter.rb +61 -49
- data/lib/action_dispatch/http/parameters.rb +94 -51
- data/lib/action_dispatch/http/rack_cache.rb +4 -3
- data/lib/action_dispatch/http/request.rb +262 -117
- data/lib/action_dispatch/http/response.rb +400 -86
- data/lib/action_dispatch/http/upload.rb +66 -29
- data/lib/action_dispatch/http/url.rb +232 -60
- data/lib/action_dispatch/journey/formatter.rb +189 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
- data/lib/action_dispatch/journey/nodes/node.rb +140 -0
- data/lib/action_dispatch/journey/parser.rb +199 -0
- data/lib/action_dispatch/journey/parser.y +50 -0
- data/lib/action_dispatch/journey/parser_extras.rb +31 -0
- data/lib/action_dispatch/journey/path/pattern.rb +199 -0
- data/lib/action_dispatch/journey/route.rb +203 -0
- data/lib/action_dispatch/journey/router/utils.rb +102 -0
- data/lib/action_dispatch/journey/router.rb +156 -0
- data/lib/action_dispatch/journey/routes.rb +82 -0
- data/lib/action_dispatch/journey/scanner.rb +64 -0
- data/lib/action_dispatch/journey/visitors.rb +268 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +7 -0
- data/lib/action_dispatch/middleware/callbacks.rb +17 -13
- data/lib/action_dispatch/middleware/cookies.rb +494 -162
- data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +128 -91
- data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
- data/lib/action_dispatch/middleware/reloader.rb +6 -83
- data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
- data/lib/action_dispatch/middleware/request_id.rb +19 -15
- data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
- data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
- data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
- data/lib/action_dispatch/middleware/ssl.rb +150 -0
- data/lib/action_dispatch/middleware/stack.rb +33 -41
- data/lib/action_dispatch/middleware/static.rb +92 -48
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/lib/action_dispatch/railtie.rb +29 -8
- data/lib/action_dispatch/request/session.rb +234 -0
- data/lib/action_dispatch/request/utils.rb +78 -0
- data/lib/action_dispatch/routing/endpoint.rb +17 -0
- data/lib/action_dispatch/routing/inspector.rb +225 -0
- data/lib/action_dispatch/routing/mapper.rb +1329 -582
- data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
- data/lib/action_dispatch/routing/redirection.rb +120 -50
- data/lib/action_dispatch/routing/route_set.rb +545 -322
- data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
- data/lib/action_dispatch/routing/url_for.rb +103 -34
- data/lib/action_dispatch/routing.rb +66 -99
- data/lib/action_dispatch/system_test_case.rb +147 -0
- data/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/lib/action_dispatch/system_testing/server.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/lib/action_dispatch/testing/assertions/response.rb +53 -42
- data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
- data/lib/action_dispatch/testing/assertions.rb +15 -9
- data/lib/action_dispatch/testing/integration.rb +361 -207
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -19
- data/lib/action_dispatch/testing/test_request.rb +30 -33
- data/lib/action_dispatch/testing/test_response.rb +35 -11
- data/lib/action_dispatch.rb +42 -32
- data/lib/action_pack/gem_version.rb +17 -0
- data/lib/action_pack/version.rb +7 -7
- data/lib/action_pack.rb +4 -2
- metadata +116 -175
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/fragments.rb +0 -127
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/integration_test.rb +0 -2
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/deprecated.rb +0 -3
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/hide_actions.rb +0 -41
- data/lib/action_controller/metal/rack_delegation.rb +0 -26
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_controller/record_identifier.rb +0 -85
- data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_controller/vendor/html-scanner.rb +0 -20
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/params_parser.rb +0 -75
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/base.rb +0 -220
- data/lib/action_view/buffers.rb +0 -43
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/flows.rb +0 -79
- data/lib/action_view/helpers/active_model_helper.rb +0 -50
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
- data/lib/action_view/helpers/cache_helper.rb +0 -64
- data/lib/action_view/helpers/capture_helper.rb +0 -203
- 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 -1062
- data/lib/action_view/helpers/debug_helper.rb +0 -40
- data/lib/action_view/helpers/form_helper.rb +0 -1486
- data/lib/action_view/helpers/form_options_helper.rb +0 -658
- data/lib/action_view/helpers/form_tag_helper.rb +0 -685
- data/lib/action_view/helpers/javascript_helper.rb +0 -110
- data/lib/action_view/helpers/number_helper.rb +0 -622
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -111
- data/lib/action_view/helpers/rendering_helper.rb +0 -92
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -167
- data/lib/action_view/helpers/text_helper.rb +0 -426
- data/lib/action_view/helpers/translation_helper.rb +0 -91
- data/lib/action_view/helpers/url_helper.rb +0 -693
- data/lib/action_view/helpers.rb +0 -60
- data/lib/action_view/locale/en.yml +0 -160
- data/lib/action_view/log_subscriber.rb +0 -28
- data/lib/action_view/lookup_context.rb +0 -258
- data/lib/action_view/path_set.rb +0 -101
- data/lib/action_view/railtie.rb +0 -55
- data/lib/action_view/renderer/abstract_renderer.rb +0 -41
- data/lib/action_view/renderer/partial_renderer.rb +0 -415
- data/lib/action_view/renderer/renderer.rb +0 -61
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -95
- data/lib/action_view/template/error.rb +0 -128
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -125
- data/lib/action_view/template/handlers.rb +0 -50
- data/lib/action_view/template/resolver.rb +0 -298
- data/lib/action_view/template/text.rb +0 -30
- data/lib/action_view/template.rb +0 -337
- data/lib/action_view/test_case.rb +0 -246
- data/lib/action_view/testing/resolvers.rb +0 -49
- data/lib/action_view.rb +0 -84
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/dependencies"
|
|
2
4
|
|
|
3
5
|
module AbstractController
|
|
4
6
|
module Helpers
|
|
5
7
|
extend ActiveSupport::Concern
|
|
6
8
|
|
|
7
9
|
included do
|
|
8
|
-
class_attribute :_helpers
|
|
9
|
-
|
|
10
|
+
class_attribute :_helpers, default: Module.new
|
|
11
|
+
class_attribute :_helper_methods, default: Array.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class MissingHelperError < LoadError
|
|
15
|
+
def initialize(error, path)
|
|
16
|
+
@error = error
|
|
17
|
+
@path = "helpers/#{path}.rb"
|
|
18
|
+
set_backtrace error.backtrace
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
if error.path =~ /^#{path}(\.rb)?$/
|
|
21
|
+
super("Missing helper file helpers/%s.rb" % path)
|
|
22
|
+
else
|
|
23
|
+
raise error
|
|
24
|
+
end
|
|
25
|
+
end
|
|
13
26
|
end
|
|
14
27
|
|
|
15
28
|
module ClassMethods
|
|
@@ -19,22 +32,23 @@ module AbstractController
|
|
|
19
32
|
def inherited(klass)
|
|
20
33
|
helpers = _helpers
|
|
21
34
|
klass._helpers = Module.new { include helpers }
|
|
22
|
-
klass.class_eval { default_helper_module! unless anonymous?
|
|
35
|
+
klass.class_eval { default_helper_module! } unless klass.anonymous?
|
|
23
36
|
super
|
|
24
37
|
end
|
|
25
38
|
|
|
26
39
|
# Declare a controller method as a helper. For example, the following
|
|
27
|
-
# makes the +current_user+ controller
|
|
40
|
+
# makes the +current_user+ and +logged_in?+ controller methods available
|
|
41
|
+
# to the view:
|
|
28
42
|
# class ApplicationController < ActionController::Base
|
|
29
43
|
# helper_method :current_user, :logged_in?
|
|
30
44
|
#
|
|
31
45
|
# def current_user
|
|
32
|
-
# @current_user ||= User.
|
|
46
|
+
# @current_user ||= User.find_by(id: session[:user])
|
|
33
47
|
# end
|
|
34
48
|
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
49
|
+
# def logged_in?
|
|
50
|
+
# current_user != nil
|
|
51
|
+
# end
|
|
38
52
|
# end
|
|
39
53
|
#
|
|
40
54
|
# In a view:
|
|
@@ -49,20 +63,19 @@ module AbstractController
|
|
|
49
63
|
|
|
50
64
|
meths.each do |meth|
|
|
51
65
|
_helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
|
|
52
|
-
def #{meth}(*args, &blk)
|
|
53
|
-
controller.send(%(#{meth}), *args, &blk)
|
|
54
|
-
end
|
|
66
|
+
def #{meth}(*args, &blk) # def current_user(*args, &blk)
|
|
67
|
+
controller.send(%(#{meth}), *args, &blk) # controller.send(:current_user, *args, &blk)
|
|
68
|
+
end # end
|
|
55
69
|
ruby_eval
|
|
56
70
|
end
|
|
57
71
|
end
|
|
58
72
|
|
|
59
73
|
# The +helper+ class method can take a series of helper module names, a block, or both.
|
|
60
74
|
#
|
|
61
|
-
# ====
|
|
62
|
-
# * <tt>*args</tt> - Module, Symbol, String
|
|
75
|
+
# ==== Options
|
|
76
|
+
# * <tt>*args</tt> - Module, Symbol, String
|
|
63
77
|
# * <tt>block</tt> - A block defining helper methods
|
|
64
78
|
#
|
|
65
|
-
# ==== Examples
|
|
66
79
|
# When the argument is a module it will be included directly in the template class.
|
|
67
80
|
# helper FooHelper # => includes FooHelper
|
|
68
81
|
#
|
|
@@ -114,7 +127,7 @@ module AbstractController
|
|
|
114
127
|
# helpers with the following behavior:
|
|
115
128
|
#
|
|
116
129
|
# String or Symbol:: :FooBar or "FooBar" becomes "foo_bar_helper",
|
|
117
|
-
#
|
|
130
|
+
# and "foo_bar_helper.rb" is loaded using require_dependency.
|
|
118
131
|
#
|
|
119
132
|
# Module:: No further processing
|
|
120
133
|
#
|
|
@@ -132,8 +145,22 @@ module AbstractController
|
|
|
132
145
|
case arg
|
|
133
146
|
when String, Symbol
|
|
134
147
|
file_name = "#{arg.to_s.underscore}_helper"
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
begin
|
|
149
|
+
require_dependency(file_name)
|
|
150
|
+
rescue LoadError => e
|
|
151
|
+
raise AbstractController::Helpers::MissingHelperError.new(e, file_name)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
mod_name = file_name.camelize
|
|
155
|
+
begin
|
|
156
|
+
mod_name.constantize
|
|
157
|
+
rescue LoadError
|
|
158
|
+
# dependencies.rb gives a similar error message but its wording is
|
|
159
|
+
# not as clear because it mentions autoloading. To the user all it
|
|
160
|
+
# matters is that a helper module couldn't be loaded, autoloading
|
|
161
|
+
# is an internal mechanism that should not leak.
|
|
162
|
+
raise NameError, "Couldn't find #{mod_name}, expected it to be defined in helpers/#{file_name}.rb"
|
|
163
|
+
end
|
|
137
164
|
when Module
|
|
138
165
|
arg
|
|
139
166
|
else
|
|
@@ -143,25 +170,25 @@ module AbstractController
|
|
|
143
170
|
end
|
|
144
171
|
|
|
145
172
|
private
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
173
|
+
# Makes all the (instance) methods in the helper module available to templates
|
|
174
|
+
# rendered through this controller.
|
|
175
|
+
#
|
|
176
|
+
# ==== Parameters
|
|
177
|
+
# * <tt>module</tt> - The module to include into the current helper module
|
|
178
|
+
# for the class
|
|
179
|
+
def add_template_helper(mod)
|
|
180
|
+
_helpers.module_eval { include mod }
|
|
181
|
+
end
|
|
155
182
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
183
|
+
def default_helper_module!
|
|
184
|
+
module_name = name.sub(/Controller$/, "".freeze)
|
|
185
|
+
module_path = module_name.underscore
|
|
186
|
+
helper module_path
|
|
187
|
+
rescue LoadError => e
|
|
188
|
+
raise e unless e.is_missing? "helpers/#{module_path}_helper"
|
|
189
|
+
rescue NameError => e
|
|
190
|
+
raise e unless e.missing_name? "#{module_name}Helper"
|
|
191
|
+
end
|
|
165
192
|
end
|
|
166
193
|
end
|
|
167
194
|
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module AbstractController
|
|
2
4
|
module Railties
|
|
3
5
|
module RoutesHelpers
|
|
4
|
-
def self.with(routes)
|
|
6
|
+
def self.with(routes, include_path_helpers = true)
|
|
5
7
|
Module.new do
|
|
6
8
|
define_method(:inherited) do |klass|
|
|
7
9
|
super(klass)
|
|
8
10
|
if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
|
|
9
|
-
klass.
|
|
11
|
+
klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
|
|
10
12
|
else
|
|
11
|
-
klass.
|
|
13
|
+
klass.include(routes.url_helpers(include_path_helpers))
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "abstract_controller/error"
|
|
2
4
|
require "action_view"
|
|
3
|
-
require "
|
|
4
|
-
require "
|
|
5
|
+
require "action_view/view_paths"
|
|
6
|
+
require "set"
|
|
5
7
|
|
|
6
8
|
module AbstractController
|
|
7
9
|
class DoubleRenderError < Error
|
|
@@ -12,168 +14,114 @@ module AbstractController
|
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
# This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
|
|
16
|
-
# it will trigger the lookup_context and consequently expire the cache.
|
|
17
|
-
class I18nProxy < ::I18n::Config #:nodoc:
|
|
18
|
-
attr_reader :original_config, :lookup_context
|
|
19
|
-
|
|
20
|
-
def initialize(original_config, lookup_context)
|
|
21
|
-
original_config = original_config.original_config if original_config.respond_to?(:original_config)
|
|
22
|
-
@original_config, @lookup_context = original_config, lookup_context
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def locale
|
|
26
|
-
@original_config.locale
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def locale=(value)
|
|
30
|
-
@lookup_context.locale = value
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
17
|
module Rendering
|
|
35
18
|
extend ActiveSupport::Concern
|
|
36
|
-
include
|
|
37
|
-
|
|
38
|
-
included do
|
|
39
|
-
class_attribute :protected_instance_variables
|
|
40
|
-
self.protected_instance_variables = []
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Overwrite process to setup I18n proxy.
|
|
44
|
-
def process(*) #:nodoc:
|
|
45
|
-
old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
|
|
46
|
-
super
|
|
47
|
-
ensure
|
|
48
|
-
I18n.config = old_config
|
|
49
|
-
end
|
|
19
|
+
include ActionView::ViewPaths
|
|
50
20
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
21
|
+
# Normalizes arguments, options and then delegates render_to_body and
|
|
22
|
+
# sticks the result in <tt>self.response_body</tt>.
|
|
23
|
+
def render(*args, &block)
|
|
24
|
+
options = _normalize_render(*args, &block)
|
|
25
|
+
rendered_body = render_to_body(options)
|
|
26
|
+
if options[:html]
|
|
27
|
+
_set_html_content_type
|
|
28
|
+
else
|
|
29
|
+
_set_rendered_content_type rendered_format
|
|
58
30
|
end
|
|
31
|
+
self.response_body = rendered_body
|
|
59
32
|
end
|
|
60
33
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def view_context_class
|
|
64
|
-
@_view_context_class ||= self.class.view_context_class
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# An instance of a view class. The default view class is ActionView::Base
|
|
34
|
+
# Raw rendering of a template to a string.
|
|
68
35
|
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
# View#render[options]
|
|
73
|
-
# Returns String with the rendered template
|
|
36
|
+
# It is similar to render, except that it does not
|
|
37
|
+
# set the +response_body+ and it should be guaranteed
|
|
38
|
+
# to always return a string.
|
|
74
39
|
#
|
|
75
|
-
#
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# Returns an object that is able to render templates.
|
|
81
|
-
def view_renderer
|
|
82
|
-
@_view_renderer ||= ActionView::Renderer.new(lookup_context)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Normalize arguments, options and then delegates render_to_body and
|
|
86
|
-
# sticks the result in self.response_body.
|
|
87
|
-
def render(*args, &block)
|
|
88
|
-
options = _normalize_render(*args, &block)
|
|
89
|
-
self.response_body = render_to_body(options)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# Raw rendering of a template to a string. Just convert the results of
|
|
93
|
-
# render_response into a String.
|
|
94
|
-
# :api: plugin
|
|
40
|
+
# If a component extends the semantics of +response_body+
|
|
41
|
+
# (as ActionController extends it to be anything that
|
|
42
|
+
# responds to the method each), this method needs to be
|
|
43
|
+
# overridden in order to still return a string.
|
|
95
44
|
def render_to_string(*args, &block)
|
|
96
45
|
options = _normalize_render(*args, &block)
|
|
97
46
|
render_to_body(options)
|
|
98
47
|
end
|
|
99
48
|
|
|
100
|
-
#
|
|
101
|
-
# :api: plugin
|
|
49
|
+
# Performs the actual template rendering.
|
|
102
50
|
def render_to_body(options = {})
|
|
103
|
-
_process_options(options)
|
|
104
|
-
_render_template(options)
|
|
105
51
|
end
|
|
106
52
|
|
|
107
|
-
#
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
lookup_context.rendered_format = nil if options[:formats]
|
|
111
|
-
view_renderer.render(view_context, options)
|
|
53
|
+
# Returns Content-Type of rendered content.
|
|
54
|
+
def rendered_format
|
|
55
|
+
Mime[:text]
|
|
112
56
|
end
|
|
113
57
|
|
|
114
|
-
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %
|
|
115
|
-
@_action_name @_response_body @_formats @_prefixes
|
|
116
|
-
@_view_context_class @_view_renderer @_lookup_context
|
|
58
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %i(
|
|
59
|
+
@_action_name @_response_body @_formats @_prefixes
|
|
117
60
|
)
|
|
118
61
|
|
|
119
62
|
# This method should return a hash with assigns.
|
|
120
63
|
# You can overwrite this configuration per controller.
|
|
121
|
-
# :api: public
|
|
122
64
|
def view_assigns
|
|
123
|
-
|
|
124
|
-
variables
|
|
125
|
-
|
|
126
|
-
variables
|
|
127
|
-
variables.
|
|
128
|
-
|
|
65
|
+
protected_vars = _protected_ivars
|
|
66
|
+
variables = instance_variables
|
|
67
|
+
|
|
68
|
+
variables.reject! { |s| protected_vars.include? s }
|
|
69
|
+
variables.each_with_object({}) { |name, hash|
|
|
70
|
+
hash[name.slice(1, name.length)] = instance_variable_get(name)
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
# Normalize args by converting <tt>render "foo"</tt> to
|
|
76
|
+
# <tt>render :action => "foo"</tt> and <tt>render "foo/bar"</tt> to
|
|
77
|
+
# <tt>render :file => "foo/bar"</tt>.
|
|
78
|
+
def _normalize_args(action = nil, options = {}) # :doc:
|
|
79
|
+
if action.respond_to?(:permitted?)
|
|
80
|
+
if action.permitted?
|
|
81
|
+
action
|
|
82
|
+
else
|
|
83
|
+
raise ArgumentError, "render parameters are not permitted"
|
|
84
|
+
end
|
|
85
|
+
elsif action.is_a?(Hash)
|
|
86
|
+
action
|
|
87
|
+
else
|
|
88
|
+
options
|
|
89
|
+
end
|
|
129
90
|
end
|
|
130
91
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
# Normalize args and options.
|
|
134
|
-
# :api: private
|
|
135
|
-
def _normalize_render(*args, &block)
|
|
136
|
-
options = _normalize_args(*args, &block)
|
|
137
|
-
_normalize_options(options)
|
|
92
|
+
# Normalize options.
|
|
93
|
+
def _normalize_options(options) # :doc:
|
|
138
94
|
options
|
|
139
95
|
end
|
|
140
96
|
|
|
141
|
-
#
|
|
142
|
-
|
|
143
|
-
# :api: plugin
|
|
144
|
-
def _normalize_args(action=nil, options={})
|
|
145
|
-
case action
|
|
146
|
-
when NilClass
|
|
147
|
-
when Hash
|
|
148
|
-
options = action
|
|
149
|
-
when String, Symbol
|
|
150
|
-
action = action.to_s
|
|
151
|
-
key = action.include?(?/) ? :app_template_file : :action
|
|
152
|
-
options[key] = action
|
|
153
|
-
else
|
|
154
|
-
options[:partial] = action
|
|
155
|
-
end
|
|
97
|
+
# Process extra options.
|
|
98
|
+
def _process_options(options) # :doc:
|
|
156
99
|
options
|
|
157
100
|
end
|
|
158
101
|
|
|
159
|
-
#
|
|
160
|
-
# :
|
|
161
|
-
|
|
162
|
-
if options[:partial] == true
|
|
163
|
-
options[:partial] = action_name
|
|
164
|
-
end
|
|
102
|
+
# Process the rendered format.
|
|
103
|
+
def _process_format(format) # :nodoc:
|
|
104
|
+
end
|
|
165
105
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
106
|
+
def _process_variant(options)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def _set_html_content_type # :nodoc:
|
|
110
|
+
end
|
|
169
111
|
|
|
170
|
-
|
|
112
|
+
def _set_rendered_content_type(format) # :nodoc:
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Normalize args and options.
|
|
116
|
+
def _normalize_render(*args, &block) # :nodoc:
|
|
117
|
+
options = _normalize_args(*args, &block)
|
|
118
|
+
_process_variant(options)
|
|
119
|
+
_normalize_options(options)
|
|
171
120
|
options
|
|
172
121
|
end
|
|
173
122
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def _process_options(options)
|
|
123
|
+
def _protected_ivars # :nodoc:
|
|
124
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES
|
|
177
125
|
end
|
|
178
126
|
end
|
|
179
127
|
end
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module AbstractController
|
|
2
4
|
module Translation
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
# Delegates to <tt>I18n.translate</tt>. Also aliased as <tt>t</tt>.
|
|
6
|
+
#
|
|
7
|
+
# When the given key starts with a period, it will be scoped by the current
|
|
8
|
+
# controller and action. So if you call <tt>translate(".foo")</tt> from
|
|
9
|
+
# <tt>PeopleController#index</tt>, it will convert the call to
|
|
10
|
+
# <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
|
|
11
|
+
# to translate many keys within the same controller / action and gives you a
|
|
12
|
+
# simple framework for scoping them consistently.
|
|
13
|
+
def translate(key, options = {})
|
|
14
|
+
if key.to_s.first == "."
|
|
15
|
+
path = controller_path.tr("/", ".")
|
|
16
|
+
defaults = [:"#{path}#{key}"]
|
|
17
|
+
defaults << options[:default] if options[:default]
|
|
18
|
+
options[:default] = defaults.flatten
|
|
19
|
+
key = "#{path}.#{action_name}#{key}"
|
|
20
|
+
end
|
|
21
|
+
I18n.translate(key, options)
|
|
5
22
|
end
|
|
6
23
|
alias :t :translate
|
|
7
24
|
|
|
25
|
+
# Delegates to <tt>I18n.localize</tt>. Also aliased as <tt>l</tt>.
|
|
8
26
|
def localize(*args)
|
|
9
27
|
I18n.localize(*args)
|
|
10
28
|
end
|
|
11
29
|
alias :l :localize
|
|
12
30
|
end
|
|
13
|
-
end
|
|
31
|
+
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
# exception will be raised.
|
|
4
|
-
#
|
|
5
|
-
# Note that this module is completely decoupled from HTTP - the only requirement is a valid
|
|
6
|
-
# <tt>_routes</tt> implementation.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
7
3
|
module AbstractController
|
|
4
|
+
# Includes +url_for+ into the host class (e.g. an abstract controller or mailer). The class
|
|
5
|
+
# has to provide a +RouteSet+ by implementing the <tt>_routes</tt> methods. Otherwise, an
|
|
6
|
+
# exception will be raised.
|
|
7
|
+
#
|
|
8
|
+
# Note that this module is completely decoupled from HTTP - the only requirement is a valid
|
|
9
|
+
# <tt>_routes</tt> implementation.
|
|
8
10
|
module UrlFor
|
|
9
11
|
extend ActiveSupport::Concern
|
|
10
12
|
include ActionDispatch::Routing::UrlFor
|
|
11
13
|
|
|
12
14
|
def _routes
|
|
13
15
|
raise "In order to use #url_for, you must include routing helpers explicitly. " \
|
|
14
|
-
"For instance, `include Rails.application.routes.url_helpers"
|
|
16
|
+
"For instance, `include Rails.application.routes.url_helpers`."
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
module ClassMethods
|
data/lib/abstract_controller.rb
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require 'active_support/dependencies/autoload'
|
|
8
|
-
require 'active_support/core_ext/class/attribute'
|
|
9
|
-
require 'active_support/core_ext/module/attr_internal'
|
|
10
|
-
require 'active_support/core_ext/module/delegation'
|
|
11
|
-
require 'active_support/core_ext/module/anonymous'
|
|
12
|
-
require 'active_support/i18n'
|
|
3
|
+
require "action_pack"
|
|
4
|
+
require "active_support/rails"
|
|
5
|
+
require "active_support/i18n"
|
|
13
6
|
|
|
14
7
|
module AbstractController
|
|
15
8
|
extend ActiveSupport::Autoload
|
|
16
9
|
|
|
10
|
+
autoload :ActionNotFound, "abstract_controller/base"
|
|
17
11
|
autoload :Base
|
|
12
|
+
autoload :Caching
|
|
18
13
|
autoload :Callbacks
|
|
19
14
|
autoload :Collector
|
|
15
|
+
autoload :DoubleRenderError, "abstract_controller/rendering"
|
|
20
16
|
autoload :Helpers
|
|
21
|
-
autoload :Layouts
|
|
22
17
|
autoload :Logger
|
|
23
18
|
autoload :Rendering
|
|
24
19
|
autoload :Translation
|
|
25
20
|
autoload :AssetPaths
|
|
26
|
-
autoload :ViewPaths
|
|
27
21
|
autoload :UrlFor
|
|
22
|
+
|
|
23
|
+
def self.eager_load!
|
|
24
|
+
super
|
|
25
|
+
AbstractController::Caching.eager_load!
|
|
26
|
+
end
|
|
28
27
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActionController
|
|
4
|
+
module ApiRendering
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include Rendering
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def render_to_body(options = {})
|
|
12
|
+
_process_options(options)
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|