actionpack 4.0.1 → 4.2.11.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (241) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +402 -1173
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +7 -7
  5. data/lib/abstract_controller/base.rb +39 -7
  6. data/lib/abstract_controller/callbacks.rb +32 -53
  7. data/lib/abstract_controller/collector.rb +11 -1
  8. data/lib/abstract_controller/helpers.rb +26 -16
  9. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  10. data/lib/abstract_controller/rendering.rb +57 -127
  11. data/lib/abstract_controller/url_for.rb +1 -1
  12. data/lib/abstract_controller.rb +1 -2
  13. data/lib/action_controller/base.rb +19 -10
  14. data/lib/action_controller/caching/fragments.rb +7 -1
  15. data/lib/action_controller/caching.rb +2 -12
  16. data/lib/action_controller/log_subscriber.rb +29 -20
  17. data/lib/action_controller/metal/conditional_get.rb +37 -12
  18. data/lib/action_controller/metal/data_streaming.rb +1 -1
  19. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  20. data/lib/action_controller/metal/exceptions.rb +1 -1
  21. data/lib/action_controller/metal/flash.rb +17 -0
  22. data/lib/action_controller/metal/force_ssl.rb +2 -2
  23. data/lib/action_controller/metal/head.rb +8 -6
  24. data/lib/action_controller/metal/helpers.rb +6 -2
  25. data/lib/action_controller/metal/http_authentication.rb +45 -23
  26. data/lib/action_controller/metal/instrumentation.rb +9 -6
  27. data/lib/action_controller/metal/live.rb +173 -20
  28. data/lib/action_controller/metal/mime_responds.rb +127 -232
  29. data/lib/action_controller/metal/params_wrapper.rb +16 -9
  30. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  31. data/lib/action_controller/metal/redirecting.rb +34 -26
  32. data/lib/action_controller/metal/renderers.rb +39 -12
  33. data/lib/action_controller/metal/rendering.rb +41 -14
  34. data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
  35. data/lib/action_controller/metal/streaming.rb +19 -21
  36. data/lib/action_controller/metal/strong_parameters.rb +166 -22
  37. data/lib/action_controller/metal/testing.rb +0 -1
  38. data/lib/action_controller/metal/url_for.rb +11 -12
  39. data/lib/action_controller/metal.rb +14 -8
  40. data/lib/action_controller/model_naming.rb +1 -1
  41. data/lib/action_controller/railtie.rb +5 -1
  42. data/lib/action_controller/test_case.rb +160 -94
  43. data/lib/action_controller.rb +2 -18
  44. data/lib/action_dispatch/http/cache.rb +5 -4
  45. data/lib/action_dispatch/http/filter_parameters.rb +2 -2
  46. data/lib/action_dispatch/http/filter_redirect.rb +5 -4
  47. data/lib/action_dispatch/http/headers.rb +46 -10
  48. data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
  49. data/lib/action_dispatch/http/mime_type.rb +25 -26
  50. data/lib/action_dispatch/http/mime_types.rb +1 -0
  51. data/lib/action_dispatch/http/parameter_filter.rb +1 -1
  52. data/lib/action_dispatch/http/parameters.rb +25 -41
  53. data/lib/action_dispatch/http/request.rb +49 -32
  54. data/lib/action_dispatch/http/response.rb +127 -25
  55. data/lib/action_dispatch/http/upload.rb +9 -21
  56. data/lib/action_dispatch/http/url.rb +97 -70
  57. data/lib/action_dispatch/journey/formatter.rb +35 -19
  58. data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
  59. data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
  60. data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
  61. data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
  62. data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
  63. data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
  64. data/lib/action_dispatch/journey/nodes/node.rb +4 -0
  65. data/lib/action_dispatch/journey/parser.rb +51 -59
  66. data/lib/action_dispatch/journey/parser.y +12 -10
  67. data/lib/action_dispatch/journey/path/pattern.rb +16 -19
  68. data/lib/action_dispatch/journey/route.rb +8 -19
  69. data/lib/action_dispatch/journey/router/strexp.rb +9 -6
  70. data/lib/action_dispatch/journey/router/utils.rb +54 -18
  71. data/lib/action_dispatch/journey/router.rb +53 -75
  72. data/lib/action_dispatch/journey/routes.rb +4 -0
  73. data/lib/action_dispatch/journey/scanner.rb +5 -5
  74. data/lib/action_dispatch/journey/visitors.rb +81 -60
  75. data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
  76. data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
  77. data/lib/action_dispatch/middleware/callbacks.rb +7 -7
  78. data/lib/action_dispatch/middleware/cookies.rb +119 -43
  79. data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
  80. data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
  81. data/lib/action_dispatch/middleware/flash.rb +37 -24
  82. data/lib/action_dispatch/middleware/params_parser.rb +2 -2
  83. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
  84. data/lib/action_dispatch/middleware/reloader.rb +11 -2
  85. data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
  86. data/lib/action_dispatch/middleware/request_id.rb +1 -1
  87. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  88. data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
  89. data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
  90. data/lib/action_dispatch/middleware/ssl.rb +10 -7
  91. data/lib/action_dispatch/middleware/static.rb +79 -23
  92. data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
  93. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  94. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
  95. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  96. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  97. data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +1 -1
  98. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  99. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
  100. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  101. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  102. data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +3 -1
  103. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  104. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  105. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  106. data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
  107. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  108. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
  109. data/lib/action_dispatch/railtie.rb +5 -2
  110. data/lib/action_dispatch/request/session.rb +12 -0
  111. data/lib/action_dispatch/request/utils.rb +35 -0
  112. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  113. data/lib/action_dispatch/routing/inspector.rb +11 -17
  114. data/lib/action_dispatch/routing/mapper.rb +519 -312
  115. data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
  116. data/lib/action_dispatch/routing/redirection.rb +51 -26
  117. data/lib/action_dispatch/routing/route_set.rb +331 -206
  118. data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
  119. data/lib/action_dispatch/routing/url_for.rb +19 -5
  120. data/lib/action_dispatch/routing.rb +9 -6
  121. data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
  122. data/lib/action_dispatch/testing/assertions/response.rb +9 -15
  123. data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
  124. data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
  125. data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
  126. data/lib/action_dispatch/testing/assertions.rb +11 -7
  127. data/lib/action_dispatch/testing/integration.rb +31 -29
  128. data/lib/action_dispatch/testing/test_request.rb +1 -1
  129. data/lib/action_dispatch/testing/test_response.rb +1 -5
  130. data/lib/action_dispatch.rb +5 -8
  131. data/lib/action_pack/gem_version.rb +15 -0
  132. data/lib/action_pack/version.rb +4 -7
  133. data/lib/action_pack.rb +1 -1
  134. metadata +77 -159
  135. data/lib/abstract_controller/layouts.rb +0 -423
  136. data/lib/abstract_controller/view_paths.rb +0 -96
  137. data/lib/action_controller/deprecated/integration_test.rb +0 -5
  138. data/lib/action_controller/deprecated.rb +0 -7
  139. data/lib/action_controller/metal/responder.rb +0 -287
  140. data/lib/action_controller/record_identifier.rb +0 -31
  141. data/lib/action_controller/vendor/html-scanner.rb +0 -5
  142. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
  143. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
  144. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
  145. data/lib/action_view/base.rb +0 -201
  146. data/lib/action_view/buffers.rb +0 -49
  147. data/lib/action_view/context.rb +0 -36
  148. data/lib/action_view/dependency_tracker.rb +0 -93
  149. data/lib/action_view/digestor.rb +0 -113
  150. data/lib/action_view/flows.rb +0 -76
  151. data/lib/action_view/helpers/active_model_helper.rb +0 -49
  152. data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
  153. data/lib/action_view/helpers/asset_url_helper.rb +0 -355
  154. data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
  155. data/lib/action_view/helpers/cache_helper.rb +0 -196
  156. data/lib/action_view/helpers/capture_helper.rb +0 -216
  157. data/lib/action_view/helpers/controller_helper.rb +0 -25
  158. data/lib/action_view/helpers/csrf_helper.rb +0 -30
  159. data/lib/action_view/helpers/date_helper.rb +0 -1083
  160. data/lib/action_view/helpers/debug_helper.rb +0 -39
  161. data/lib/action_view/helpers/form_helper.rb +0 -1880
  162. data/lib/action_view/helpers/form_options_helper.rb +0 -838
  163. data/lib/action_view/helpers/form_tag_helper.rb +0 -785
  164. data/lib/action_view/helpers/javascript_helper.rb +0 -117
  165. data/lib/action_view/helpers/number_helper.rb +0 -441
  166. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  167. data/lib/action_view/helpers/record_tag_helper.rb +0 -106
  168. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  169. data/lib/action_view/helpers/sanitize_helper.rb +0 -256
  170. data/lib/action_view/helpers/tag_helper.rb +0 -173
  171. data/lib/action_view/helpers/tags/base.rb +0 -148
  172. data/lib/action_view/helpers/tags/check_box.rb +0 -64
  173. data/lib/action_view/helpers/tags/checkable.rb +0 -16
  174. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
  175. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
  176. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
  177. data/lib/action_view/helpers/tags/collection_select.rb +0 -28
  178. data/lib/action_view/helpers/tags/color_field.rb +0 -25
  179. data/lib/action_view/helpers/tags/date_field.rb +0 -13
  180. data/lib/action_view/helpers/tags/date_select.rb +0 -72
  181. data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
  182. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
  183. data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
  184. data/lib/action_view/helpers/tags/email_field.rb +0 -8
  185. data/lib/action_view/helpers/tags/file_field.rb +0 -8
  186. data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
  187. data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
  188. data/lib/action_view/helpers/tags/label.rb +0 -66
  189. data/lib/action_view/helpers/tags/month_field.rb +0 -13
  190. data/lib/action_view/helpers/tags/number_field.rb +0 -18
  191. data/lib/action_view/helpers/tags/password_field.rb +0 -12
  192. data/lib/action_view/helpers/tags/radio_button.rb +0 -31
  193. data/lib/action_view/helpers/tags/range_field.rb +0 -8
  194. data/lib/action_view/helpers/tags/search_field.rb +0 -24
  195. data/lib/action_view/helpers/tags/select.rb +0 -40
  196. data/lib/action_view/helpers/tags/tel_field.rb +0 -8
  197. data/lib/action_view/helpers/tags/text_area.rb +0 -18
  198. data/lib/action_view/helpers/tags/text_field.rb +0 -29
  199. data/lib/action_view/helpers/tags/time_field.rb +0 -13
  200. data/lib/action_view/helpers/tags/time_select.rb +0 -8
  201. data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
  202. data/lib/action_view/helpers/tags/url_field.rb +0 -8
  203. data/lib/action_view/helpers/tags/week_field.rb +0 -13
  204. data/lib/action_view/helpers/tags.rb +0 -39
  205. data/lib/action_view/helpers/text_helper.rb +0 -443
  206. data/lib/action_view/helpers/translation_helper.rb +0 -107
  207. data/lib/action_view/helpers/url_helper.rb +0 -635
  208. data/lib/action_view/helpers.rb +0 -58
  209. data/lib/action_view/locale/en.yml +0 -56
  210. data/lib/action_view/log_subscriber.rb +0 -30
  211. data/lib/action_view/lookup_context.rb +0 -241
  212. data/lib/action_view/model_naming.rb +0 -12
  213. data/lib/action_view/path_set.rb +0 -77
  214. data/lib/action_view/railtie.rb +0 -43
  215. data/lib/action_view/record_identifier.rb +0 -84
  216. data/lib/action_view/renderer/abstract_renderer.rb +0 -47
  217. data/lib/action_view/renderer/partial_renderer.rb +0 -492
  218. data/lib/action_view/renderer/renderer.rb +0 -50
  219. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
  220. data/lib/action_view/renderer/template_renderer.rb +0 -96
  221. data/lib/action_view/routing_url_for.rb +0 -107
  222. data/lib/action_view/tasks/dependencies.rake +0 -17
  223. data/lib/action_view/template/error.rb +0 -138
  224. data/lib/action_view/template/handlers/builder.rb +0 -26
  225. data/lib/action_view/template/handlers/erb.rb +0 -146
  226. data/lib/action_view/template/handlers/raw.rb +0 -11
  227. data/lib/action_view/template/handlers.rb +0 -53
  228. data/lib/action_view/template/resolver.rb +0 -326
  229. data/lib/action_view/template/text.rb +0 -34
  230. data/lib/action_view/template/types.rb +0 -57
  231. data/lib/action_view/template.rb +0 -339
  232. data/lib/action_view/test_case.rb +0 -270
  233. data/lib/action_view/testing/resolvers.rb +0 -50
  234. data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
  235. data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
  236. data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
  237. data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
  238. data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
  239. data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
  240. data/lib/action_view/vendor/html-scanner.rb +0 -20
  241. data/lib/action_view.rb +0 -93
@@ -1,423 +0,0 @@
1
- require "active_support/core_ext/module/remove_method"
2
-
3
- module AbstractController
4
- # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
5
- # repeated setups. The inclusion pattern has pages that look like this:
6
- #
7
- # <%= render "shared/header" %>
8
- # Hello World
9
- # <%= render "shared/footer" %>
10
- #
11
- # This approach is a decent way of keeping common structures isolated from the changing content, but it's verbose
12
- # and if you ever want to change the structure of these two includes, you'll have to change all the templates.
13
- #
14
- # With layouts, you can flip it around and have the common structure know where to insert changing content. This means
15
- # that the header and footer are only mentioned in one place, like this:
16
- #
17
- # // The header part of this layout
18
- # <%= yield %>
19
- # // The footer part of this layout
20
- #
21
- # And then you have content pages that look like this:
22
- #
23
- # hello world
24
- #
25
- # At rendering time, the content page is computed and then inserted in the layout, like this:
26
- #
27
- # // The header part of this layout
28
- # hello world
29
- # // The footer part of this layout
30
- #
31
- # == Accessing shared variables
32
- #
33
- # Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with
34
- # references that won't materialize before rendering time:
35
- #
36
- # <h1><%= @page_title %></h1>
37
- # <%= yield %>
38
- #
39
- # ...and content pages that fulfill these references _at_ rendering time:
40
- #
41
- # <% @page_title = "Welcome" %>
42
- # Off-world colonies offers you a chance to start a new life
43
- #
44
- # The result after rendering is:
45
- #
46
- # <h1>Welcome</h1>
47
- # Off-world colonies offers you a chance to start a new life
48
- #
49
- # == Layout assignment
50
- #
51
- # You can either specify a layout declaratively (using the #layout class method) or give
52
- # it the same name as your controller, and place it in <tt>app/views/layouts</tt>.
53
- # If a subclass does not have a layout specified, it inherits its layout using normal Ruby inheritance.
54
- #
55
- # For instance, if you have PostsController and a template named <tt>app/views/layouts/posts.html.erb</tt>,
56
- # that template will be used for all actions in PostsController and controllers inheriting
57
- # from PostsController.
58
- #
59
- # If you use a module, for instance Weblog::PostsController, you will need a template named
60
- # <tt>app/views/layouts/weblog/posts.html.erb</tt>.
61
- #
62
- # Since all your controllers inherit from ApplicationController, they will use
63
- # <tt>app/views/layouts/application.html.erb</tt> if no other layout is specified
64
- # or provided.
65
- #
66
- # == Inheritance Examples
67
- #
68
- # class BankController < ActionController::Base
69
- # # bank.html.erb exists
70
- #
71
- # class ExchangeController < BankController
72
- # # exchange.html.erb exists
73
- #
74
- # class CurrencyController < BankController
75
- #
76
- # class InformationController < BankController
77
- # layout "information"
78
- #
79
- # class TellerController < InformationController
80
- # # teller.html.erb exists
81
- #
82
- # class EmployeeController < InformationController
83
- # # employee.html.erb exists
84
- # layout nil
85
- #
86
- # class VaultController < BankController
87
- # layout :access_level_layout
88
- #
89
- # class TillController < BankController
90
- # layout false
91
- #
92
- # In these examples, we have three implicit lookup scenarios:
93
- # * The BankController uses the "bank" layout.
94
- # * The ExchangeController uses the "exchange" layout.
95
- # * The CurrencyController inherits the layout from BankController.
96
- #
97
- # However, when a layout is explicitly set, the explicitly set layout wins:
98
- # * The InformationController uses the "information" layout, explicitly set.
99
- # * The TellerController also uses the "information" layout, because the parent explicitly set it.
100
- # * The EmployeeController uses the "employee" layout, because it set the layout to nil, resetting the parent configuration.
101
- # * The VaultController chooses a layout dynamically by calling the <tt>access_level_layout</tt> method.
102
- # * The TillController does not use a layout at all.
103
- #
104
- # == Types of layouts
105
- #
106
- # Layouts are basically just regular templates, but the name of this template needs not be specified statically. Sometimes
107
- # you want to alternate layouts depending on runtime information, such as whether someone is logged in or not. This can
108
- # be done either by specifying a method reference as a symbol or using an inline method (as a proc).
109
- #
110
- # The method reference is the preferred approach to variable layouts and is used like this:
111
- #
112
- # class WeblogController < ActionController::Base
113
- # layout :writers_and_readers
114
- #
115
- # def index
116
- # # fetching posts
117
- # end
118
- #
119
- # private
120
- # def writers_and_readers
121
- # logged_in? ? "writer_layout" : "reader_layout"
122
- # end
123
- # end
124
- #
125
- # Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing
126
- # is logged in or not.
127
- #
128
- # If you want to use an inline method, such as a proc, do something like this:
129
- #
130
- # class WeblogController < ActionController::Base
131
- # layout proc { |controller| controller.logged_in? ? "writer_layout" : "reader_layout" }
132
- # end
133
- #
134
- # If an argument isn't given to the proc, it's evaluated in the context of
135
- # the current controller anyway.
136
- #
137
- # class WeblogController < ActionController::Base
138
- # layout proc { logged_in? ? "writer_layout" : "reader_layout" }
139
- # end
140
- #
141
- # Of course, the most common way of specifying a layout is still just as a plain template name:
142
- #
143
- # class WeblogController < ActionController::Base
144
- # layout "weblog_standard"
145
- # end
146
- #
147
- # The template will be looked always in <tt>app/views/layouts/</tt> folder. But you can point
148
- # <tt>layouts</tt> folder direct also. <tt>layout "layouts/demo"</tt> is the same as <tt>layout "demo"</tt>.
149
- #
150
- # Setting the layout to nil forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists.
151
- # Setting it to nil is useful to re-enable template lookup overriding a previous configuration set in the parent:
152
- #
153
- # class ApplicationController < ActionController::Base
154
- # layout "application"
155
- # end
156
- #
157
- # class PostsController < ApplicationController
158
- # # Will use "application" layout
159
- # end
160
- #
161
- # class CommentsController < ApplicationController
162
- # # Will search for "comments" layout and fallback "application" layout
163
- # layout nil
164
- # end
165
- #
166
- # == Conditional layouts
167
- #
168
- # If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering
169
- # a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The
170
- # <tt>:only</tt> and <tt>:except</tt> options can be passed to the layout call. For example:
171
- #
172
- # class WeblogController < ActionController::Base
173
- # layout "weblog_standard", except: :rss
174
- #
175
- # # ...
176
- #
177
- # end
178
- #
179
- # This will assign "weblog_standard" as the WeblogController's layout for all actions except for the +rss+ action, which will
180
- # be rendered directly, without wrapping a layout around the rendered view.
181
- #
182
- # Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so
183
- # #<tt>except: [ :rss, :text_only ]</tt> is valid, as is <tt>except: :rss</tt>.
184
- #
185
- # == Using a different layout in the action render call
186
- #
187
- # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above.
188
- # Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller.
189
- # You can do this by passing a <tt>:layout</tt> option to the <tt>render</tt> call. For example:
190
- #
191
- # class WeblogController < ActionController::Base
192
- # layout "weblog_standard"
193
- #
194
- # def help
195
- # render action: "help", layout: "help"
196
- # end
197
- # end
198
- #
199
- # This will override the controller-wide "weblog_standard" layout, and will render the help action with the "help" layout instead.
200
- module Layouts
201
- extend ActiveSupport::Concern
202
-
203
- include Rendering
204
-
205
- included do
206
- class_attribute :_layout, :_layout_conditions, :instance_accessor => false
207
- self._layout = nil
208
- self._layout_conditions = {}
209
- _write_layout_method
210
- end
211
-
212
- delegate :_layout_conditions, to: :class
213
-
214
- module ClassMethods
215
- def inherited(klass) # :nodoc:
216
- super
217
- klass._write_layout_method
218
- end
219
-
220
- # This module is mixed in if layout conditions are provided. This means
221
- # that if no layout conditions are used, this method is not used
222
- module LayoutConditions # :nodoc:
223
- private
224
-
225
- # Determines whether the current action has a layout definition by
226
- # checking the action name against the :only and :except conditions
227
- # set by the <tt>layout</tt> method.
228
- #
229
- # ==== Returns
230
- # * <tt> Boolean</tt> - True if the action has a layout definition, false otherwise.
231
- def _conditional_layout?
232
- return unless super
233
-
234
- conditions = _layout_conditions
235
-
236
- if only = conditions[:only]
237
- only.include?(action_name)
238
- elsif except = conditions[:except]
239
- !except.include?(action_name)
240
- else
241
- true
242
- end
243
- end
244
- end
245
-
246
- # Specify the layout to use for this class.
247
- #
248
- # If the specified layout is a:
249
- # String:: the String is the template name
250
- # Symbol:: call the method specified by the symbol, which will return the template name
251
- # false:: There is no layout
252
- # true:: raise an ArgumentError
253
- # nil:: Force default layout behavior with inheritance
254
- #
255
- # ==== Parameters
256
- # * <tt>layout</tt> - The layout to use.
257
- #
258
- # ==== Options (conditions)
259
- # * :only - A list of actions to apply this layout to.
260
- # * :except - Apply this layout to all actions but this one.
261
- def layout(layout, conditions = {})
262
- include LayoutConditions unless conditions.empty?
263
-
264
- conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
265
- self._layout_conditions = conditions
266
-
267
- self._layout = layout
268
- _write_layout_method
269
- end
270
-
271
- # If no layout is supplied, look for a template named the return
272
- # value of this method.
273
- #
274
- # ==== Returns
275
- # * <tt>String</tt> - A template name
276
- def _implied_layout_name # :nodoc:
277
- controller_path
278
- end
279
-
280
- # Creates a _layout method to be called by _default_layout .
281
- #
282
- # If a layout is not explicitly mentioned then look for a layout with the controller's name.
283
- # if nothing is found then try same procedure to find super class's layout.
284
- def _write_layout_method # :nodoc:
285
- remove_possible_method(:_layout)
286
-
287
- prefixes = _implied_layout_name =~ /\blayouts/ ? [] : ["layouts"]
288
- default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}).first || super"
289
- name_clause = if name
290
- default_behavior
291
- else
292
- <<-RUBY
293
- super
294
- RUBY
295
- end
296
-
297
- layout_definition = case _layout
298
- when String
299
- _layout.inspect
300
- when Symbol
301
- <<-RUBY
302
- #{_layout}.tap do |layout|
303
- return #{default_behavior} if layout.nil?
304
- unless layout.is_a?(String) || !layout
305
- raise ArgumentError, "Your layout method :#{_layout} returned \#{layout}. It " \
306
- "should have returned a String, false, or nil"
307
- end
308
- end
309
- RUBY
310
- when Proc
311
- define_method :_layout_from_proc, &_layout
312
- protected :_layout_from_proc
313
- <<-RUBY
314
- result = _layout_from_proc(#{_layout.arity == 0 ? '' : 'self'})
315
- return #{default_behavior} if result.nil?
316
- result
317
- RUBY
318
- when false
319
- nil
320
- when true
321
- raise ArgumentError, "Layouts must be specified as a String, Symbol, Proc, false, or nil"
322
- when nil
323
- name_clause
324
- end
325
-
326
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
327
- def _layout
328
- if _conditional_layout?
329
- #{layout_definition}
330
- else
331
- #{name_clause}
332
- end
333
- end
334
- private :_layout
335
- RUBY
336
- end
337
- end
338
-
339
- def _normalize_options(options) # :nodoc:
340
- super
341
-
342
- if _include_layout?(options)
343
- layout = options.delete(:layout) { :default }
344
- options[:layout] = _layout_for_option(layout)
345
- end
346
- end
347
-
348
- attr_internal_writer :action_has_layout
349
-
350
- def initialize(*) # :nodoc:
351
- @_action_has_layout = true
352
- super
353
- end
354
-
355
- # Controls whether an action should be rendered using a layout.
356
- # If you want to disable any <tt>layout</tt> settings for the
357
- # current action so that it is rendered without a layout then
358
- # either override this method in your controller to return false
359
- # for that action or set the <tt>action_has_layout</tt> attribute
360
- # to false before rendering.
361
- def action_has_layout?
362
- @_action_has_layout
363
- end
364
-
365
- private
366
-
367
- def _conditional_layout?
368
- true
369
- end
370
-
371
- # This will be overwritten by _write_layout_method
372
- def _layout; end
373
-
374
- # Determine the layout for a given name, taking into account the name type.
375
- #
376
- # ==== Parameters
377
- # * <tt>name</tt> - The name of the template
378
- def _layout_for_option(name)
379
- case name
380
- when String then _normalize_layout(name)
381
- when Proc then name
382
- when true then Proc.new { _default_layout(true) }
383
- when :default then Proc.new { _default_layout(false) }
384
- when false, nil then nil
385
- else
386
- raise ArgumentError,
387
- "String, Proc, :default, true, or false, expected for `layout'; you passed #{name.inspect}"
388
- end
389
- end
390
-
391
- def _normalize_layout(value)
392
- value.is_a?(String) && value !~ /\blayouts/ ? "layouts/#{value}" : value
393
- end
394
-
395
- # Returns the default layout for this controller.
396
- # Optionally raises an exception if the layout could not be found.
397
- #
398
- # ==== Parameters
399
- # * <tt>require_layout</tt> - If set to true and layout is not found,
400
- # an ArgumentError exception is raised (defaults to false)
401
- #
402
- # ==== Returns
403
- # * <tt>template</tt> - The template object for the default layout (or nil)
404
- def _default_layout(require_layout = false)
405
- begin
406
- value = _layout if action_has_layout?
407
- rescue NameError => e
408
- raise e, "Could not render layout: #{e.message}"
409
- end
410
-
411
- if require_layout && action_has_layout? && !value
412
- raise ArgumentError,
413
- "There was no default layout for #{self.class} in #{view_paths.inspect}"
414
- end
415
-
416
- _normalize_layout(value)
417
- end
418
-
419
- def _include_layout?(options)
420
- (options.keys & [:text, :inline, :partial]).empty? || options.key?(:layout)
421
- end
422
- end
423
- end
@@ -1,96 +0,0 @@
1
- require 'action_view/base'
2
-
3
- module AbstractController
4
- module ViewPaths
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :_view_paths
9
- self._view_paths = ActionView::PathSet.new
10
- self._view_paths.freeze
11
- end
12
-
13
- delegate :template_exists?, :view_paths, :formats, :formats=,
14
- :locale, :locale=, :to => :lookup_context
15
-
16
- module ClassMethods
17
- def parent_prefixes
18
- @parent_prefixes ||= begin
19
- parent_controller = superclass
20
- prefixes = []
21
-
22
- until parent_controller.abstract?
23
- prefixes << parent_controller.controller_path
24
- parent_controller = parent_controller.superclass
25
- end
26
-
27
- prefixes
28
- end
29
- end
30
- end
31
-
32
- # The prefixes used in render "foo" shortcuts.
33
- def _prefixes
34
- @_prefixes ||= begin
35
- parent_prefixes = self.class.parent_prefixes
36
- parent_prefixes.dup.unshift(controller_path)
37
- end
38
- end
39
-
40
- # LookupContext is the object responsible to hold all information required to lookup
41
- # templates, i.e. view paths and details. Check ActionView::LookupContext for more
42
- # information.
43
- def lookup_context
44
- @_lookup_context ||=
45
- ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
46
- end
47
-
48
- def details_for_lookup
49
- { }
50
- end
51
-
52
- def append_view_path(path)
53
- lookup_context.view_paths.push(*path)
54
- end
55
-
56
- def prepend_view_path(path)
57
- lookup_context.view_paths.unshift(*path)
58
- end
59
-
60
- module ClassMethods
61
- # Append a path to the list of view paths for this controller.
62
- #
63
- # ==== Parameters
64
- # * <tt>path</tt> - If a String is provided, it gets converted into
65
- # the default view path. You may also provide a custom view path
66
- # (see ActionView::PathSet for more information)
67
- def append_view_path(path)
68
- self._view_paths = view_paths + Array(path)
69
- end
70
-
71
- # Prepend a path to the list of view paths for this controller.
72
- #
73
- # ==== Parameters
74
- # * <tt>path</tt> - If a String is provided, it gets converted into
75
- # the default view path. You may also provide a custom view path
76
- # (see ActionView::PathSet for more information)
77
- def prepend_view_path(path)
78
- self._view_paths = ActionView::PathSet.new(Array(path) + view_paths)
79
- end
80
-
81
- # A list of all of the default view paths for this controller.
82
- def view_paths
83
- _view_paths
84
- end
85
-
86
- # Set the view paths.
87
- #
88
- # ==== Parameters
89
- # * <tt>paths</tt> - If a PathSet is provided, use that;
90
- # otherwise, process the parameter into a PathSet.
91
- def view_paths=(paths)
92
- self._view_paths = ActionView::PathSet.new(Array(paths))
93
- end
94
- end
95
- end
96
- end
@@ -1,5 +0,0 @@
1
- ActionController::Integration = ActionDispatch::Integration
2
- ActionController::IntegrationTest = ActionDispatch::IntegrationTest
3
-
4
- ActiveSupport::Deprecation.warn 'ActionController::Integration is deprecated and will be removed, use ActionDispatch::Integration instead.'
5
- ActiveSupport::Deprecation.warn 'ActionController::IntegrationTest is deprecated and will be removed, use ActionDispatch::IntegrationTest instead.'
@@ -1,7 +0,0 @@
1
- ActionController::AbstractRequest = ActionController::Request = ActionDispatch::Request
2
- ActionController::AbstractResponse = ActionController::Response = ActionDispatch::Response
3
- ActionController::Routing = ActionDispatch::Routing
4
-
5
- ActiveSupport::Deprecation.warn 'ActionController::AbstractRequest and ActionController::Request are deprecated and will be removed, use ActionDispatch::Request instead.'
6
- ActiveSupport::Deprecation.warn 'ActionController::AbstractResponse and ActionController::Response are deprecated and will be removed, use ActionDispatch::Response instead.'
7
- ActiveSupport::Deprecation.warn 'ActionController::Routing is deprecated and will be removed, use ActionDispatch::Routing instead.'