actionpack 4.0.13 → 4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +131 -1636
- data/README.rdoc +1 -6
- data/lib/abstract_controller.rb +1 -2
- data/lib/abstract_controller/base.rb +3 -25
- data/lib/abstract_controller/callbacks.rb +4 -2
- data/lib/abstract_controller/collector.rb +11 -1
- data/lib/abstract_controller/helpers.rb +18 -15
- data/lib/abstract_controller/rendering.rb +48 -127
- data/lib/action_controller.rb +1 -17
- data/lib/action_controller/base.rb +14 -6
- data/lib/action_controller/caching.rb +1 -11
- data/lib/action_controller/log_subscriber.rb +1 -1
- data/lib/action_controller/metal.rb +0 -4
- data/lib/action_controller/metal/flash.rb +17 -0
- data/lib/action_controller/metal/force_ssl.rb +1 -1
- data/lib/action_controller/metal/head.rb +1 -3
- data/lib/action_controller/metal/helpers.rb +6 -2
- data/lib/action_controller/metal/http_authentication.rb +7 -14
- data/lib/action_controller/metal/instrumentation.rb +1 -1
- data/lib/action_controller/metal/live.rb +74 -0
- data/lib/action_controller/metal/mime_responds.rb +93 -16
- data/lib/action_controller/metal/params_wrapper.rb +4 -11
- data/lib/action_controller/metal/rack_delegation.rb +1 -1
- data/lib/action_controller/metal/redirecting.rb +20 -20
- data/lib/action_controller/metal/renderers.rb +8 -5
- data/lib/action_controller/metal/rendering.rb +14 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +67 -13
- data/lib/action_controller/metal/responder.rb +12 -2
- data/lib/action_controller/metal/streaming.rb +18 -20
- data/lib/action_controller/metal/strong_parameters.rb +22 -34
- data/lib/action_controller/railtie.rb +0 -1
- data/lib/action_controller/test_case.rb +0 -15
- data/lib/action_dispatch.rb +1 -0
- data/lib/action_dispatch/http/headers.rb +1 -3
- data/lib/action_dispatch/http/mime_negotiation.rb +16 -2
- data/lib/action_dispatch/http/mime_type.rb +4 -22
- data/lib/action_dispatch/http/mime_types.rb +1 -0
- data/lib/action_dispatch/http/parameters.rb +18 -19
- data/lib/action_dispatch/http/request.rb +16 -25
- data/lib/action_dispatch/http/response.rb +21 -8
- data/lib/action_dispatch/http/upload.rb +0 -13
- data/lib/action_dispatch/http/url.rb +10 -18
- data/lib/action_dispatch/journey/formatter.rb +3 -3
- data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -5
- data/lib/action_dispatch/journey/parser.rb +1 -1
- data/lib/action_dispatch/journey/parser.y +1 -0
- data/lib/action_dispatch/journey/router.rb +7 -1
- data/lib/action_dispatch/journey/router/utils.rb +1 -1
- data/lib/action_dispatch/journey/visitors.rb +26 -47
- data/lib/action_dispatch/middleware/callbacks.rb +6 -6
- data/lib/action_dispatch/middleware/cookies.rb +15 -15
- data/lib/action_dispatch/middleware/debug_exceptions.rb +21 -13
- data/lib/action_dispatch/middleware/exception_wrapper.rb +1 -1
- data/lib/action_dispatch/middleware/flash.rb +5 -11
- data/lib/action_dispatch/middleware/params_parser.rb +1 -1
- data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +4 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +5 -2
- data/lib/action_dispatch/middleware/ssl.rb +1 -1
- data/lib/action_dispatch/middleware/static.rb +5 -25
- data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/{_trace.erb → _trace.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +15 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/{missing_template.erb → missing_template.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/{template_error.erb → template_error.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +3 -3
- data/lib/action_dispatch/railtie.rb +1 -2
- data/lib/action_dispatch/request/session.rb +12 -0
- data/lib/action_dispatch/request/utils.rb +24 -0
- data/lib/action_dispatch/routing.rb +7 -6
- data/lib/action_dispatch/routing/inspector.rb +4 -4
- data/lib/action_dispatch/routing/mapper.rb +81 -138
- data/lib/action_dispatch/routing/polymorphic_routes.rb +13 -0
- data/lib/action_dispatch/routing/redirection.rb +34 -27
- data/lib/action_dispatch/routing/route_set.rb +43 -37
- data/lib/action_dispatch/routing/url_for.rb +3 -1
- data/lib/action_dispatch/testing/assertions/response.rb +8 -15
- data/lib/action_dispatch/testing/assertions/selector.rb +4 -4
- data/lib/action_dispatch/testing/integration.rb +1 -7
- data/lib/action_pack/version.rb +1 -1
- metadata +43 -167
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/deprecated.rb +0 -7
- data/lib/action_controller/deprecated/integration_test.rb +0 -5
- data/lib/action_controller/record_identifier.rb +0 -31
- data/lib/action_controller/vendor/html-scanner.rb +0 -5
- data/lib/action_view.rb +0 -93
- data/lib/action_view/base.rb +0 -205
- data/lib/action_view/buffers.rb +0 -49
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/dependency_tracker.rb +0 -93
- data/lib/action_view/digestor.rb +0 -113
- data/lib/action_view/flows.rb +0 -76
- data/lib/action_view/helpers.rb +0 -58
- data/lib/action_view/helpers/active_model_helper.rb +0 -49
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
- data/lib/action_view/helpers/asset_url_helper.rb +0 -355
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
- data/lib/action_view/helpers/cache_helper.rb +0 -196
- data/lib/action_view/helpers/capture_helper.rb +0 -216
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1087
- data/lib/action_view/helpers/debug_helper.rb +0 -39
- data/lib/action_view/helpers/form_helper.rb +0 -1882
- data/lib/action_view/helpers/form_options_helper.rb +0 -838
- data/lib/action_view/helpers/form_tag_helper.rb +0 -785
- data/lib/action_view/helpers/javascript_helper.rb +0 -117
- data/lib/action_view/helpers/number_helper.rb +0 -451
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -106
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -256
- data/lib/action_view/helpers/tag_helper.rb +0 -173
- data/lib/action_view/helpers/tags.rb +0 -39
- data/lib/action_view/helpers/tags/base.rb +0 -148
- data/lib/action_view/helpers/tags/check_box.rb +0 -64
- data/lib/action_view/helpers/tags/checkable.rb +0 -16
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -53
- data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
- data/lib/action_view/helpers/tags/collection_select.rb +0 -28
- data/lib/action_view/helpers/tags/color_field.rb +0 -25
- data/lib/action_view/helpers/tags/date_field.rb +0 -13
- data/lib/action_view/helpers/tags/date_select.rb +0 -72
- data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
- data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
- data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
- data/lib/action_view/helpers/tags/email_field.rb +0 -8
- data/lib/action_view/helpers/tags/file_field.rb +0 -8
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
- data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
- data/lib/action_view/helpers/tags/label.rb +0 -65
- data/lib/action_view/helpers/tags/month_field.rb +0 -13
- data/lib/action_view/helpers/tags/number_field.rb +0 -18
- data/lib/action_view/helpers/tags/password_field.rb +0 -12
- data/lib/action_view/helpers/tags/radio_button.rb +0 -31
- data/lib/action_view/helpers/tags/range_field.rb +0 -8
- data/lib/action_view/helpers/tags/search_field.rb +0 -22
- data/lib/action_view/helpers/tags/select.rb +0 -40
- data/lib/action_view/helpers/tags/tel_field.rb +0 -8
- data/lib/action_view/helpers/tags/text_area.rb +0 -18
- data/lib/action_view/helpers/tags/text_field.rb +0 -30
- data/lib/action_view/helpers/tags/time_field.rb +0 -13
- data/lib/action_view/helpers/tags/time_select.rb +0 -8
- data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
- data/lib/action_view/helpers/tags/url_field.rb +0 -8
- data/lib/action_view/helpers/tags/week_field.rb +0 -13
- data/lib/action_view/helpers/text_helper.rb +0 -448
- data/lib/action_view/helpers/translation_helper.rb +0 -112
- data/lib/action_view/helpers/url_helper.rb +0 -635
- data/lib/action_view/locale/en.yml +0 -56
- data/lib/action_view/log_subscriber.rb +0 -30
- data/lib/action_view/lookup_context.rb +0 -248
- data/lib/action_view/model_naming.rb +0 -12
- data/lib/action_view/path_set.rb +0 -77
- data/lib/action_view/railtie.rb +0 -43
- data/lib/action_view/record_identifier.rb +0 -84
- data/lib/action_view/renderer/abstract_renderer.rb +0 -47
- data/lib/action_view/renderer/partial_renderer.rb +0 -500
- data/lib/action_view/renderer/renderer.rb +0 -50
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
- data/lib/action_view/renderer/template_renderer.rb +0 -96
- data/lib/action_view/routing_url_for.rb +0 -107
- data/lib/action_view/tasks/dependencies.rake +0 -17
- data/lib/action_view/template.rb +0 -339
- data/lib/action_view/template/error.rb +0 -138
- data/lib/action_view/template/handlers.rb +0 -53
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -146
- data/lib/action_view/template/handlers/raw.rb +0 -11
- data/lib/action_view/template/resolver.rb +0 -340
- data/lib/action_view/template/text.rb +0 -34
- data/lib/action_view/template/types.rb +0 -57
- data/lib/action_view/test_case.rb +0 -270
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view/vendor/html-scanner.rb +0 -20
- data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
- data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
@@ -1,196 +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
|
-
# The best way to use this is by doing key-based cache expiration
|
12
|
-
# on top of a cache store like Memcached that'll automatically
|
13
|
-
# kick out old entries. For more on key-based expiration, see:
|
14
|
-
# http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works
|
15
|
-
#
|
16
|
-
# When using this method, you list the cache dependency as the name of the cache, like so:
|
17
|
-
#
|
18
|
-
# <% cache project do %>
|
19
|
-
# <b>All the topics on this project</b>
|
20
|
-
# <%= render project.topics %>
|
21
|
-
# <% end %>
|
22
|
-
#
|
23
|
-
# This approach will assume that when a new topic is added, you'll touch
|
24
|
-
# the project. The cache key generated from this call will be something like:
|
25
|
-
#
|
26
|
-
# views/projects/123-20120806214154/7a1156131a6928cb0026877f8b749ac9
|
27
|
-
# ^class ^id ^updated_at ^template tree digest
|
28
|
-
#
|
29
|
-
# The cache is thus automatically bumped whenever the project updated_at is touched.
|
30
|
-
#
|
31
|
-
# If your template cache depends on multiple sources (try to avoid this to keep things simple),
|
32
|
-
# you can name all these dependencies as part of an array:
|
33
|
-
#
|
34
|
-
# <% cache [ project, current_user ] do %>
|
35
|
-
# <b>All the topics on this project</b>
|
36
|
-
# <%= render project.topics %>
|
37
|
-
# <% end %>
|
38
|
-
#
|
39
|
-
# This will include both records as part of the cache key and updating either of them will
|
40
|
-
# expire the cache.
|
41
|
-
#
|
42
|
-
# ==== Template digest
|
43
|
-
#
|
44
|
-
# The template digest that's added to the cache key is computed by taking an md5 of the
|
45
|
-
# contents of the entire template file. This ensures that your caches will automatically
|
46
|
-
# expire when you change the template file.
|
47
|
-
#
|
48
|
-
# Note that the md5 is taken of the entire template file, not just what's within the
|
49
|
-
# cache do/end call. So it's possible that changing something outside of that call will
|
50
|
-
# still expire the cache.
|
51
|
-
#
|
52
|
-
# Additionally, the digestor will automatically look through your template file for
|
53
|
-
# explicit and implicit dependencies, and include those as part of the digest.
|
54
|
-
#
|
55
|
-
# The digestor can be bypassed by passing skip_digest: true as an option to the cache call:
|
56
|
-
#
|
57
|
-
# <% cache project, skip_digest: true do %>
|
58
|
-
# <b>All the topics on this project</b>
|
59
|
-
# <%= render project.topics %>
|
60
|
-
# <% end %>
|
61
|
-
#
|
62
|
-
# ==== Implicit dependencies
|
63
|
-
#
|
64
|
-
# Most template dependencies can be derived from calls to render in the template itself.
|
65
|
-
# Here are some examples of render calls that Cache Digests knows how to decode:
|
66
|
-
#
|
67
|
-
# render partial: "comments/comment", collection: commentable.comments
|
68
|
-
# render "comments/comments"
|
69
|
-
# render 'comments/comments'
|
70
|
-
# render('comments/comments')
|
71
|
-
#
|
72
|
-
# render "header" => render("comments/header")
|
73
|
-
#
|
74
|
-
# render(@topic) => render("topics/topic")
|
75
|
-
# render(topics) => render("topics/topic")
|
76
|
-
# render(message.topics) => render("topics/topic")
|
77
|
-
#
|
78
|
-
# It's not possible to derive all render calls like that, though. Here are a few examples of things that can't be derived:
|
79
|
-
#
|
80
|
-
# render group_of_attachments
|
81
|
-
# render @project.documents.where(published: true).order('created_at')
|
82
|
-
#
|
83
|
-
# You will have to rewrite those to the explicit form:
|
84
|
-
#
|
85
|
-
# render partial: 'attachments/attachment', collection: group_of_attachments
|
86
|
-
# render partial: 'documents/document', collection: @project.documents.where(published: true).order('created_at')
|
87
|
-
#
|
88
|
-
# === Explicit dependencies
|
89
|
-
#
|
90
|
-
# Some times you'll have template dependencies that can't be derived at all. This is typically
|
91
|
-
# the case when you have template rendering that happens in helpers. Here's an example:
|
92
|
-
#
|
93
|
-
# <%= render_sortable_todolists @project.todolists %>
|
94
|
-
#
|
95
|
-
# You'll need to use a special comment format to call those out:
|
96
|
-
#
|
97
|
-
# <%# Template Dependency: todolists/todolist %>
|
98
|
-
# <%= render_sortable_todolists @project.todolists %>
|
99
|
-
#
|
100
|
-
# The pattern used to match these is /# Template Dependency: ([^ ]+)/, so it's important that you type it out just so.
|
101
|
-
# You can only declare one template dependency per line.
|
102
|
-
#
|
103
|
-
# === External dependencies
|
104
|
-
#
|
105
|
-
# If you use a helper method, for example, inside of a cached block and you then update that helper,
|
106
|
-
# you'll have to bump the cache as well. It doesn't really matter how you do it, but the md5 of the template file
|
107
|
-
# must change. One recommendation is to simply be explicit in a comment, like:
|
108
|
-
#
|
109
|
-
# <%# Helper Dependency Updated: May 6, 2012 at 6pm %>
|
110
|
-
# <%= some_helper_method(person) %>
|
111
|
-
#
|
112
|
-
# Now all you'll have to do is change that timestamp when the helper method changes.
|
113
|
-
def cache(name = {}, options = nil, &block)
|
114
|
-
if controller.perform_caching
|
115
|
-
safe_concat(fragment_for(cache_fragment_name(name, options), options, &block))
|
116
|
-
else
|
117
|
-
yield
|
118
|
-
end
|
119
|
-
|
120
|
-
nil
|
121
|
-
end
|
122
|
-
|
123
|
-
# Cache fragments of a view if +condition+ is true
|
124
|
-
#
|
125
|
-
# <%= cache_if admin?, project do %>
|
126
|
-
# <b>All the topics on this project</b>
|
127
|
-
# <%= render project.topics %>
|
128
|
-
# <% end %>
|
129
|
-
def cache_if(condition, name = {}, options = nil, &block)
|
130
|
-
if condition
|
131
|
-
cache(name, options, &block)
|
132
|
-
else
|
133
|
-
yield
|
134
|
-
end
|
135
|
-
|
136
|
-
nil
|
137
|
-
end
|
138
|
-
|
139
|
-
# Cache fragments of a view unless +condition+ is true
|
140
|
-
#
|
141
|
-
# <%= cache_unless admin?, project do %>
|
142
|
-
# <b>All the topics on this project</b>
|
143
|
-
# <%= render project.topics %>
|
144
|
-
# <% end %>
|
145
|
-
def cache_unless(condition, name = {}, options = nil, &block)
|
146
|
-
cache_if !condition, name, options, &block
|
147
|
-
end
|
148
|
-
|
149
|
-
# This helper returns the name of a cache key for a given fragment cache
|
150
|
-
# call. By supplying skip_digest: true to cache, the digestion of cache
|
151
|
-
# fragments can be manually bypassed. This is useful when cache fragments
|
152
|
-
# cannot be manually expired unless you know the exact key which is the
|
153
|
-
# case when using memcached.
|
154
|
-
def cache_fragment_name(name = {}, options = nil)
|
155
|
-
skip_digest = options && options[:skip_digest]
|
156
|
-
|
157
|
-
if skip_digest
|
158
|
-
name
|
159
|
-
else
|
160
|
-
fragment_name_with_digest(name)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
private
|
165
|
-
|
166
|
-
def fragment_name_with_digest(name) #:nodoc:
|
167
|
-
if @virtual_path
|
168
|
-
[
|
169
|
-
*Array(name.is_a?(Hash) ? controller.url_for(name).split("://").last : name),
|
170
|
-
Digestor.digest(@virtual_path, formats.last.to_sym, lookup_context, dependencies: view_cache_dependencies)
|
171
|
-
]
|
172
|
-
else
|
173
|
-
name
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
# TODO: Create an object that has caching read/write on it
|
178
|
-
def fragment_for(name = {}, options = nil, &block) #:nodoc:
|
179
|
-
if fragment = controller.read_fragment(name, options)
|
180
|
-
fragment
|
181
|
-
else
|
182
|
-
# VIEW TODO: Make #capture usable outside of ERB
|
183
|
-
# This dance is needed because Builder can't use capture
|
184
|
-
pos = output_buffer.length
|
185
|
-
yield
|
186
|
-
output_safe = output_buffer.html_safe?
|
187
|
-
fragment = output_buffer.slice!(pos..-1)
|
188
|
-
if output_safe
|
189
|
-
self.output_buffer = output_buffer.class.new(output_buffer)
|
190
|
-
end
|
191
|
-
controller.write_fragment(name, fragment, options)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
@@ -1,216 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/string/output_safety'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
# = Action View Capture Helper
|
5
|
-
module Helpers
|
6
|
-
# CaptureHelper exposes methods to let you extract generated markup which
|
7
|
-
# can be used in other parts of a template or layout file.
|
8
|
-
#
|
9
|
-
# It provides a method to capture blocks into variables through capture and
|
10
|
-
# a way to capture a block of markup for use in a layout through content_for.
|
11
|
-
module CaptureHelper
|
12
|
-
# The capture method allows you to extract part of a template into a
|
13
|
-
# variable. You can then use this variable anywhere in your templates or layout.
|
14
|
-
#
|
15
|
-
# The capture method can be used in ERB templates...
|
16
|
-
#
|
17
|
-
# <% @greeting = capture do %>
|
18
|
-
# Welcome to my shiny new web page! The date and time is
|
19
|
-
# <%= Time.now %>
|
20
|
-
# <% end %>
|
21
|
-
#
|
22
|
-
# ...and Builder (RXML) templates.
|
23
|
-
#
|
24
|
-
# @timestamp = capture do
|
25
|
-
# "The current timestamp is #{Time.now}."
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# You can then use that variable anywhere else. For example:
|
29
|
-
#
|
30
|
-
# <html>
|
31
|
-
# <head><title><%= @greeting %></title></head>
|
32
|
-
# <body>
|
33
|
-
# <b><%= @greeting %></b>
|
34
|
-
# </body></html>
|
35
|
-
#
|
36
|
-
def capture(*args)
|
37
|
-
value = nil
|
38
|
-
buffer = with_output_buffer { value = yield(*args) }
|
39
|
-
if string = buffer.presence || value and string.is_a?(String)
|
40
|
-
ERB::Util.html_escape string
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Calling content_for stores a block of markup in an identifier for later use.
|
45
|
-
# In order to access this stored content in other templates, helper modules
|
46
|
-
# or the layout, you would pass the identifier as an argument to <tt>content_for</tt>.
|
47
|
-
#
|
48
|
-
# Note: <tt>yield</tt> can still be used to retrieve the stored content, but calling
|
49
|
-
# <tt>yield</tt> doesn't work in helper modules, while <tt>content_for</tt> does.
|
50
|
-
#
|
51
|
-
# <% content_for :not_authorized do %>
|
52
|
-
# alert('You are not authorized to do that!')
|
53
|
-
# <% end %>
|
54
|
-
#
|
55
|
-
# You can then use <tt>content_for :not_authorized</tt> anywhere in your templates.
|
56
|
-
#
|
57
|
-
# <%= content_for :not_authorized if current_user.nil? %>
|
58
|
-
#
|
59
|
-
# This is equivalent to:
|
60
|
-
#
|
61
|
-
# <%= yield :not_authorized if current_user.nil? %>
|
62
|
-
#
|
63
|
-
# <tt>content_for</tt>, however, can also be used in helper modules.
|
64
|
-
#
|
65
|
-
# module StorageHelper
|
66
|
-
# def stored_content
|
67
|
-
# content_for(:storage) || "Your storage is empty"
|
68
|
-
# end
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# This helper works just like normal helpers.
|
72
|
-
#
|
73
|
-
# <%= stored_content %>
|
74
|
-
#
|
75
|
-
# You can also use the <tt>yield</tt> syntax alongside an existing call to
|
76
|
-
# <tt>yield</tt> in a layout. For example:
|
77
|
-
#
|
78
|
-
# <%# This is the layout %>
|
79
|
-
# <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
80
|
-
# <head>
|
81
|
-
# <title>My Website</title>
|
82
|
-
# <%= yield :script %>
|
83
|
-
# </head>
|
84
|
-
# <body>
|
85
|
-
# <%= yield %>
|
86
|
-
# </body>
|
87
|
-
# </html>
|
88
|
-
#
|
89
|
-
# And now, we'll create a view that has a <tt>content_for</tt> call that
|
90
|
-
# creates the <tt>script</tt> identifier.
|
91
|
-
#
|
92
|
-
# <%# This is our view %>
|
93
|
-
# Please login!
|
94
|
-
#
|
95
|
-
# <% content_for :script do %>
|
96
|
-
# <script>alert('You are not authorized to view this page!')</script>
|
97
|
-
# <% end %>
|
98
|
-
#
|
99
|
-
# Then, in another view, you could to do something like this:
|
100
|
-
#
|
101
|
-
# <%= link_to 'Logout', action: 'logout', remote: true %>
|
102
|
-
#
|
103
|
-
# <% content_for :script do %>
|
104
|
-
# <%= javascript_include_tag :defaults %>
|
105
|
-
# <% end %>
|
106
|
-
#
|
107
|
-
# That will place +script+ tags for your default set of JavaScript files on the page;
|
108
|
-
# this technique is useful if you'll only be using these scripts in a few views.
|
109
|
-
#
|
110
|
-
# Note that content_for concatenates (default) the blocks it is given for a particular
|
111
|
-
# identifier in order. For example:
|
112
|
-
#
|
113
|
-
# <% content_for :navigation do %>
|
114
|
-
# <li><%= link_to 'Home', action: 'index' %></li>
|
115
|
-
# <% end %>
|
116
|
-
#
|
117
|
-
# And in other place:
|
118
|
-
#
|
119
|
-
# <% content_for :navigation do %>
|
120
|
-
# <li><%= link_to 'Login', action: 'login' %></li>
|
121
|
-
# <% end %>
|
122
|
-
#
|
123
|
-
# Then, in another template or layout, this code would render both links in order:
|
124
|
-
#
|
125
|
-
# <ul><%= content_for :navigation %></ul>
|
126
|
-
#
|
127
|
-
# If the flush parameter is true content_for replaces the blocks it is given. For example:
|
128
|
-
#
|
129
|
-
# <% content_for :navigation do %>
|
130
|
-
# <li><%= link_to 'Home', action: 'index' %></li>
|
131
|
-
# <% end %>
|
132
|
-
#
|
133
|
-
# <%# Add some other content, or use a different template: %>
|
134
|
-
#
|
135
|
-
# <% content_for :navigation, flush: true do %>
|
136
|
-
# <li><%= link_to 'Login', action: 'login' %></li>
|
137
|
-
# <% end %>
|
138
|
-
#
|
139
|
-
# Then, in another template or layout, this code would render only the last link:
|
140
|
-
#
|
141
|
-
# <ul><%= content_for :navigation %></ul>
|
142
|
-
#
|
143
|
-
# Lastly, simple content can be passed as a parameter:
|
144
|
-
#
|
145
|
-
# <% content_for :script, javascript_include_tag(:defaults) %>
|
146
|
-
#
|
147
|
-
# WARNING: content_for is ignored in caches. So you shouldn't use it for elements that will be fragment cached.
|
148
|
-
def content_for(name, content = nil, options = {}, &block)
|
149
|
-
if content || block_given?
|
150
|
-
if block_given?
|
151
|
-
options = content if content
|
152
|
-
content = capture(&block)
|
153
|
-
end
|
154
|
-
if content
|
155
|
-
options[:flush] ? @view_flow.set(name, content) : @view_flow.append(name, content)
|
156
|
-
end
|
157
|
-
nil
|
158
|
-
else
|
159
|
-
@view_flow.get(name).presence
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# The same as +content_for+ but when used with streaming flushes
|
164
|
-
# straight back to the layout. In other words, if you want to
|
165
|
-
# concatenate several times to the same buffer when rendering a given
|
166
|
-
# template, you should use +content_for+, if not, use +provide+ to tell
|
167
|
-
# the layout to stop looking for more contents.
|
168
|
-
def provide(name, content = nil, &block)
|
169
|
-
content = capture(&block) if block_given?
|
170
|
-
result = @view_flow.append!(name, content) if content
|
171
|
-
result unless content
|
172
|
-
end
|
173
|
-
|
174
|
-
# content_for? checks whether any content has been captured yet using `content_for`.
|
175
|
-
# Useful to render parts of your layout differently based on what is in your views.
|
176
|
-
#
|
177
|
-
# <%# This is the layout %>
|
178
|
-
# <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
179
|
-
# <head>
|
180
|
-
# <title>My Website</title>
|
181
|
-
# <%= yield :script %>
|
182
|
-
# </head>
|
183
|
-
# <body class="<%= content_for?(:right_col) ? 'two-column' : 'one-column' %>">
|
184
|
-
# <%= yield %>
|
185
|
-
# <%= yield :right_col %>
|
186
|
-
# </body>
|
187
|
-
# </html>
|
188
|
-
def content_for?(name)
|
189
|
-
@view_flow.get(name).present?
|
190
|
-
end
|
191
|
-
|
192
|
-
# Use an alternate output buffer for the duration of the block.
|
193
|
-
# Defaults to a new empty string.
|
194
|
-
def with_output_buffer(buf = nil) #:nodoc:
|
195
|
-
unless buf
|
196
|
-
buf = ActionView::OutputBuffer.new
|
197
|
-
buf.force_encoding(output_buffer.encoding) if output_buffer
|
198
|
-
end
|
199
|
-
self.output_buffer, old_buffer = buf, output_buffer
|
200
|
-
yield
|
201
|
-
output_buffer
|
202
|
-
ensure
|
203
|
-
self.output_buffer = old_buffer
|
204
|
-
end
|
205
|
-
|
206
|
-
# Add the output buffer to the response body and start a new one.
|
207
|
-
def flush_output_buffer #:nodoc:
|
208
|
-
if output_buffer && !output_buffer.empty?
|
209
|
-
response.stream.write output_buffer
|
210
|
-
self.output_buffer = output_buffer.respond_to?(:clone_empty) ? output_buffer.clone_empty : output_buffer[0, 0]
|
211
|
-
nil
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
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
|
-
module ActionView
|
2
|
-
# = Action View CSRF Helper
|
3
|
-
module Helpers
|
4
|
-
module CsrfHelper
|
5
|
-
# Returns meta tags "csrf-param" and "csrf-token" with the name of the cross-site
|
6
|
-
# request forgery protection parameter and token, respectively.
|
7
|
-
#
|
8
|
-
# <head>
|
9
|
-
# <%= csrf_meta_tags %>
|
10
|
-
# </head>
|
11
|
-
#
|
12
|
-
# These are used to generate the dynamic forms that implement non-remote links with
|
13
|
-
# <tt>:method</tt>.
|
14
|
-
#
|
15
|
-
# You don't need to use these tags for regular forms as they generate their own hidden fields.
|
16
|
-
#
|
17
|
-
# For AJAX requests other than GETs, extract the "csrf-token" from the meta-tag and send as the
|
18
|
-
# "X-CSRF-Token" HTTP header. If you are using jQuery with jquery-rails this happens automatically.
|
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
|