actionpack 3.2.19 → 4.2.11.3

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 (244) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +412 -503
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +11 -294
  5. data/lib/abstract_controller/asset_paths.rb +2 -2
  6. data/lib/abstract_controller/base.rb +52 -18
  7. data/lib/abstract_controller/callbacks.rb +87 -89
  8. data/lib/abstract_controller/collector.rb +17 -3
  9. data/lib/abstract_controller/helpers.rb +41 -14
  10. data/lib/abstract_controller/logger.rb +1 -2
  11. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  12. data/lib/abstract_controller/rendering.rb +65 -118
  13. data/lib/abstract_controller/translation.rb +16 -1
  14. data/lib/abstract_controller/url_for.rb +7 -7
  15. data/lib/abstract_controller.rb +2 -10
  16. data/lib/action_controller/base.rb +61 -28
  17. data/lib/action_controller/caching/fragments.rb +30 -54
  18. data/lib/action_controller/caching.rb +38 -35
  19. data/lib/action_controller/log_subscriber.rb +35 -18
  20. data/lib/action_controller/metal/conditional_get.rb +103 -34
  21. data/lib/action_controller/metal/data_streaming.rb +20 -26
  22. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  23. data/lib/action_controller/metal/exceptions.rb +19 -6
  24. data/lib/action_controller/metal/flash.rb +41 -9
  25. data/lib/action_controller/metal/force_ssl.rb +70 -12
  26. data/lib/action_controller/metal/head.rb +30 -7
  27. data/lib/action_controller/metal/helpers.rb +11 -11
  28. data/lib/action_controller/metal/hide_actions.rb +0 -1
  29. data/lib/action_controller/metal/http_authentication.rb +140 -94
  30. data/lib/action_controller/metal/implicit_render.rb +1 -1
  31. data/lib/action_controller/metal/instrumentation.rb +11 -7
  32. data/lib/action_controller/metal/live.rb +328 -0
  33. data/lib/action_controller/metal/mime_responds.rb +161 -152
  34. data/lib/action_controller/metal/params_wrapper.rb +126 -81
  35. data/lib/action_controller/metal/rack_delegation.rb +10 -4
  36. data/lib/action_controller/metal/redirecting.rb +44 -41
  37. data/lib/action_controller/metal/renderers.rb +48 -19
  38. data/lib/action_controller/metal/rendering.rb +46 -11
  39. data/lib/action_controller/metal/request_forgery_protection.rb +250 -29
  40. data/lib/action_controller/metal/streaming.rb +30 -38
  41. data/lib/action_controller/metal/strong_parameters.rb +669 -0
  42. data/lib/action_controller/metal/testing.rb +12 -18
  43. data/lib/action_controller/metal/url_for.rb +31 -29
  44. data/lib/action_controller/metal.rb +31 -40
  45. data/lib/action_controller/model_naming.rb +12 -0
  46. data/lib/action_controller/railtie.rb +38 -18
  47. data/lib/action_controller/railties/helpers.rb +22 -0
  48. data/lib/action_controller/test_case.rb +359 -173
  49. data/lib/action_controller.rb +9 -16
  50. data/lib/action_dispatch/http/cache.rb +64 -11
  51. data/lib/action_dispatch/http/filter_parameters.rb +20 -10
  52. data/lib/action_dispatch/http/filter_redirect.rb +38 -0
  53. data/lib/action_dispatch/http/headers.rb +85 -17
  54. data/lib/action_dispatch/http/mime_negotiation.rb +55 -5
  55. data/lib/action_dispatch/http/mime_type.rb +167 -114
  56. data/lib/action_dispatch/http/mime_types.rb +2 -1
  57. data/lib/action_dispatch/http/parameter_filter.rb +44 -46
  58. data/lib/action_dispatch/http/parameters.rb +30 -46
  59. data/lib/action_dispatch/http/rack_cache.rb +2 -3
  60. data/lib/action_dispatch/http/request.rb +108 -45
  61. data/lib/action_dispatch/http/response.rb +247 -48
  62. data/lib/action_dispatch/http/upload.rb +60 -29
  63. data/lib/action_dispatch/http/url.rb +135 -45
  64. data/lib/action_dispatch/journey/backwards.rb +5 -0
  65. data/lib/action_dispatch/journey/formatter.rb +166 -0
  66. data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
  67. data/lib/action_dispatch/journey/gtg/simulator.rb +47 -0
  68. data/lib/action_dispatch/journey/gtg/transition_table.rb +157 -0
  69. data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
  70. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  71. data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
  72. data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
  73. data/lib/action_dispatch/journey/nodes/node.rb +128 -0
  74. data/lib/action_dispatch/journey/parser.rb +198 -0
  75. data/lib/action_dispatch/journey/parser.y +49 -0
  76. data/lib/action_dispatch/journey/parser_extras.rb +23 -0
  77. data/lib/action_dispatch/journey/path/pattern.rb +193 -0
  78. data/lib/action_dispatch/journey/route.rb +125 -0
  79. data/lib/action_dispatch/journey/router/strexp.rb +27 -0
  80. data/lib/action_dispatch/journey/router/utils.rb +93 -0
  81. data/lib/action_dispatch/journey/router.rb +144 -0
  82. data/lib/action_dispatch/journey/routes.rb +80 -0
  83. data/lib/action_dispatch/journey/scanner.rb +61 -0
  84. data/lib/action_dispatch/journey/visitors.rb +221 -0
  85. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  86. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  87. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  88. data/lib/action_dispatch/journey.rb +5 -0
  89. data/lib/action_dispatch/middleware/callbacks.rb +16 -11
  90. data/lib/action_dispatch/middleware/cookies.rb +346 -125
  91. data/lib/action_dispatch/middleware/debug_exceptions.rb +52 -24
  92. data/lib/action_dispatch/middleware/exception_wrapper.rb +75 -9
  93. data/lib/action_dispatch/middleware/flash.rb +85 -72
  94. data/lib/action_dispatch/middleware/params_parser.rb +16 -31
  95. data/lib/action_dispatch/middleware/public_exceptions.rb +39 -14
  96. data/lib/action_dispatch/middleware/reloader.rb +16 -7
  97. data/lib/action_dispatch/middleware/remote_ip.rb +132 -40
  98. data/lib/action_dispatch/middleware/request_id.rb +3 -7
  99. data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
  100. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  101. data/lib/action_dispatch/middleware/session/cookie_store.rb +84 -29
  102. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
  103. data/lib/action_dispatch/middleware/show_exceptions.rb +15 -44
  104. data/lib/action_dispatch/middleware/ssl.rb +72 -0
  105. data/lib/action_dispatch/middleware/stack.rb +6 -1
  106. data/lib/action_dispatch/middleware/static.rb +80 -23
  107. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +34 -0
  108. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  109. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +27 -0
  110. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  111. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  112. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  113. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  114. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +133 -5
  115. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  116. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  117. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  123. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  125. data/lib/action_dispatch/railtie.rb +19 -6
  126. data/lib/action_dispatch/request/session.rb +193 -0
  127. data/lib/action_dispatch/request/utils.rb +35 -0
  128. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  129. data/lib/action_dispatch/routing/inspector.rb +234 -0
  130. data/lib/action_dispatch/routing/mapper.rb +897 -436
  131. data/lib/action_dispatch/routing/polymorphic_routes.rb +213 -92
  132. data/lib/action_dispatch/routing/redirection.rb +97 -37
  133. data/lib/action_dispatch/routing/route_set.rb +432 -239
  134. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  135. data/lib/action_dispatch/routing/url_for.rb +63 -34
  136. data/lib/action_dispatch/routing.rb +57 -89
  137. data/lib/action_dispatch/testing/assertions/dom.rb +2 -36
  138. data/lib/action_dispatch/testing/assertions/response.rb +24 -38
  139. data/lib/action_dispatch/testing/assertions/routing.rb +55 -54
  140. data/lib/action_dispatch/testing/assertions/selector.rb +2 -434
  141. data/lib/action_dispatch/testing/assertions/tag.rb +2 -137
  142. data/lib/action_dispatch/testing/assertions.rb +11 -7
  143. data/lib/action_dispatch/testing/integration.rb +88 -72
  144. data/lib/action_dispatch/testing/test_process.rb +9 -6
  145. data/lib/action_dispatch/testing/test_request.rb +13 -9
  146. data/lib/action_dispatch/testing/test_response.rb +1 -5
  147. data/lib/action_dispatch.rb +24 -21
  148. data/lib/action_pack/gem_version.rb +15 -0
  149. data/lib/action_pack/version.rb +5 -7
  150. data/lib/action_pack.rb +1 -1
  151. metadata +181 -292
  152. data/lib/abstract_controller/layouts.rb +0 -423
  153. data/lib/abstract_controller/view_paths.rb +0 -96
  154. data/lib/action_controller/caching/actions.rb +0 -185
  155. data/lib/action_controller/caching/pages.rb +0 -187
  156. data/lib/action_controller/caching/sweeping.rb +0 -97
  157. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  158. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  159. data/lib/action_controller/deprecated.rb +0 -3
  160. data/lib/action_controller/metal/compatibility.rb +0 -65
  161. data/lib/action_controller/metal/responder.rb +0 -286
  162. data/lib/action_controller/metal/session_management.rb +0 -14
  163. data/lib/action_controller/railties/paths.rb +0 -25
  164. data/lib/action_controller/record_identifier.rb +0 -85
  165. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  166. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  167. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  168. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  169. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  170. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  171. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  172. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  173. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  174. data/lib/action_dispatch/middleware/head.rb +0 -18
  175. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  176. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  177. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  178. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  179. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  180. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  181. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  182. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  183. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  184. data/lib/action_view/asset_paths.rb +0 -142
  185. data/lib/action_view/base.rb +0 -220
  186. data/lib/action_view/buffers.rb +0 -43
  187. data/lib/action_view/context.rb +0 -36
  188. data/lib/action_view/flows.rb +0 -79
  189. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  190. data/lib/action_view/helpers/asset_paths.rb +0 -7
  191. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  192. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  193. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  194. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  195. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  196. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  197. data/lib/action_view/helpers/cache_helper.rb +0 -64
  198. data/lib/action_view/helpers/capture_helper.rb +0 -203
  199. data/lib/action_view/helpers/controller_helper.rb +0 -25
  200. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  201. data/lib/action_view/helpers/date_helper.rb +0 -1062
  202. data/lib/action_view/helpers/debug_helper.rb +0 -40
  203. data/lib/action_view/helpers/form_helper.rb +0 -1486
  204. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  205. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  206. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  207. data/lib/action_view/helpers/number_helper.rb +0 -622
  208. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  209. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  210. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  211. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  212. data/lib/action_view/helpers/tag_helper.rb +0 -160
  213. data/lib/action_view/helpers/text_helper.rb +0 -426
  214. data/lib/action_view/helpers/translation_helper.rb +0 -91
  215. data/lib/action_view/helpers/url_helper.rb +0 -693
  216. data/lib/action_view/helpers.rb +0 -60
  217. data/lib/action_view/locale/en.yml +0 -160
  218. data/lib/action_view/log_subscriber.rb +0 -28
  219. data/lib/action_view/lookup_context.rb +0 -254
  220. data/lib/action_view/path_set.rb +0 -89
  221. data/lib/action_view/railtie.rb +0 -55
  222. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  223. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  224. data/lib/action_view/renderer/renderer.rb +0 -54
  225. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  226. data/lib/action_view/renderer/template_renderer.rb +0 -94
  227. data/lib/action_view/template/error.rb +0 -128
  228. data/lib/action_view/template/handlers/builder.rb +0 -26
  229. data/lib/action_view/template/handlers/erb.rb +0 -125
  230. data/lib/action_view/template/handlers.rb +0 -50
  231. data/lib/action_view/template/resolver.rb +0 -272
  232. data/lib/action_view/template/text.rb +0 -30
  233. data/lib/action_view/template.rb +0 -337
  234. data/lib/action_view/test_case.rb +0 -245
  235. data/lib/action_view/testing/resolvers.rb +0 -50
  236. data/lib/action_view.rb +0 -84
  237. data/lib/sprockets/assets.rake +0 -99
  238. data/lib/sprockets/bootstrap.rb +0 -37
  239. data/lib/sprockets/compressors.rb +0 -83
  240. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  241. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  242. data/lib/sprockets/helpers.rb +0 -6
  243. data/lib/sprockets/railtie.rb +0 -62
  244. data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,64 +0,0 @@
1
- module ActionView
2
- # = Action View Cache Helper
3
- module Helpers
4
- module CacheHelper
5
- # This helper exposes a method for caching fragments of a view
6
- # rather than an entire action or page. This technique is useful
7
- # caching pieces like menus, lists of newstopics, static HTML
8
- # fragments, and so on. This method takes a block that contains
9
- # the content you wish to cache.
10
- #
11
- # See ActionController::Caching::Fragments for usage instructions.
12
- #
13
- # ==== Examples
14
- # If you want to cache a navigation menu, you can do following:
15
- #
16
- # <% cache do %>
17
- # <%= render :partial => "menu" %>
18
- # <% end %>
19
- #
20
- # You can also cache static content:
21
- #
22
- # <% cache do %>
23
- # <p>Hello users! Welcome to our website!</p>
24
- # <% end %>
25
- #
26
- # Static content with embedded ruby content can be cached as
27
- # well:
28
- #
29
- # <% cache do %>
30
- # Topics:
31
- # <%= render :partial => "topics", :collection => @topic_list %>
32
- # <i>Topics listed alphabetically</i>
33
- # <% end %>
34
- def cache(name = {}, options = nil, &block)
35
- if controller.perform_caching
36
- safe_concat(fragment_for(name, options, &block))
37
- else
38
- yield
39
- end
40
-
41
- nil
42
- end
43
-
44
- private
45
- # TODO: Create an object that has caching read/write on it
46
- def fragment_for(name = {}, options = nil, &block) #:nodoc:
47
- if fragment = controller.read_fragment(name, options)
48
- fragment
49
- else
50
- # VIEW TODO: Make #capture usable outside of ERB
51
- # This dance is needed because Builder can't use capture
52
- pos = output_buffer.length
53
- yield
54
- output_safe = output_buffer.html_safe?
55
- fragment = output_buffer.slice!(pos..-1)
56
- if output_safe
57
- self.output_buffer = output_buffer.class.new(output_buffer)
58
- end
59
- controller.write_fragment(name, fragment, options)
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,203 +0,0 @@
1
- require 'active_support/core_ext/object/blank'
2
- require 'active_support/core_ext/string/output_safety'
3
-
4
- module ActionView
5
- # = Action View Capture Helper
6
- module Helpers
7
- # CaptureHelper exposes methods to let you extract generated markup which
8
- # can be used in other parts of a template or layout file.
9
- #
10
- # It provides a method to capture blocks into variables through capture and
11
- # a way to capture a block of markup for use in a layout through content_for.
12
- module CaptureHelper
13
- # The capture method allows you to extract part of a template into a
14
- # variable. You can then use this variable anywhere in your templates or layout.
15
- #
16
- # ==== Examples
17
- # The capture method can be used in ERB templates...
18
- #
19
- # <% @greeting = capture do %>
20
- # Welcome to my shiny new web page! The date and time is
21
- # <%= Time.now %>
22
- # <% end %>
23
- #
24
- # ...and Builder (RXML) templates.
25
- #
26
- # @timestamp = capture do
27
- # "The current timestamp is #{Time.now}."
28
- # end
29
- #
30
- # You can then use that variable anywhere else. For example:
31
- #
32
- # <html>
33
- # <head><title><%= @greeting %></title></head>
34
- # <body>
35
- # <b><%= @greeting %></b>
36
- # </body></html>
37
- #
38
- def capture(*args)
39
- value = nil
40
- buffer = with_output_buffer { value = yield(*args) }
41
- if string = buffer.presence || value and string.is_a?(String)
42
- ERB::Util.html_escape string
43
- end
44
- end
45
-
46
- # Calling content_for stores a block of markup in an identifier for later use.
47
- # You can make subsequent calls to the stored content in other templates, helper modules
48
- # or the layout by passing the identifier as an argument to <tt>content_for</tt>.
49
- #
50
- # Note: <tt>yield</tt> can still be used to retrieve the stored content, but calling
51
- # <tt>yield</tt> doesn't work in helper modules, while <tt>content_for</tt> does.
52
- #
53
- # ==== Examples
54
- #
55
- # <% content_for :not_authorized do %>
56
- # alert('You are not authorized to do that!')
57
- # <% end %>
58
- #
59
- # You can then use <tt>content_for :not_authorized</tt> anywhere in your templates.
60
- #
61
- # <%= content_for :not_authorized if current_user.nil? %>
62
- #
63
- # This is equivalent to:
64
- #
65
- # <%= yield :not_authorized if current_user.nil? %>
66
- #
67
- # <tt>content_for</tt>, however, can also be used in helper modules.
68
- #
69
- # module StorageHelper
70
- # def stored_content
71
- # content_for(:storage) || "Your storage is empty"
72
- # end
73
- # end
74
- #
75
- # This helper works just like normal helpers.
76
- #
77
- # <%= stored_content %>
78
- #
79
- # You can use the <tt>yield</tt> syntax alongside an existing call to <tt>yield</tt> in a layout. For example:
80
- #
81
- # <%# This is the layout %>
82
- # <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
83
- # <head>
84
- # <title>My Website</title>
85
- # <%= yield :script %>
86
- # </head>
87
- # <body>
88
- # <%= yield %>
89
- # </body>
90
- # </html>
91
- #
92
- # And now, we'll create a view that has a <tt>content_for</tt> call that
93
- # creates the <tt>script</tt> identifier.
94
- #
95
- # <%# This is our view %>
96
- # Please login!
97
- #
98
- # <% content_for :script do %>
99
- # <script type="text/javascript">alert('You are not authorized to view this page!')</script>
100
- # <% end %>
101
- #
102
- # Then, in another view, you could to do something like this:
103
- #
104
- # <%= link_to 'Logout', :action => 'logout', :remote => true %>
105
- #
106
- # <% content_for :script do %>
107
- # <%= javascript_include_tag :defaults %>
108
- # <% end %>
109
- #
110
- # That will place +script+ tags for your default set of JavaScript files on the page;
111
- # this technique is useful if you'll only be using these scripts in a few views.
112
- #
113
- # Note that content_for concatenates the blocks it is given for a particular
114
- # identifier in order. For example:
115
- #
116
- # <% content_for :navigation do %>
117
- # <li><%= link_to 'Home', :action => 'index' %></li>
118
- # <% end %>
119
- #
120
- # <%# Add some other content, or use a different template: %>
121
- #
122
- # <% content_for :navigation do %>
123
- # <li><%= link_to 'Login', :action => 'login' %></li>
124
- # <% end %>
125
- #
126
- # Then, in another template or layout, this code would render both links in order:
127
- #
128
- # <ul><%= content_for :navigation %></ul>
129
- #
130
- # Lastly, simple content can be passed as a parameter:
131
- #
132
- # <% content_for :script, javascript_include_tag(:defaults) %>
133
- #
134
- # WARNING: content_for is ignored in caches. So you shouldn't use it
135
- # for elements that will be fragment cached.
136
- def content_for(name, content = nil, &block)
137
- if content || block_given?
138
- content = capture(&block) if block_given?
139
- @view_flow.append(name, content) if content
140
- nil
141
- else
142
- @view_flow.get(name)
143
- end
144
- end
145
-
146
- # The same as +content_for+ but when used with streaming flushes
147
- # straight back to the layout. In other words, if you want to
148
- # concatenate several times to the same buffer when rendering a given
149
- # template, you should use +content_for+, if not, use +provide+ to tell
150
- # the layout to stop looking for more contents.
151
- def provide(name, content = nil, &block)
152
- content = capture(&block) if block_given?
153
- result = @view_flow.append!(name, content) if content
154
- result unless content
155
- end
156
-
157
- # content_for? simply checks whether any content has been captured yet using content_for
158
- # Useful to render parts of your layout differently based on what is in your views.
159
- #
160
- # ==== Examples
161
- #
162
- # Perhaps you will use different css in you layout if no content_for :right_column
163
- #
164
- # <%# This is the layout %>
165
- # <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
166
- # <head>
167
- # <title>My Website</title>
168
- # <%= yield :script %>
169
- # </head>
170
- # <body class="<%= content_for?(:right_col) ? 'one-column' : 'two-column' %>">
171
- # <%= yield %>
172
- # <%= yield :right_col %>
173
- # </body>
174
- # </html>
175
- def content_for?(name)
176
- @view_flow.get(name).present?
177
- end
178
-
179
- # Use an alternate output buffer for the duration of the block.
180
- # Defaults to a new empty string.
181
- def with_output_buffer(buf = nil) #:nodoc:
182
- unless buf
183
- buf = ActionView::OutputBuffer.new
184
- buf.force_encoding(output_buffer.encoding) if output_buffer.respond_to?(:encoding) && buf.respond_to?(:force_encoding)
185
- end
186
- self.output_buffer, old_buffer = buf, output_buffer
187
- yield
188
- output_buffer
189
- ensure
190
- self.output_buffer = old_buffer
191
- end
192
-
193
- # Add the output buffer to the response body and start a new one.
194
- def flush_output_buffer #:nodoc:
195
- if output_buffer && !output_buffer.empty?
196
- response.body_parts << output_buffer
197
- self.output_buffer = output_buffer.respond_to?(:clone_empty) ? output_buffer.clone_empty : output_buffer[0, 0]
198
- nil
199
- end
200
- end
201
- end
202
- end
203
- end
@@ -1,25 +0,0 @@
1
- require 'active_support/core_ext/module/attr_internal'
2
-
3
- module ActionView
4
- module Helpers
5
- # This module keeps all methods and behavior in ActionView
6
- # that simply delegates to the controller.
7
- module ControllerHelper #:nodoc:
8
- attr_internal :controller, :request
9
-
10
- delegate :request_forgery_protection_token, :params, :session, :cookies, :response, :headers,
11
- :flash, :action_name, :controller_name, :controller_path, :to => :controller
12
-
13
- def assign_controller(controller)
14
- if @_controller = controller
15
- @_request = controller.request if controller.respond_to?(:request)
16
- @_config = controller.config.inheritable_copy if controller.respond_to?(:config)
17
- end
18
- end
19
-
20
- def logger
21
- controller.logger if controller.respond_to?(:logger)
22
- end
23
- end
24
- end
25
- end
@@ -1,32 +0,0 @@
1
- require 'active_support/core_ext/string/strip'
2
-
3
- module ActionView
4
- # = Action View CSRF Helper
5
- module Helpers
6
- module CsrfHelper
7
- # Returns meta tags "csrf-param" and "csrf-token" with the name of the cross-site
8
- # request forgery protection parameter and token, respectively.
9
- #
10
- # <head>
11
- # <%= csrf_meta_tags %>
12
- # </head>
13
- #
14
- # These are used to generate the dynamic forms that implement non-remote links with
15
- # <tt>:method</tt>.
16
- #
17
- # Note that regular forms generate hidden fields, and that Ajax calls are whitelisted,
18
- # so they do not use these tags.
19
- def csrf_meta_tags
20
- if protect_against_forgery?
21
- [
22
- tag('meta', :name => 'csrf-param', :content => request_forgery_protection_token),
23
- tag('meta', :name => 'csrf-token', :content => form_authenticity_token)
24
- ].join("\n").html_safe
25
- end
26
- end
27
-
28
- # For backwards compatibility.
29
- alias csrf_meta_tag csrf_meta_tags
30
- end
31
- end
32
- end