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.
- data/CHANGELOG +88 -142
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -6
- data/lib/abstract_controller.rb +1 -0
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +24 -19
- data/lib/abstract_controller/callbacks.rb +19 -19
- data/lib/abstract_controller/helpers.rb +11 -13
- data/lib/abstract_controller/layouts.rb +4 -5
- data/lib/abstract_controller/railties/routes_helpers.rb +18 -0
- data/lib/abstract_controller/rendering.rb +34 -31
- data/lib/abstract_controller/url_for.rb +27 -0
- data/lib/abstract_controller/view_paths.rb +31 -6
- data/lib/action_controller.rb +5 -3
- data/lib/action_controller/base.rb +15 -16
- data/lib/action_controller/caching.rb +2 -2
- data/lib/action_controller/caching/actions.rb +11 -12
- data/lib/action_controller/caching/fragments.rb +41 -19
- data/lib/action_controller/caching/pages.rb +3 -9
- data/lib/action_controller/caching/sweeping.rb +0 -1
- data/lib/action_controller/deprecated.rb +1 -1
- data/lib/action_controller/log_subscriber.rb +1 -1
- data/lib/action_controller/metal.rb +78 -20
- data/lib/action_controller/metal/compatibility.rb +0 -9
- data/lib/action_controller/metal/conditional_get.rb +9 -9
- data/lib/action_controller/metal/data_streaming.rb +145 -0
- data/lib/action_controller/metal/force_ssl.rb +35 -0
- data/lib/action_controller/metal/head.rb +1 -1
- data/lib/action_controller/metal/helpers.rb +37 -44
- data/lib/action_controller/metal/hide_actions.rb +2 -3
- data/lib/action_controller/metal/http_authentication.rb +41 -38
- data/lib/action_controller/metal/implicit_render.rb +13 -13
- data/lib/action_controller/metal/instrumentation.rb +2 -2
- data/lib/action_controller/metal/mime_responds.rb +25 -19
- data/lib/action_controller/metal/params_wrapper.rb +224 -0
- data/lib/action_controller/metal/redirecting.rb +6 -2
- data/lib/action_controller/metal/renderers.rb +50 -36
- data/lib/action_controller/metal/rendering.rb +34 -25
- data/lib/action_controller/metal/request_forgery_protection.rb +18 -36
- data/lib/action_controller/metal/responder.rb +47 -12
- data/lib/action_controller/metal/streaming.rb +244 -138
- data/lib/action_controller/metal/testing.rb +0 -9
- data/lib/action_controller/metal/url_for.rb +12 -14
- data/lib/action_controller/railtie.rb +19 -37
- data/lib/action_controller/railties/paths.rb +24 -0
- data/lib/action_controller/record_identifier.rb +4 -10
- data/lib/action_controller/test_case.rb +36 -19
- data/lib/action_controller/vendor/html-scanner/html/node.rb +5 -5
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +3 -3
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -0
- data/lib/action_dispatch.rb +4 -1
- data/lib/action_dispatch/http/cache.rb +5 -32
- data/lib/action_dispatch/http/filter_parameters.rb +3 -1
- data/lib/action_dispatch/http/mime_negotiation.rb +22 -3
- data/lib/action_dispatch/http/mime_type.rb +45 -5
- data/lib/action_dispatch/http/rack_cache.rb +58 -0
- data/lib/action_dispatch/http/request.rb +27 -41
- data/lib/action_dispatch/http/response.rb +56 -54
- data/lib/action_dispatch/http/upload.rb +1 -11
- data/lib/action_dispatch/http/url.rb +102 -42
- data/lib/action_dispatch/middleware/callbacks.rb +8 -25
- data/lib/action_dispatch/middleware/closed_error.rb +7 -0
- data/lib/action_dispatch/middleware/cookies.rb +37 -15
- data/lib/action_dispatch/middleware/flash.rb +80 -11
- data/lib/action_dispatch/middleware/params_parser.rb +2 -2
- data/lib/action_dispatch/middleware/reloader.rb +76 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +56 -226
- data/lib/action_dispatch/middleware/session/cookie_store.rb +20 -44
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -46
- data/lib/action_dispatch/middleware/show_exceptions.rb +15 -2
- data/lib/action_dispatch/middleware/stack.rb +50 -17
- data/lib/action_dispatch/middleware/static.rb +41 -29
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +4 -2
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +2 -6
- data/lib/action_dispatch/railtie.rb +8 -0
- data/lib/action_dispatch/routing.rb +13 -1
- data/lib/action_dispatch/routing/mapper.rb +345 -227
- data/lib/action_dispatch/routing/polymorphic_routes.rb +33 -13
- data/lib/action_dispatch/routing/redirection.rb +110 -0
- data/lib/action_dispatch/routing/route.rb +15 -13
- data/lib/action_dispatch/routing/route_set.rb +116 -90
- data/lib/action_dispatch/routing/routes_proxy.rb +35 -0
- data/lib/action_dispatch/routing/url_for.rb +25 -1
- data/lib/action_dispatch/testing/assertions/response.rb +8 -10
- data/lib/action_dispatch/testing/assertions/routing.rb +15 -15
- data/lib/action_dispatch/testing/assertions/selector.rb +13 -220
- data/lib/action_dispatch/testing/integration.rb +37 -28
- data/lib/action_dispatch/testing/performance_test.rb +1 -3
- data/lib/action_dispatch/testing/test_process.rb +1 -1
- data/lib/action_dispatch/testing/test_request.rb +9 -3
- data/lib/action_dispatch/testing/test_response.rb +4 -111
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +3 -3
- data/lib/action_view.rb +39 -24
- data/lib/action_view/base.rb +61 -86
- data/lib/action_view/buffers.rb +43 -0
- data/lib/action_view/context.rb +21 -24
- data/lib/action_view/flows.rb +79 -0
- data/lib/action_view/helpers.rb +8 -6
- data/lib/action_view/helpers/active_model_helper.rb +0 -23
- data/lib/action_view/helpers/asset_paths.rb +79 -0
- data/lib/action_view/helpers/asset_tag_helper.rb +30 -500
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +147 -0
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +101 -0
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +200 -0
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +152 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +2 -2
- data/lib/action_view/helpers/cache_helper.rb +11 -19
- data/lib/action_view/helpers/capture_helper.rb +19 -8
- data/lib/action_view/helpers/controller_helper.rb +21 -0
- data/lib/action_view/helpers/csrf_helper.rb +22 -4
- data/lib/action_view/helpers/date_helper.rb +36 -22
- data/lib/action_view/helpers/form_helper.rb +199 -113
- data/lib/action_view/helpers/form_options_helper.rb +10 -11
- data/lib/action_view/helpers/form_tag_helper.rb +94 -22
- data/lib/action_view/helpers/javascript_helper.rb +24 -107
- data/lib/action_view/helpers/number_helper.rb +36 -33
- data/lib/action_view/helpers/output_safety_helper.rb +38 -0
- data/lib/action_view/helpers/record_tag_helper.rb +6 -6
- data/lib/action_view/helpers/rendering_helper.rb +90 -0
- data/lib/action_view/helpers/sanitize_helper.rb +2 -2
- data/lib/action_view/helpers/sprockets_helper.rb +69 -0
- data/lib/action_view/helpers/tag_helper.rb +34 -12
- data/lib/action_view/helpers/text_helper.rb +30 -145
- data/lib/action_view/helpers/translation_helper.rb +10 -17
- data/lib/action_view/helpers/url_helper.rb +70 -67
- data/lib/action_view/locale/en.yml +1 -1
- data/lib/action_view/lookup_context.rb +36 -14
- data/lib/action_view/{paths.rb → path_set.rb} +9 -8
- data/lib/action_view/railtie.rb +12 -4
- data/lib/action_view/renderer/abstract_renderer.rb +36 -0
- data/lib/action_view/{render/partials.rb → renderer/partial_renderer.rb} +147 -146
- data/lib/action_view/renderer/renderer.rb +54 -0
- data/lib/action_view/renderer/streaming_template_renderer.rb +106 -0
- data/lib/action_view/renderer/template_renderer.rb +74 -0
- data/lib/action_view/template.rb +91 -54
- data/lib/action_view/template/error.rb +11 -8
- data/lib/action_view/template/handler.rb +9 -1
- data/lib/action_view/template/handlers.rb +9 -9
- data/lib/action_view/template/handlers/builder.rb +4 -4
- data/lib/action_view/template/handlers/erb.rb +21 -41
- data/lib/action_view/template/resolver.rb +171 -57
- data/lib/action_view/template/text.rb +0 -4
- data/lib/action_view/test_case.rb +32 -16
- data/lib/action_view/testing/resolvers.rb +16 -10
- data/lib/sprockets/railtie.rb +100 -0
- metadata +162 -140
- checksums.yaml +0 -7
- data/lib/action_controller/deprecated/base.rb +0 -143
- data/lib/action_controller/deprecated/dispatcher.rb +0 -28
- data/lib/action_controller/deprecated/url_writer.rb +0 -14
- data/lib/action_dispatch/routing/deprecated_mapper.rb +0 -525
- data/lib/action_view/helpers/prototype_helper.rb +0 -851
- data/lib/action_view/helpers/raw_output_helper.rb +0 -18
- data/lib/action_view/helpers/scriptaculous_helper.rb +0 -263
- data/lib/action_view/render/layouts.rb +0 -83
- data/lib/action_view/render/rendering.rb +0 -67
- data/lib/action_view/template/handlers/rjs.rb +0 -17
data/lib/action_view/base.rb
CHANGED
@@ -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
|
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
|
-
# ==
|
14
|
+
# == ERB
|
19
15
|
#
|
20
|
-
# You trigger
|
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
|
-
# <%
|
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
|
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
|
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
|
-
|
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
|
-
|
188
|
-
|
152
|
+
def cache_template_loading
|
153
|
+
ActionView::Resolver.caching?
|
154
|
+
end
|
189
155
|
|
190
|
-
|
191
|
-
|
156
|
+
def cache_template_loading=(value)
|
157
|
+
ActionView::Resolver.caching = value
|
158
|
+
end
|
192
159
|
|
193
|
-
|
194
|
-
|
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
|
-
|
165
|
+
def xss_safe? #:nodoc:
|
166
|
+
true
|
167
|
+
end
|
197
168
|
|
198
|
-
|
199
|
-
|
200
|
-
|
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
|
-
|
204
|
-
|
205
|
-
end
|
186
|
+
attr_accessor :view_renderer
|
187
|
+
attr_internal :config, :assigns
|
206
188
|
|
207
|
-
|
208
|
-
|
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
|
-
|
193
|
+
@_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
|
214
194
|
end
|
215
195
|
|
216
|
-
def initialize(
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
-
|
225
|
-
|
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
|
data/lib/action_view/context.rb
CHANGED
@@ -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
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
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
|
-
|
36
|
-
|
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
|
data/lib/action_view/helpers.rb
CHANGED
@@ -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 :
|
21
|
-
autoload :RawOutputHelper
|
21
|
+
autoload :OutputSafetyHelper
|
22
22
|
autoload :RecordTagHelper
|
23
|
+
autoload :RenderingHelper
|
23
24
|
autoload :SanitizeHelper
|
24
|
-
autoload :
|
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
|
51
|
-
include RawOutputHelper
|
52
|
+
include OutputSafetyHelper
|
52
53
|
include RecordTagHelper
|
54
|
+
include RenderingHelper
|
53
55
|
include SanitizeHelper
|
54
|
-
include
|
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
|