actionpack 3.0.20 → 3.1.0.beta1

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 (161) hide show
  1. data/CHANGELOG +88 -142
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +5 -6
  4. data/lib/abstract_controller.rb +1 -0
  5. data/lib/abstract_controller/asset_paths.rb +2 -2
  6. data/lib/abstract_controller/base.rb +24 -19
  7. data/lib/abstract_controller/callbacks.rb +19 -19
  8. data/lib/abstract_controller/helpers.rb +11 -13
  9. data/lib/abstract_controller/layouts.rb +4 -5
  10. data/lib/abstract_controller/railties/routes_helpers.rb +18 -0
  11. data/lib/abstract_controller/rendering.rb +34 -31
  12. data/lib/abstract_controller/url_for.rb +27 -0
  13. data/lib/abstract_controller/view_paths.rb +31 -6
  14. data/lib/action_controller.rb +5 -3
  15. data/lib/action_controller/base.rb +15 -16
  16. data/lib/action_controller/caching.rb +2 -2
  17. data/lib/action_controller/caching/actions.rb +11 -12
  18. data/lib/action_controller/caching/fragments.rb +41 -19
  19. data/lib/action_controller/caching/pages.rb +3 -9
  20. data/lib/action_controller/caching/sweeping.rb +0 -1
  21. data/lib/action_controller/deprecated.rb +1 -1
  22. data/lib/action_controller/log_subscriber.rb +1 -1
  23. data/lib/action_controller/metal.rb +78 -20
  24. data/lib/action_controller/metal/compatibility.rb +0 -9
  25. data/lib/action_controller/metal/conditional_get.rb +9 -9
  26. data/lib/action_controller/metal/data_streaming.rb +145 -0
  27. data/lib/action_controller/metal/force_ssl.rb +35 -0
  28. data/lib/action_controller/metal/head.rb +1 -1
  29. data/lib/action_controller/metal/helpers.rb +37 -44
  30. data/lib/action_controller/metal/hide_actions.rb +2 -3
  31. data/lib/action_controller/metal/http_authentication.rb +41 -38
  32. data/lib/action_controller/metal/implicit_render.rb +13 -13
  33. data/lib/action_controller/metal/instrumentation.rb +2 -2
  34. data/lib/action_controller/metal/mime_responds.rb +25 -19
  35. data/lib/action_controller/metal/params_wrapper.rb +224 -0
  36. data/lib/action_controller/metal/redirecting.rb +6 -2
  37. data/lib/action_controller/metal/renderers.rb +50 -36
  38. data/lib/action_controller/metal/rendering.rb +34 -25
  39. data/lib/action_controller/metal/request_forgery_protection.rb +18 -36
  40. data/lib/action_controller/metal/responder.rb +47 -12
  41. data/lib/action_controller/metal/streaming.rb +244 -138
  42. data/lib/action_controller/metal/testing.rb +0 -9
  43. data/lib/action_controller/metal/url_for.rb +12 -14
  44. data/lib/action_controller/railtie.rb +19 -37
  45. data/lib/action_controller/railties/paths.rb +24 -0
  46. data/lib/action_controller/record_identifier.rb +4 -10
  47. data/lib/action_controller/test_case.rb +36 -19
  48. data/lib/action_controller/vendor/html-scanner/html/node.rb +5 -5
  49. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +3 -3
  50. data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -0
  51. data/lib/action_dispatch.rb +4 -1
  52. data/lib/action_dispatch/http/cache.rb +5 -32
  53. data/lib/action_dispatch/http/filter_parameters.rb +3 -1
  54. data/lib/action_dispatch/http/mime_negotiation.rb +22 -3
  55. data/lib/action_dispatch/http/mime_type.rb +45 -5
  56. data/lib/action_dispatch/http/rack_cache.rb +58 -0
  57. data/lib/action_dispatch/http/request.rb +27 -41
  58. data/lib/action_dispatch/http/response.rb +56 -54
  59. data/lib/action_dispatch/http/upload.rb +1 -11
  60. data/lib/action_dispatch/http/url.rb +102 -42
  61. data/lib/action_dispatch/middleware/callbacks.rb +8 -25
  62. data/lib/action_dispatch/middleware/closed_error.rb +7 -0
  63. data/lib/action_dispatch/middleware/cookies.rb +37 -15
  64. data/lib/action_dispatch/middleware/flash.rb +80 -11
  65. data/lib/action_dispatch/middleware/params_parser.rb +2 -2
  66. data/lib/action_dispatch/middleware/reloader.rb +76 -0
  67. data/lib/action_dispatch/middleware/session/abstract_store.rb +56 -226
  68. data/lib/action_dispatch/middleware/session/cookie_store.rb +20 -44
  69. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -46
  70. data/lib/action_dispatch/middleware/show_exceptions.rb +15 -2
  71. data/lib/action_dispatch/middleware/stack.rb +50 -17
  72. data/lib/action_dispatch/middleware/static.rb +41 -29
  73. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +3 -3
  74. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +3 -3
  75. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +3 -3
  76. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +4 -2
  77. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +2 -6
  78. data/lib/action_dispatch/railtie.rb +8 -0
  79. data/lib/action_dispatch/routing.rb +13 -1
  80. data/lib/action_dispatch/routing/mapper.rb +345 -227
  81. data/lib/action_dispatch/routing/polymorphic_routes.rb +33 -13
  82. data/lib/action_dispatch/routing/redirection.rb +110 -0
  83. data/lib/action_dispatch/routing/route.rb +15 -13
  84. data/lib/action_dispatch/routing/route_set.rb +116 -90
  85. data/lib/action_dispatch/routing/routes_proxy.rb +35 -0
  86. data/lib/action_dispatch/routing/url_for.rb +25 -1
  87. data/lib/action_dispatch/testing/assertions/response.rb +8 -10
  88. data/lib/action_dispatch/testing/assertions/routing.rb +15 -15
  89. data/lib/action_dispatch/testing/assertions/selector.rb +13 -220
  90. data/lib/action_dispatch/testing/integration.rb +37 -28
  91. data/lib/action_dispatch/testing/performance_test.rb +1 -3
  92. data/lib/action_dispatch/testing/test_process.rb +1 -1
  93. data/lib/action_dispatch/testing/test_request.rb +9 -3
  94. data/lib/action_dispatch/testing/test_response.rb +4 -111
  95. data/lib/action_pack.rb +1 -1
  96. data/lib/action_pack/version.rb +3 -3
  97. data/lib/action_view.rb +39 -24
  98. data/lib/action_view/base.rb +61 -86
  99. data/lib/action_view/buffers.rb +43 -0
  100. data/lib/action_view/context.rb +21 -24
  101. data/lib/action_view/flows.rb +79 -0
  102. data/lib/action_view/helpers.rb +8 -6
  103. data/lib/action_view/helpers/active_model_helper.rb +0 -23
  104. data/lib/action_view/helpers/asset_paths.rb +79 -0
  105. data/lib/action_view/helpers/asset_tag_helper.rb +30 -500
  106. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +147 -0
  107. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +101 -0
  108. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +200 -0
  109. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +152 -0
  110. data/lib/action_view/helpers/atom_feed_helper.rb +2 -2
  111. data/lib/action_view/helpers/cache_helper.rb +11 -19
  112. data/lib/action_view/helpers/capture_helper.rb +19 -8
  113. data/lib/action_view/helpers/controller_helper.rb +21 -0
  114. data/lib/action_view/helpers/csrf_helper.rb +22 -4
  115. data/lib/action_view/helpers/date_helper.rb +36 -22
  116. data/lib/action_view/helpers/form_helper.rb +199 -113
  117. data/lib/action_view/helpers/form_options_helper.rb +10 -11
  118. data/lib/action_view/helpers/form_tag_helper.rb +94 -22
  119. data/lib/action_view/helpers/javascript_helper.rb +24 -107
  120. data/lib/action_view/helpers/number_helper.rb +36 -33
  121. data/lib/action_view/helpers/output_safety_helper.rb +38 -0
  122. data/lib/action_view/helpers/record_tag_helper.rb +6 -6
  123. data/lib/action_view/helpers/rendering_helper.rb +90 -0
  124. data/lib/action_view/helpers/sanitize_helper.rb +2 -2
  125. data/lib/action_view/helpers/sprockets_helper.rb +69 -0
  126. data/lib/action_view/helpers/tag_helper.rb +34 -12
  127. data/lib/action_view/helpers/text_helper.rb +30 -145
  128. data/lib/action_view/helpers/translation_helper.rb +10 -17
  129. data/lib/action_view/helpers/url_helper.rb +70 -67
  130. data/lib/action_view/locale/en.yml +1 -1
  131. data/lib/action_view/lookup_context.rb +36 -14
  132. data/lib/action_view/{paths.rb → path_set.rb} +9 -8
  133. data/lib/action_view/railtie.rb +12 -4
  134. data/lib/action_view/renderer/abstract_renderer.rb +36 -0
  135. data/lib/action_view/{render/partials.rb → renderer/partial_renderer.rb} +147 -146
  136. data/lib/action_view/renderer/renderer.rb +54 -0
  137. data/lib/action_view/renderer/streaming_template_renderer.rb +106 -0
  138. data/lib/action_view/renderer/template_renderer.rb +74 -0
  139. data/lib/action_view/template.rb +91 -54
  140. data/lib/action_view/template/error.rb +11 -8
  141. data/lib/action_view/template/handler.rb +9 -1
  142. data/lib/action_view/template/handlers.rb +9 -9
  143. data/lib/action_view/template/handlers/builder.rb +4 -4
  144. data/lib/action_view/template/handlers/erb.rb +21 -41
  145. data/lib/action_view/template/resolver.rb +171 -57
  146. data/lib/action_view/template/text.rb +0 -4
  147. data/lib/action_view/test_case.rb +32 -16
  148. data/lib/action_view/testing/resolvers.rb +16 -10
  149. data/lib/sprockets/railtie.rb +100 -0
  150. metadata +162 -140
  151. checksums.yaml +0 -7
  152. data/lib/action_controller/deprecated/base.rb +0 -143
  153. data/lib/action_controller/deprecated/dispatcher.rb +0 -28
  154. data/lib/action_controller/deprecated/url_writer.rb +0 -14
  155. data/lib/action_dispatch/routing/deprecated_mapper.rb +0 -525
  156. data/lib/action_view/helpers/prototype_helper.rb +0 -851
  157. data/lib/action_view/helpers/raw_output_helper.rb +0 -18
  158. data/lib/action_view/helpers/scriptaculous_helper.rb +0 -263
  159. data/lib/action_view/render/layouts.rb +0 -83
  160. data/lib/action_view/render/rendering.rb +0 -67
  161. data/lib/action_view/template/handlers/rjs.rb +0 -17
@@ -6,27 +6,23 @@ require 'active_support/ordered_options'
6
6
  require 'action_view/log_subscriber'
7
7
 
8
8
  module ActionView #:nodoc:
9
- class NonConcattingString < ActiveSupport::SafeBuffer
10
- end
11
-
12
9
  # = Action View Base
13
10
  #
14
- # Action View templates can be written in three ways. If the template file has a <tt>.erb</tt> (or <tt>.rhtml</tt>) extension then it uses a mixture of ERb
11
+ # Action View templates can be written in several ways. If the template file has a <tt>.erb</tt> (or <tt>.rhtml</tt>) extension then it uses a mixture of ERb
15
12
  # (included in Ruby) and HTML. If the template file has a <tt>.builder</tt> (or <tt>.rxml</tt>) extension then Jim Weirich's Builder::XmlMarkup library is used.
16
- # If the template file has a <tt>.rjs</tt> extension then it will use ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.
17
13
  #
18
- # == ERb
14
+ # == ERB
19
15
  #
20
- # You trigger ERb by using embeddings such as <% %>, <% -%>, and <%= %>. The <%= %> tag set is used when you want output. Consider the
16
+ # You trigger ERB by using embeddings such as <% %>, <% -%>, and <%= %>. The <%= %> tag set is used when you want output. Consider the
21
17
  # following loop for names:
22
18
  #
23
19
  # <b>Names of all the people</b>
24
- # <% for person in @people %>
20
+ # <% @people.each do |person| %>
25
21
  # Name: <%= person.name %><br/>
26
22
  # <% end %>
27
23
  #
28
24
  # The loop is setup in regular embedding tags <% %> and the name is written using the output embedding tag <%= %>. Note that this
29
- # is not just a usage suggestion. Regular output functions like print or puts won't work with ERb templates. So this would be wrong:
25
+ # is not just a usage suggestion. Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
30
26
  #
31
27
  # <%# WRONG %>
32
28
  # Hi, Mr. <% puts "Frodo" %>
@@ -84,7 +80,7 @@ module ActionView #:nodoc:
84
80
  #
85
81
  # == Builder
86
82
  #
87
- # Builder templates are a more programmatic alternative to ERb. They are especially useful for generating XML content. An XmlMarkup object
83
+ # Builder templates are a more programmatic alternative to ERB. They are especially useful for generating XML content. An XmlMarkup object
88
84
  # named +xml+ is automatically made available to templates with a <tt>.builder</tt> extension.
89
85
  #
90
86
  # Here are some basic examples:
@@ -134,108 +130,87 @@ module ActionView #:nodoc:
134
130
  # end
135
131
  #
136
132
  # More builder documentation can be found at http://builder.rubyforge.org.
137
- #
138
- # == JavaScriptGenerator
139
- #
140
- # JavaScriptGenerator templates end in <tt>.rjs</tt>. Unlike conventional templates which are used to
141
- # render the results of an action, these templates generate instructions on how to modify an already rendered page. This makes it easy to
142
- # modify multiple elements on your page in one declarative Ajax response. Actions with these templates are called in the background with Ajax
143
- # and make updates to the page where the request originated from.
144
- #
145
- # An instance of the JavaScriptGenerator object named +page+ is automatically made available to your template, which is implicitly wrapped in an ActionView::Helpers::PrototypeHelper#update_page block.
146
- #
147
- # When an <tt>.rjs</tt> action is called with +link_to_remote+, the generated JavaScript is automatically evaluated. Example:
148
- #
149
- # link_to_remote :url => {:action => 'delete'}
150
- #
151
- # The subsequently rendered <tt>delete.rjs</tt> might look like:
152
- #
153
- # page.replace_html 'sidebar', :partial => 'sidebar'
154
- # page.remove "person-#{@person.id}"
155
- # page.visual_effect :highlight, 'user-list'
156
- #
157
- # This refreshes the sidebar, removes a person element and highlights the user list.
158
- #
159
- # See the ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods documentation for more details.
160
133
  class Base
161
- module Subclasses
162
- end
163
-
164
- include Helpers, Rendering, Partials, Layouts, ::ERB::Util, Context
165
-
166
- # Specify whether RJS responses should be wrapped in a try/catch block
167
- # that alert()s the caught exception (and then re-raises it).
168
- cattr_reader :debug_rjs
169
- @@debug_rjs = false
170
- def self.debug_rjs=(new_value)
171
- ActiveSupport::Deprecation.warn("config.action_view.debug_rjs will be removed in 3.1, from 3.1 onwards you will need to install prototype-rails to continue to use RJS templates ")
172
- @@debug_rjs = new_value
173
- end
134
+ include Helpers, ::ERB::Util, Context
174
135
 
175
136
  # Specify the proc used to decorate input tags that refer to attributes with errors.
176
137
  cattr_accessor :field_error_proc
177
138
  @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
178
139
 
140
+ # How to complete the streaming when an exception occurs.
141
+ # This is our best guess: first try to close the attribute, then the tag.
142
+ cattr_accessor :streaming_completion_on_exception
143
+ @@streaming_completion_on_exception = %("><script type="text/javascript">window.location = "/500.html"</script></html>)
144
+
179
145
  class_attribute :helpers
180
146
  class_attribute :_routes
181
147
 
182
148
  class << self
183
149
  delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB'
184
150
  delegate :logger, :to => 'ActionController::Base', :allow_nil => true
185
- end
186
151
 
187
- attr_accessor :base_path, :assigns, :template_extension, :lookup_context
188
- attr_internal :captures, :request, :controller, :template, :config
152
+ def cache_template_loading
153
+ ActionView::Resolver.caching?
154
+ end
189
155
 
190
- delegate :find_template, :template_exists?, :formats, :formats=, :locale, :locale=,
191
- :view_paths, :view_paths=, :with_fallbacks, :update_details, :with_layout_format, :to => :lookup_context
156
+ def cache_template_loading=(value)
157
+ ActionView::Resolver.caching = value
158
+ end
192
159
 
193
- delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
194
- :flash, :action_name, :controller_name, :to => :controller
160
+ def process_view_paths(value)
161
+ value.is_a?(PathSet) ?
162
+ value.dup : ActionView::PathSet.new(Array.wrap(value))
163
+ end
195
164
 
196
- delegate :logger, :to => :controller, :allow_nil => true
165
+ def xss_safe? #:nodoc:
166
+ true
167
+ end
197
168
 
198
- # TODO: HACK FOR RJS
199
- def view_context
200
- self
169
+ # This method receives routes and helpers from the controller
170
+ # and return a subclass ready to be used as view context.
171
+ def prepare(routes, helpers) #:nodoc:
172
+ Class.new(self) do
173
+ if routes
174
+ include routes.url_helpers
175
+ include routes.mounted_helpers
176
+ end
177
+
178
+ if helpers
179
+ include helpers
180
+ self.helpers = helpers
181
+ end
182
+ end
183
+ end
201
184
  end
202
185
 
203
- def self.xss_safe? #:nodoc:
204
- true
205
- end
186
+ attr_accessor :view_renderer
187
+ attr_internal :config, :assigns
206
188
 
207
- def self.process_view_paths(value)
208
- value.is_a?(PathSet) ?
209
- value.dup : ActionView::PathSet.new(Array.wrap(value))
210
- end
189
+ delegate :lookup_context, :to => :view_renderer
190
+ delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :to => :lookup_context
211
191
 
212
192
  def assign(new_assigns) # :nodoc:
213
- self.assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
193
+ @_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
214
194
  end
215
195
 
216
- def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc:
217
- assign(assigns_for_first_render)
218
- self.helpers = self.class.helpers || Module.new
219
-
220
- if @_controller = controller
221
- @_request = controller.request if controller.respond_to?(:request)
196
+ def initialize(context = nil, assigns = {}, controller = nil, formats = nil) #:nodoc:
197
+ @_config = {}
198
+
199
+ # Handle all these for backwards compatibility.
200
+ # TODO Provide a new API for AV::Base and deprecate this one.
201
+ if context.is_a?(ActionView::Renderer)
202
+ @view_renderer = context
203
+ elsif
204
+ lookup_context = context.is_a?(ActionView::LookupContext) ?
205
+ context : ActionView::LookupContext.new(context)
206
+ lookup_context.formats = formats if formats
207
+ lookup_context.prefixes = controller._prefixes if controller
208
+ @view_renderer = ActionView::Renderer.new(lookup_context)
222
209
  end
223
210
 
224
- config = controller && controller.respond_to?(:config) ? controller.config : {}
225
- @_config = ActiveSupport::InheritableOptions.new(config)
226
-
227
- @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
228
- @_virtual_path = nil
229
- @output_buffer = nil
230
-
231
- @lookup_context = lookup_context.is_a?(ActionView::LookupContext) ?
232
- lookup_context : ActionView::LookupContext.new(lookup_context)
233
- @lookup_context.formats = formats if formats
234
- @controller = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :controller)
235
- end
236
-
237
- def controller_path
238
- @controller_path ||= controller && controller.controller_path
211
+ assign(assigns)
212
+ assign_controller(controller)
213
+ _prepare_context
239
214
  end
240
215
 
241
216
  ActiveSupport.run_load_hooks(:action_view, self)
@@ -0,0 +1,43 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+
3
+ module ActionView
4
+ class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc:
5
+ def initialize(*)
6
+ super
7
+ encode! if encoding_aware?
8
+ end
9
+
10
+ def <<(value)
11
+ super(value.to_s)
12
+ end
13
+ alias :append= :<<
14
+ alias :safe_append= :safe_concat
15
+ end
16
+
17
+ class StreamingBuffer #:nodoc:
18
+ def initialize(block)
19
+ @block = block
20
+ end
21
+
22
+ def <<(value)
23
+ value = value.to_s
24
+ value = ERB::Util.h(value) unless value.html_safe?
25
+ @block.call(value)
26
+ end
27
+ alias :concat :<<
28
+ alias :append= :<<
29
+
30
+ def safe_concat(value)
31
+ @block.call(value.to_s)
32
+ end
33
+ alias :safe_append= :safe_concat
34
+
35
+ def html_safe?
36
+ true
37
+ end
38
+
39
+ def html_safe
40
+ self
41
+ end
42
+ end
43
+ end
@@ -2,38 +2,35 @@ module ActionView
2
2
  module CompiledTemplates #:nodoc:
3
3
  # holds compiled template code
4
4
  end
5
+
5
6
  # = Action View Context
6
7
  #
7
8
  # Action View contexts are supplied to Action Controller to render template.
8
9
  # The default Action View context is ActionView::Base.
9
10
  #
10
- # In order to work with ActionController, a Context must implement:
11
- #
12
- # Context#render_partial[options]
13
- # - responsible for setting options[:_template]
14
- # - Returns String with the rendered partial
15
- # options<Hash>:: see _render_partial in ActionView::Base
16
- # Context#render_template[template, layout, options, partial]
17
- # - Returns String with the rendered template
18
- # template<ActionView::Template>:: The template to render
19
- # layout<ActionView::Template>:: The layout to render around the template
20
- # options<Hash>:: See _render_template_with_layout in ActionView::Base
21
- # partial<Boolean>:: Whether or not the template to render is a partial
22
- #
23
- # An Action View context can also mix in Action View's helpers. In order to
24
- # mix in helpers, a context must implement:
25
- #
26
- # Context#controller
27
- # - Returns an instance of AbstractController
28
- #
29
- # In any case, a context must mix in ActionView::Context, which stores compiled
30
- # template and provides the output buffer.
11
+ # In order to work with ActionController, a Context must just include this module.
12
+ # The initialization of the variables used by the context (@output_buffer, @view_flow,
13
+ # and @virtual_path) is responsibility of the object that includes this module
14
+ # (although you can call _prepare_context defined below).
31
15
  module Context
32
16
  include CompiledTemplates
33
- attr_accessor :output_buffer
17
+ attr_accessor :output_buffer, :view_flow
18
+
19
+ # Prepares the context by setting the appropriate instance variables.
20
+ # :api: plugin
21
+ def _prepare_context
22
+ @view_flow = OutputFlow.new
23
+ @output_buffer = nil
24
+ @virtual_path = nil
25
+ end
34
26
 
35
- def convert_to_model(object)
36
- object.respond_to?(:to_model) ? object.to_model : object
27
+ # Encapsulates the interaction with the view flow so it
28
+ # returns the correct buffer on yield. This is usually
29
+ # overwriten by helpers to add more behavior.
30
+ # :api: plugin
31
+ def _layout_for(name=nil)
32
+ name ||= :layout
33
+ view_flow.get(name).html_safe
37
34
  end
38
35
  end
39
36
  end
@@ -0,0 +1,79 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+
3
+ module ActionView
4
+ class OutputFlow #:nodoc:
5
+ attr_reader :content
6
+
7
+ def initialize
8
+ @content = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
9
+ end
10
+
11
+ # Called by _layout_for to read stored values.
12
+ def get(key)
13
+ @content[key]
14
+ end
15
+
16
+ # Called by each renderer object to set the layout contents.
17
+ def set(key, value)
18
+ @content[key] = value
19
+ end
20
+
21
+ # Called by content_for
22
+ def append(key, value)
23
+ @content[key] << value
24
+ end
25
+
26
+ # Called by provide
27
+ def append!(key, value)
28
+ @content[key] << value
29
+ end
30
+ end
31
+
32
+ class StreamingFlow < OutputFlow #:nodoc:
33
+ def initialize(view, fiber)
34
+ @view = view
35
+ @parent = nil
36
+ @child = view.output_buffer
37
+ @content = view.view_flow.content
38
+ @fiber = fiber
39
+ @root = Fiber.current.object_id
40
+ end
41
+
42
+ # Try to get an stored content. If the content
43
+ # is not available and we are inside the layout
44
+ # fiber, we set that we are waiting for the given
45
+ # key and yield.
46
+ def get(key)
47
+ return super if @content.key?(key)
48
+
49
+ if inside_fiber?
50
+ view = @view
51
+
52
+ begin
53
+ @waiting_for = key
54
+ view.output_buffer, @parent = @child, view.output_buffer
55
+ Fiber.yield
56
+ ensure
57
+ @waiting_for = nil
58
+ view.output_buffer, @child = @parent, view.output_buffer
59
+ end
60
+ end
61
+
62
+ super
63
+ end
64
+
65
+ # Appends the contents for the given key. This is called
66
+ # by provides and resumes back to the fiber if it is
67
+ # the key it is waiting for.
68
+ def append!(key, value)
69
+ super
70
+ @fiber.resume if @waiting_for == key
71
+ end
72
+
73
+ private
74
+
75
+ def inside_fiber?
76
+ Fiber.current.object_id != @root
77
+ end
78
+ end
79
+ end
@@ -9,6 +9,7 @@ module ActionView #:nodoc:
9
9
  autoload :AtomFeedHelper
10
10
  autoload :CacheHelper
11
11
  autoload :CaptureHelper
12
+ autoload :ControllerHelper
12
13
  autoload :CsrfHelper
13
14
  autoload :DateHelper
14
15
  autoload :DebugHelper
@@ -17,11 +18,11 @@ module ActionView #:nodoc:
17
18
  autoload :FormTagHelper
18
19
  autoload :JavaScriptHelper, "action_view/helpers/javascript_helper"
19
20
  autoload :NumberHelper
20
- autoload :PrototypeHelper
21
- autoload :RawOutputHelper
21
+ autoload :OutputSafetyHelper
22
22
  autoload :RecordTagHelper
23
+ autoload :RenderingHelper
23
24
  autoload :SanitizeHelper
24
- autoload :ScriptaculousHelper
25
+ autoload :SprocketsHelper
25
26
  autoload :TagHelper
26
27
  autoload :TextHelper
27
28
  autoload :TranslationHelper
@@ -39,6 +40,7 @@ module ActionView #:nodoc:
39
40
  include AtomFeedHelper
40
41
  include CacheHelper
41
42
  include CaptureHelper
43
+ include ControllerHelper
42
44
  include CsrfHelper
43
45
  include DateHelper
44
46
  include DebugHelper
@@ -47,11 +49,11 @@ module ActionView #:nodoc:
47
49
  include FormTagHelper
48
50
  include JavaScriptHelper
49
51
  include NumberHelper
50
- include PrototypeHelper
51
- include RawOutputHelper
52
+ include OutputSafetyHelper
52
53
  include RecordTagHelper
54
+ include RenderingHelper
53
55
  include SanitizeHelper
54
- include ScriptaculousHelper
56
+ include SprocketsHelper
55
57
  include TagHelper
56
58
  include TextHelper
57
59
  include TranslationHelper
@@ -7,25 +7,6 @@ module ActionView
7
7
  # = Active Model Helpers
8
8
  module Helpers
9
9
  module ActiveModelHelper
10
- %w(input form error_messages_for error_message_on).each do |method|
11
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
12
- def #{method}(*args)
13
- ActiveSupport::Deprecation.warn "#{method} was removed from Rails and is now available as a plugin. " <<
14
- "Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`.", caller
15
- end
16
- RUBY
17
- end
18
- end
19
-
20
- module ActiveModelFormBuilder
21
- %w(error_messages error_message_on).each do |method|
22
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
23
- def #{method}(*args)
24
- ActiveSupport::Deprecation.warn "f.#{method} was removed from Rails and is now available as a plugin. " <<
25
- "Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`.", caller
26
- end
27
- RUBY
28
- end
29
10
  end
30
11
 
31
12
  module ActiveModelInstanceTag
@@ -67,10 +48,6 @@ module ActionView
67
48
  end
68
49
  end
69
50
 
70
- class FormBuilder
71
- include ActiveModelFormBuilder
72
- end
73
-
74
51
  class InstanceTag
75
52
  include ActiveModelInstanceTag
76
53
  end