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.
Files changed (271) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +279 -603
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +13 -297
  5. data/lib/abstract_controller/asset_paths.rb +4 -2
  6. data/lib/abstract_controller/base.rb +82 -52
  7. data/lib/abstract_controller/caching/fragments.rb +166 -0
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/callbacks.rb +117 -103
  10. data/lib/abstract_controller/collector.rb +18 -7
  11. data/lib/abstract_controller/error.rb +6 -0
  12. data/lib/abstract_controller/helpers.rb +65 -38
  13. data/lib/abstract_controller/logger.rb +3 -2
  14. data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
  15. data/lib/abstract_controller/rendering.rb +77 -129
  16. data/lib/abstract_controller/translation.rb +21 -3
  17. data/lib/abstract_controller/url_for.rb +9 -7
  18. data/lib/abstract_controller.rb +12 -13
  19. data/lib/action_controller/api/api_rendering.rb +16 -0
  20. data/lib/action_controller/api.rb +149 -0
  21. data/lib/action_controller/base.rb +81 -40
  22. data/lib/action_controller/caching.rb +22 -62
  23. data/lib/action_controller/form_builder.rb +50 -0
  24. data/lib/action_controller/log_subscriber.rb +30 -18
  25. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  26. data/lib/action_controller/metal/conditional_get.rb +190 -47
  27. data/lib/action_controller/metal/content_security_policy.rb +52 -0
  28. data/lib/action_controller/metal/cookies.rb +3 -3
  29. data/lib/action_controller/metal/data_streaming.rb +40 -65
  30. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  31. data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
  32. data/lib/action_controller/metal/exceptions.rb +19 -12
  33. data/lib/action_controller/metal/flash.rb +42 -9
  34. data/lib/action_controller/metal/force_ssl.rb +79 -19
  35. data/lib/action_controller/metal/head.rb +35 -10
  36. data/lib/action_controller/metal/helpers.rb +31 -21
  37. data/lib/action_controller/metal/http_authentication.rb +182 -134
  38. data/lib/action_controller/metal/implicit_render.rb +62 -8
  39. data/lib/action_controller/metal/instrumentation.rb +28 -26
  40. data/lib/action_controller/metal/live.rb +312 -0
  41. data/lib/action_controller/metal/mime_responds.rb +159 -163
  42. data/lib/action_controller/metal/parameter_encoding.rb +51 -0
  43. data/lib/action_controller/metal/params_wrapper.rb +146 -93
  44. data/lib/action_controller/metal/redirecting.rb +80 -56
  45. data/lib/action_controller/metal/renderers.rb +119 -47
  46. data/lib/action_controller/metal/rendering.rb +89 -32
  47. data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
  48. data/lib/action_controller/metal/rescue.rb +9 -16
  49. data/lib/action_controller/metal/streaming.rb +39 -45
  50. data/lib/action_controller/metal/strong_parameters.rb +1086 -0
  51. data/lib/action_controller/metal/testing.rb +8 -29
  52. data/lib/action_controller/metal/url_for.rb +43 -32
  53. data/lib/action_controller/metal.rb +112 -106
  54. data/lib/action_controller/railtie.rb +56 -18
  55. data/lib/action_controller/railties/helpers.rb +24 -0
  56. data/lib/action_controller/renderer.rb +117 -0
  57. data/lib/action_controller/template_assertions.rb +11 -0
  58. data/lib/action_controller/test_case.rb +402 -347
  59. data/lib/action_controller.rb +31 -30
  60. data/lib/action_dispatch/http/cache.rb +133 -34
  61. data/lib/action_dispatch/http/content_security_policy.rb +272 -0
  62. data/lib/action_dispatch/http/filter_parameters.rb +40 -24
  63. data/lib/action_dispatch/http/filter_redirect.rb +37 -0
  64. data/lib/action_dispatch/http/headers.rb +117 -16
  65. data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
  66. data/lib/action_dispatch/http/mime_type.rb +198 -146
  67. data/lib/action_dispatch/http/mime_types.rb +22 -7
  68. data/lib/action_dispatch/http/parameter_filter.rb +61 -49
  69. data/lib/action_dispatch/http/parameters.rb +94 -51
  70. data/lib/action_dispatch/http/rack_cache.rb +4 -3
  71. data/lib/action_dispatch/http/request.rb +262 -117
  72. data/lib/action_dispatch/http/response.rb +400 -86
  73. data/lib/action_dispatch/http/upload.rb +66 -29
  74. data/lib/action_dispatch/http/url.rb +232 -60
  75. data/lib/action_dispatch/journey/formatter.rb +189 -0
  76. data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
  77. data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
  78. data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
  79. data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
  80. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  81. data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
  82. data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
  83. data/lib/action_dispatch/journey/nodes/node.rb +140 -0
  84. data/lib/action_dispatch/journey/parser.rb +199 -0
  85. data/lib/action_dispatch/journey/parser.y +50 -0
  86. data/lib/action_dispatch/journey/parser_extras.rb +31 -0
  87. data/lib/action_dispatch/journey/path/pattern.rb +199 -0
  88. data/lib/action_dispatch/journey/route.rb +203 -0
  89. data/lib/action_dispatch/journey/router/utils.rb +102 -0
  90. data/lib/action_dispatch/journey/router.rb +156 -0
  91. data/lib/action_dispatch/journey/routes.rb +82 -0
  92. data/lib/action_dispatch/journey/scanner.rb +64 -0
  93. data/lib/action_dispatch/journey/visitors.rb +268 -0
  94. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  95. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  96. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  97. data/lib/action_dispatch/journey.rb +7 -0
  98. data/lib/action_dispatch/middleware/callbacks.rb +17 -13
  99. data/lib/action_dispatch/middleware/cookies.rb +494 -162
  100. data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
  101. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  102. data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
  103. data/lib/action_dispatch/middleware/executor.rb +21 -0
  104. data/lib/action_dispatch/middleware/flash.rb +128 -91
  105. data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
  106. data/lib/action_dispatch/middleware/reloader.rb +6 -83
  107. data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
  108. data/lib/action_dispatch/middleware/request_id.rb +19 -15
  109. data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
  110. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
  111. data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
  112. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
  113. data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
  114. data/lib/action_dispatch/middleware/ssl.rb +150 -0
  115. data/lib/action_dispatch/middleware/stack.rb +33 -41
  116. data/lib/action_dispatch/middleware/static.rb +92 -48
  117. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  123. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  125. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
  126. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
  128. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  136. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  137. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  138. data/lib/action_dispatch/railtie.rb +29 -8
  139. data/lib/action_dispatch/request/session.rb +234 -0
  140. data/lib/action_dispatch/request/utils.rb +78 -0
  141. data/lib/action_dispatch/routing/endpoint.rb +17 -0
  142. data/lib/action_dispatch/routing/inspector.rb +225 -0
  143. data/lib/action_dispatch/routing/mapper.rb +1329 -582
  144. data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
  145. data/lib/action_dispatch/routing/redirection.rb +120 -50
  146. data/lib/action_dispatch/routing/route_set.rb +545 -322
  147. data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
  148. data/lib/action_dispatch/routing/url_for.rb +103 -34
  149. data/lib/action_dispatch/routing.rb +66 -99
  150. data/lib/action_dispatch/system_test_case.rb +147 -0
  151. data/lib/action_dispatch/system_testing/browser.rb +49 -0
  152. data/lib/action_dispatch/system_testing/driver.rb +59 -0
  153. data/lib/action_dispatch/system_testing/server.rb +31 -0
  154. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
  156. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +47 -0
  158. data/lib/action_dispatch/testing/assertions/response.rb +53 -42
  159. data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
  160. data/lib/action_dispatch/testing/assertions.rb +15 -9
  161. data/lib/action_dispatch/testing/integration.rb +361 -207
  162. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  163. data/lib/action_dispatch/testing/test_process.rb +28 -19
  164. data/lib/action_dispatch/testing/test_request.rb +30 -33
  165. data/lib/action_dispatch/testing/test_response.rb +35 -11
  166. data/lib/action_dispatch.rb +42 -32
  167. data/lib/action_pack/gem_version.rb +17 -0
  168. data/lib/action_pack/version.rb +7 -7
  169. data/lib/action_pack.rb +4 -2
  170. metadata +116 -175
  171. data/lib/abstract_controller/layouts.rb +0 -423
  172. data/lib/abstract_controller/view_paths.rb +0 -96
  173. data/lib/action_controller/caching/actions.rb +0 -185
  174. data/lib/action_controller/caching/fragments.rb +0 -127
  175. data/lib/action_controller/caching/pages.rb +0 -187
  176. data/lib/action_controller/caching/sweeping.rb +0 -97
  177. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  178. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  179. data/lib/action_controller/deprecated.rb +0 -3
  180. data/lib/action_controller/metal/compatibility.rb +0 -65
  181. data/lib/action_controller/metal/hide_actions.rb +0 -41
  182. data/lib/action_controller/metal/rack_delegation.rb +0 -26
  183. data/lib/action_controller/metal/responder.rb +0 -286
  184. data/lib/action_controller/metal/session_management.rb +0 -14
  185. data/lib/action_controller/middleware.rb +0 -39
  186. data/lib/action_controller/railties/paths.rb +0 -25
  187. data/lib/action_controller/record_identifier.rb +0 -85
  188. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  189. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  190. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  191. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  192. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  193. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  194. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  195. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  196. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  197. data/lib/action_dispatch/middleware/head.rb +0 -18
  198. data/lib/action_dispatch/middleware/params_parser.rb +0 -75
  199. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  200. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  201. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  202. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  203. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  204. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  205. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  206. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  207. data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
  208. data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
  209. data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
  210. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  211. data/lib/action_view/asset_paths.rb +0 -142
  212. data/lib/action_view/base.rb +0 -220
  213. data/lib/action_view/buffers.rb +0 -43
  214. data/lib/action_view/context.rb +0 -36
  215. data/lib/action_view/flows.rb +0 -79
  216. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  217. data/lib/action_view/helpers/asset_paths.rb +0 -7
  218. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  219. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  220. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  221. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  222. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  223. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  224. data/lib/action_view/helpers/cache_helper.rb +0 -64
  225. data/lib/action_view/helpers/capture_helper.rb +0 -203
  226. data/lib/action_view/helpers/controller_helper.rb +0 -25
  227. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  228. data/lib/action_view/helpers/date_helper.rb +0 -1062
  229. data/lib/action_view/helpers/debug_helper.rb +0 -40
  230. data/lib/action_view/helpers/form_helper.rb +0 -1486
  231. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  232. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  233. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  234. data/lib/action_view/helpers/number_helper.rb +0 -622
  235. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  236. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  237. data/lib/action_view/helpers/rendering_helper.rb +0 -92
  238. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  239. data/lib/action_view/helpers/tag_helper.rb +0 -167
  240. data/lib/action_view/helpers/text_helper.rb +0 -426
  241. data/lib/action_view/helpers/translation_helper.rb +0 -91
  242. data/lib/action_view/helpers/url_helper.rb +0 -693
  243. data/lib/action_view/helpers.rb +0 -60
  244. data/lib/action_view/locale/en.yml +0 -160
  245. data/lib/action_view/log_subscriber.rb +0 -28
  246. data/lib/action_view/lookup_context.rb +0 -258
  247. data/lib/action_view/path_set.rb +0 -101
  248. data/lib/action_view/railtie.rb +0 -55
  249. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  250. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  251. data/lib/action_view/renderer/renderer.rb +0 -61
  252. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  253. data/lib/action_view/renderer/template_renderer.rb +0 -95
  254. data/lib/action_view/template/error.rb +0 -128
  255. data/lib/action_view/template/handlers/builder.rb +0 -26
  256. data/lib/action_view/template/handlers/erb.rb +0 -125
  257. data/lib/action_view/template/handlers.rb +0 -50
  258. data/lib/action_view/template/resolver.rb +0 -298
  259. data/lib/action_view/template/text.rb +0 -30
  260. data/lib/action_view/template.rb +0 -337
  261. data/lib/action_view/test_case.rb +0 -246
  262. data/lib/action_view/testing/resolvers.rb +0 -49
  263. data/lib/action_view.rb +0 -84
  264. data/lib/sprockets/assets.rake +0 -99
  265. data/lib/sprockets/bootstrap.rb +0 -37
  266. data/lib/sprockets/compressors.rb +0 -83
  267. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  268. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  269. data/lib/sprockets/helpers.rb +0 -6
  270. data/lib/sprockets/railtie.rb +0 -62
  271. data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,15 +1,28 @@
1
- require 'active_support/dependencies'
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
- self._helpers = Module.new
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
- class_attribute :_helper_methods
12
- self._helper_methods = Array.new
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 method available to the view:
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.find_by_id(session[:user])
46
+ # @current_user ||= User.find_by(id: session[:user])
33
47
  # end
34
48
  #
35
- # def logged_in?
36
- # current_user != nil
37
- # end
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
- # ==== Parameters
62
- # * <tt>*args</tt> - Module, Symbol, String, :all
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
- # and "foo_bar_helper.rb" is loaded using require_dependency.
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
- require_dependency(file_name, "Missing helper file helpers/%s.rb")
136
- file_name.camelize.constantize
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
- # Makes all the (instance) methods in the helper module available to templates
147
- # rendered through this controller.
148
- #
149
- # ==== Parameters
150
- # * <tt>module</tt> - The module to include into the current helper module
151
- # for the class
152
- def add_template_helper(mod)
153
- _helpers.module_eval { include mod }
154
- end
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
- def default_helper_module!
157
- module_name = name.sub(/Controller$/, '')
158
- module_path = module_name.underscore
159
- helper module_path
160
- rescue MissingSourceFile => e
161
- raise e unless e.is_missing? "helpers/#{module_path}_helper"
162
- rescue NameError => e
163
- raise e unless e.missing_name? "#{module_name}Helper"
164
- end
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,8 +1,9 @@
1
- require "active_support/core_ext/logger"
1
+ # frozen_string_literal: true
2
+
2
3
  require "active_support/benchmarkable"
3
4
 
4
5
  module AbstractController
5
- module Logger
6
+ module Logger #:nodoc:
6
7
  extend ActiveSupport::Concern
7
8
 
8
9
  included do
@@ -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.send(:include, namespace.railtie_routes_url_helpers)
11
+ klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
10
12
  else
11
- klass.send(:include, routes.url_helpers)
13
+ klass.include(routes.url_helpers(include_path_helpers))
12
14
  end
13
15
  end
14
16
  end
@@ -1,7 +1,9 @@
1
- require "abstract_controller/base"
1
+ # frozen_string_literal: true
2
+
3
+ require "abstract_controller/error"
2
4
  require "action_view"
3
- require "active_support/core_ext/object/instance_variables"
4
- require "active_support/hash_with_indifferent_access"
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 AbstractController::ViewPaths
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
- module ClassMethods
52
- def view_context_class
53
- @view_context_class ||= begin
54
- routes = _routes if respond_to?(:_routes)
55
- helpers = _helpers if respond_to?(:_helpers)
56
- ActionView::Base.prepare(routes, helpers)
57
- end
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
- attr_internal_writer :view_context_class
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
- # The view class must have the following methods:
70
- # View.new[lookup_context, assigns, controller]
71
- # Create a new ActionView instance for a controller
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
- # Override this method in a module to change the default behavior.
76
- def view_context
77
- view_context_class.new(view_renderer, view_assigns, self)
78
- end
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
- # Raw rendering of a template to a Rack-compatible body.
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
- # Find and renders a template based on the options given.
108
- # :api: private
109
- def _render_template(options) #:nodoc:
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 = %w(
115
- @_action_name @_response_body @_formats @_prefixes @_config
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
- hash = {}
124
- variables = instance_variable_names
125
- variables -= protected_instance_variables
126
- variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
127
- variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) }
128
- hash
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
- private
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
- # Normalize args by converting render "foo" to render :action => "foo" and
142
- # render "foo/bar" to render :app_template_file => "foo/bar".
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
- # Normalize options.
160
- # :api: plugin
161
- def _normalize_options(options)
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
- if (options.keys & [:partial, :file, :template]).empty?
167
- options[:prefixes] ||= _prefixes
168
- end
106
+ def _process_variant(options)
107
+ end
108
+
109
+ def _set_html_content_type # :nodoc:
110
+ end
169
111
 
170
- options[:template] ||= (options[:action] || action_name).to_s
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
- # Process extra options.
175
- # :api: plugin
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
- def translate(*args)
4
- I18n.translate(*args)
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
- # Includes +url_for+ into the host class (e.g. an abstract controller or mailer). The class
2
- # has to provide a +RouteSet+ by implementing the <tt>_routes</tt> methods. Otherwise, an
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
@@ -1,28 +1,27 @@
1
- activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
2
- $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
1
+ # frozen_string_literal: true
3
2
 
4
- require 'action_pack'
5
- require 'active_support/concern'
6
- require 'active_support/ruby/shim'
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