actionpack 3.0.0.rc → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +11 -16
- data/README.rdoc +3 -3
- data/lib/abstract_controller/base.rb +28 -14
- data/lib/abstract_controller/callbacks.rb +22 -23
- data/lib/abstract_controller/helpers.rb +24 -7
- data/lib/abstract_controller/layouts.rb +12 -10
- data/lib/abstract_controller/view_paths.rb +7 -7
- data/lib/abstract_controller.rb +1 -0
- data/lib/action_controller/base.rb +165 -2
- data/lib/action_controller/deprecated/base.rb +11 -1
- data/lib/action_controller/deprecated/url_writer.rb +14 -0
- data/lib/action_controller/metal/http_authentication.rb +3 -3
- data/lib/action_controller/metal/responder.rb +2 -8
- data/lib/action_controller/middleware.rb +1 -1
- data/lib/action_controller/test_case.rb +2 -1
- data/lib/action_controller/vendor/html-scanner/html/document.rb +2 -2
- data/lib/action_controller/vendor/html-scanner/html/node.rb +29 -29
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +25 -25
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +8 -8
- data/lib/action_controller.rb +2 -1
- data/lib/action_dispatch/http/cache.rb +2 -2
- data/lib/action_dispatch/http/mime_negotiation.rb +1 -1
- data/lib/action_dispatch/http/mime_type.rb +10 -10
- data/lib/action_dispatch/http/parameters.rb +2 -2
- data/lib/action_dispatch/http/request.rb +7 -0
- data/lib/action_dispatch/http/url.rb +12 -2
- data/lib/action_dispatch/middleware/best_standards_support.rb +22 -0
- data/lib/action_dispatch/middleware/cookies.rb +29 -10
- data/lib/action_dispatch/middleware/flash.rb +7 -2
- data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -5
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +1 -0
- data/lib/action_dispatch/middleware/show_exceptions.rb +2 -9
- data/lib/action_dispatch/middleware/stack.rb +1 -1
- data/lib/action_dispatch/railtie.rb +2 -1
- data/lib/action_dispatch/routing/deprecated_mapper.rb +1 -0
- data/lib/action_dispatch/routing/mapper.rb +120 -137
- data/lib/action_dispatch/routing/polymorphic_routes.rb +10 -10
- data/lib/action_dispatch/routing/route_set.rb +8 -5
- data/lib/action_dispatch/routing/url_for.rb +1 -1
- data/lib/action_dispatch/routing.rb +4 -4
- data/lib/action_dispatch/testing/assertions/dom.rb +1 -1
- data/lib/action_dispatch/testing/assertions/response.rb +5 -5
- data/lib/action_dispatch/testing/assertions/routing.rb +39 -16
- data/lib/action_dispatch/testing/integration.rb +1 -0
- data/lib/action_dispatch.rb +1 -0
- data/lib/action_pack/version.rb +1 -2
- data/lib/action_view/base.rb +1 -0
- data/lib/action_view/helpers/asset_tag_helper.rb +12 -0
- data/lib/action_view/helpers/capture_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +13 -17
- data/lib/action_view/helpers/debug_helper.rb +1 -1
- data/lib/action_view/helpers/form_helper.rb +16 -10
- data/lib/action_view/helpers/form_options_helper.rb +21 -18
- data/lib/action_view/helpers/form_tag_helper.rb +9 -9
- data/lib/action_view/helpers/number_helper.rb +1 -1
- data/lib/action_view/helpers/raw_output_helper.rb +1 -1
- data/lib/action_view/helpers/sanitize_helper.rb +4 -2
- data/lib/action_view/helpers/text_helper.rb +5 -2
- data/lib/action_view/helpers/translation_helper.rb +9 -9
- data/lib/action_view/helpers/url_helper.rb +2 -2
- data/lib/action_view/log_subscriber.rb +1 -1
- data/lib/action_view/render/layouts.rb +8 -4
- data/lib/action_view/render/partials.rb +1 -1
- data/lib/action_view/template/handler.rb +1 -1
- data/lib/action_view/template/handlers.rb +1 -1
- data/lib/action_view/template/resolver.rb +15 -0
- data/lib/action_view/template.rb +3 -3
- data/lib/action_view/test_case.rb +1 -1
- data/lib/action_view/testing/resolvers.rb +1 -1
- metadata +20 -23
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
require 'uri'
|
|
1
2
|
require 'active_support/core_ext/hash/diff'
|
|
2
3
|
require 'active_support/core_ext/hash/indifferent_access'
|
|
3
4
|
|
|
4
5
|
module ActionDispatch
|
|
5
6
|
module Assertions
|
|
6
|
-
# Suite of assertions to test routes generated by Rails and the handling of requests made to them.
|
|
7
|
+
# Suite of assertions to test routes generated by \Rails and the handling of requests made to them.
|
|
7
8
|
module RoutingAssertions
|
|
8
9
|
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
|
|
9
|
-
# match +path+. Basically, it asserts that Rails recognizes the route given by +expected_options+.
|
|
10
|
+
# match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
|
|
10
11
|
#
|
|
11
12
|
# Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
|
|
12
13
|
# requiring a specific HTTP method. The hash should contain a :path with the incoming request path
|
|
@@ -40,14 +41,7 @@ module ActionDispatch
|
|
|
40
41
|
# # Check a Simply RESTful generated route
|
|
41
42
|
# assert_recognizes list_items_url, 'items/list'
|
|
42
43
|
def assert_recognizes(expected_options, path, extras={}, message=nil)
|
|
43
|
-
|
|
44
|
-
request_method = path[:method]
|
|
45
|
-
path = path[:path]
|
|
46
|
-
else
|
|
47
|
-
request_method = nil
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
request = recognized_request_for(path, request_method)
|
|
44
|
+
request = recognized_request_for(path)
|
|
51
45
|
|
|
52
46
|
expected_options = expected_options.clone
|
|
53
47
|
extras.each_key { |key| expected_options.delete key } unless extras.nil?
|
|
@@ -77,7 +71,16 @@ module ActionDispatch
|
|
|
77
71
|
# # Asserts that the generated route gives us our custom route
|
|
78
72
|
# assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" }
|
|
79
73
|
def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
|
|
80
|
-
expected_path
|
|
74
|
+
if expected_path =~ %r{://}
|
|
75
|
+
begin
|
|
76
|
+
uri = URI.parse(expected_path)
|
|
77
|
+
expected_path = uri.path.to_s.empty? ? "/" : uri.path
|
|
78
|
+
rescue URI::InvalidURIError => e
|
|
79
|
+
raise ActionController::RoutingError, e.message
|
|
80
|
+
end
|
|
81
|
+
else
|
|
82
|
+
expected_path = "/#{expected_path}" unless expected_path.first == '/'
|
|
83
|
+
end
|
|
81
84
|
# Load routes.rb if it hasn't been loaded.
|
|
82
85
|
|
|
83
86
|
generated_path, extra_keys = @routes.generate_extras(options, defaults)
|
|
@@ -177,15 +180,35 @@ module ActionDispatch
|
|
|
177
180
|
|
|
178
181
|
private
|
|
179
182
|
# Recognizes the route for a given path.
|
|
180
|
-
def recognized_request_for(path
|
|
181
|
-
|
|
183
|
+
def recognized_request_for(path)
|
|
184
|
+
if path.is_a?(Hash)
|
|
185
|
+
method = path[:method]
|
|
186
|
+
path = path[:path]
|
|
187
|
+
else
|
|
188
|
+
method = :get
|
|
189
|
+
end
|
|
182
190
|
|
|
183
191
|
# Assume given controller
|
|
184
192
|
request = ActionController::TestRequest.new
|
|
185
|
-
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
|
|
186
|
-
request.path = path
|
|
187
193
|
|
|
188
|
-
|
|
194
|
+
if path =~ %r{://}
|
|
195
|
+
begin
|
|
196
|
+
uri = URI.parse(path)
|
|
197
|
+
request.env["rack.url_scheme"] = uri.scheme || "http"
|
|
198
|
+
request.host = uri.host if uri.host
|
|
199
|
+
request.port = uri.port if uri.port
|
|
200
|
+
request.path = uri.path.to_s.empty? ? "/" : uri.path
|
|
201
|
+
rescue URI::InvalidURIError => e
|
|
202
|
+
raise ActionController::RoutingError, e.message
|
|
203
|
+
end
|
|
204
|
+
else
|
|
205
|
+
path = "/#{path}" unless path.first == "/"
|
|
206
|
+
request.path = path
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
request.request_method = method if method
|
|
210
|
+
|
|
211
|
+
params = @routes.recognize_path(path, { :method => method })
|
|
189
212
|
request.path_parameters = params.with_indifferent_access
|
|
190
213
|
|
|
191
214
|
request
|
data/lib/action_dispatch.rb
CHANGED
data/lib/action_pack/version.rb
CHANGED
data/lib/action_view/base.rb
CHANGED
|
@@ -227,6 +227,7 @@ module ActionView #:nodoc:
|
|
|
227
227
|
@lookup_context = lookup_context.is_a?(ActionView::LookupContext) ?
|
|
228
228
|
lookup_context : ActionView::LookupContext.new(lookup_context)
|
|
229
229
|
@lookup_context.formats = formats if formats
|
|
230
|
+
@controller = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :controller)
|
|
230
231
|
end
|
|
231
232
|
|
|
232
233
|
def controller_path
|
|
@@ -393,6 +393,18 @@ module ActionView
|
|
|
393
393
|
@@stylesheet_expansions.merge!(expansions)
|
|
394
394
|
end
|
|
395
395
|
|
|
396
|
+
def self.reset_javascript_include_default
|
|
397
|
+
ActiveSupport::Deprecation.warn "reset_javascript_include_default is deprecated. Please manipulate " \
|
|
398
|
+
"config.action_view.javascript_expansions[:defaults] directly", caller
|
|
399
|
+
self.javascript_expansions[:defaults] = ['prototype', 'effects', 'dragdrop', 'controls', 'rails']
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def self.register_javascript_include_default(*args)
|
|
403
|
+
ActiveSupport::Deprecation.warn "register_javascript_include_default is deprecated. Please " \
|
|
404
|
+
"manipulate config.action_view.javascript_expansions[:defaults] directly", caller
|
|
405
|
+
self.javascript_expansions[:defaults].concat args
|
|
406
|
+
end
|
|
407
|
+
|
|
396
408
|
# Computes the path to a stylesheet asset in the public stylesheets directory.
|
|
397
409
|
# If the +source+ filename has no extension, <tt>.css</tt> will be appended (except for explicit URIs).
|
|
398
410
|
# Full paths from the document root will be passed through.
|
|
@@ -106,7 +106,7 @@ module ActionView
|
|
|
106
106
|
# <%= javascript_include_tag :defaults %>
|
|
107
107
|
# <% end %>
|
|
108
108
|
#
|
|
109
|
-
# That will place <script> tags for Prototype, Scriptaculous, and application.js (if it exists)
|
|
109
|
+
# That will place <tt>script</tt> tags for Prototype, Scriptaculous, and application.js (if it exists)
|
|
110
110
|
# on the page; this technique is useful if you'll only be using these scripts in a few views.
|
|
111
111
|
#
|
|
112
112
|
# Note that content_for concatenates the blocks it is given for a particular
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'date'
|
|
2
2
|
require 'action_view/helpers/tag_helper'
|
|
3
3
|
require 'active_support/core_ext/hash/slice'
|
|
4
|
+
require 'active_support/core_ext/object/with_options'
|
|
4
5
|
|
|
5
6
|
module ActionView
|
|
6
7
|
module Helpers
|
|
@@ -751,10 +752,8 @@ module ActionView
|
|
|
751
752
|
# => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
752
753
|
# "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
|
753
754
|
def translated_month_names
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
I18n.translate(key, :locale => @options[:locale])
|
|
757
|
-
end
|
|
755
|
+
key = @options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names'
|
|
756
|
+
I18n.translate(key, :locale => @options[:locale])
|
|
758
757
|
end
|
|
759
758
|
|
|
760
759
|
# Lookup month name for number
|
|
@@ -781,9 +780,7 @@ module ActionView
|
|
|
781
780
|
memoize :date_order
|
|
782
781
|
|
|
783
782
|
def translated_date_order
|
|
784
|
-
|
|
785
|
-
I18n.translate(:'date.order', :locale => @options[:locale]) || []
|
|
786
|
-
end
|
|
783
|
+
I18n.translate(:'date.order', :locale => @options[:locale]) || []
|
|
787
784
|
end
|
|
788
785
|
|
|
789
786
|
# Build full select tag from date type and options
|
|
@@ -837,15 +834,14 @@ module ActionView
|
|
|
837
834
|
# prompt_option_tag(:month, :prompt => 'Select month')
|
|
838
835
|
# => "<option value="">Select month</option>"
|
|
839
836
|
def prompt_option_tag(type, options)
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
prompt = I18n.translate(('datetime.prompts.' + type.to_s).to_sym, :locale => @options[:locale])
|
|
837
|
+
prompt = case options
|
|
838
|
+
when Hash
|
|
839
|
+
default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false}
|
|
840
|
+
default_options.merge!(options)[type.to_sym]
|
|
841
|
+
when String
|
|
842
|
+
options
|
|
843
|
+
else
|
|
844
|
+
I18n.translate(:"datetime.prompts.#{type}", :locale => @options[:locale])
|
|
849
845
|
end
|
|
850
846
|
|
|
851
847
|
prompt ? content_tag(:option, prompt, :value => '') : ''
|
|
@@ -215,7 +215,7 @@ module ActionView
|
|
|
215
215
|
# ...
|
|
216
216
|
# <% end %>
|
|
217
217
|
#
|
|
218
|
-
# If your resource has associations defined, for example, you want to add comments
|
|
218
|
+
# If your resource has associations defined, for example, you want to add comments
|
|
219
219
|
# to the post given that the routes are set correctly:
|
|
220
220
|
#
|
|
221
221
|
# <%= form_for([@document, @comment]) do |f| %>
|
|
@@ -583,8 +583,9 @@ module ActionView
|
|
|
583
583
|
# 'Accept <a href="/terms">Terms</a>.'
|
|
584
584
|
# end
|
|
585
585
|
def label(object_name, method, content_or_options = nil, options = nil, &block)
|
|
586
|
-
|
|
587
|
-
|
|
586
|
+
content_is_options = content_or_options.is_a?(Hash)
|
|
587
|
+
if content_is_options || block_given?
|
|
588
|
+
options = content_or_options if content_is_options
|
|
588
589
|
text = nil
|
|
589
590
|
else
|
|
590
591
|
text = content_or_options
|
|
@@ -623,16 +624,16 @@ module ActionView
|
|
|
623
624
|
#
|
|
624
625
|
# ==== Examples
|
|
625
626
|
# password_field(:login, :pass, :size => 20)
|
|
626
|
-
# # => <input type="
|
|
627
|
+
# # => <input type="password" id="login_pass" name="login[pass]" size="20" value="#{@login.pass}" />
|
|
627
628
|
#
|
|
628
629
|
# password_field(:account, :secret, :class => "form_input")
|
|
629
|
-
# # => <input type="
|
|
630
|
+
# # => <input type="password" id="account_secret" name="account[secret]" value="#{@account.secret}" class="form_input" />
|
|
630
631
|
#
|
|
631
632
|
# password_field(:user, :password, :onchange => "if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }")
|
|
632
|
-
# # => <input type="
|
|
633
|
+
# # => <input type="password" id="user_password" name="user[password]" value="#{@user.password}" onchange = "if $('user[password]').length > 30 { alert('Your password needs to be shorter!'); }"/>
|
|
633
634
|
#
|
|
634
635
|
# password_field(:account, :pin, :size => 20, :class => 'form_input')
|
|
635
|
-
# # => <input type="
|
|
636
|
+
# # => <input type="password" id="account_pin" name="account[pin]" size="20" value="#{@account.pin}" class="form_input" />
|
|
636
637
|
#
|
|
637
638
|
def password_field(object_name, method, options = {})
|
|
638
639
|
InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("password", options)
|
|
@@ -1005,9 +1006,14 @@ module ActionView
|
|
|
1005
1006
|
|
|
1006
1007
|
def value_before_type_cast(object, method_name)
|
|
1007
1008
|
unless object.nil?
|
|
1008
|
-
object.respond_to?(method_name
|
|
1009
|
-
|
|
1010
|
-
|
|
1009
|
+
if object.respond_to?(method_name)
|
|
1010
|
+
object.send(method_name)
|
|
1011
|
+
# FIXME: this is AR dependent
|
|
1012
|
+
elsif object.respond_to?(method_name + "_before_type_cast")
|
|
1013
|
+
object.send(method_name + "_before_type_cast")
|
|
1014
|
+
else
|
|
1015
|
+
raise NoMethodError, "Model #{object.class} does not respond to #{method_name}"
|
|
1016
|
+
end
|
|
1011
1017
|
end
|
|
1012
1018
|
end
|
|
1013
1019
|
|
|
@@ -53,16 +53,16 @@ module ActionView
|
|
|
53
53
|
# <option value="2">Sam</option>
|
|
54
54
|
# <option value="3">Tobias</option>
|
|
55
55
|
# </select>
|
|
56
|
-
#
|
|
57
|
-
# Like the other form helpers, +select+ can accept an <tt>:index</tt> option to manually set the ID used in the resulting output. Unlike other helpers, +select+ expects this
|
|
56
|
+
#
|
|
57
|
+
# Like the other form helpers, +select+ can accept an <tt>:index</tt> option to manually set the ID used in the resulting output. Unlike other helpers, +select+ expects this
|
|
58
58
|
# option to be in the +html_options+ parameter.
|
|
59
|
-
#
|
|
60
|
-
# Example:
|
|
61
|
-
#
|
|
59
|
+
#
|
|
60
|
+
# Example:
|
|
61
|
+
#
|
|
62
62
|
# select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
|
|
63
|
-
#
|
|
63
|
+
#
|
|
64
64
|
# becomes:
|
|
65
|
-
#
|
|
65
|
+
#
|
|
66
66
|
# <select name="album[][genre]" id="album__genre">
|
|
67
67
|
# <option value="rap">rap</option>
|
|
68
68
|
# <option value="rock">rock</option>
|
|
@@ -140,7 +140,7 @@ module ActionView
|
|
|
140
140
|
# The <tt>:value_method</tt> and <tt>:text_method</tt> parameters are methods to be called on each member
|
|
141
141
|
# of +collection+. The return values are used as the +value+ attribute and contents of each
|
|
142
142
|
# <tt><option></tt> tag, respectively.
|
|
143
|
-
#
|
|
143
|
+
#
|
|
144
144
|
# Example object structure for use with this method:
|
|
145
145
|
# class Post < ActiveRecord::Base
|
|
146
146
|
# belongs_to :author
|
|
@@ -298,17 +298,18 @@ module ActionView
|
|
|
298
298
|
return container if String === container
|
|
299
299
|
|
|
300
300
|
container = container.to_a if Hash === container
|
|
301
|
-
selected, disabled = extract_selected_and_disabled(selected)
|
|
301
|
+
selected, disabled = extract_selected_and_disabled(selected).map do | r |
|
|
302
|
+
Array.wrap(r).map(&:to_s)
|
|
303
|
+
end
|
|
302
304
|
|
|
303
|
-
|
|
305
|
+
container.map do |element|
|
|
304
306
|
html_attributes = option_html_attributes(element)
|
|
305
|
-
text, value = option_text_and_value(element)
|
|
307
|
+
text, value = option_text_and_value(element).map(&:to_s)
|
|
306
308
|
selected_attribute = ' selected="selected"' if option_value_selected?(value, selected)
|
|
307
309
|
disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled)
|
|
308
|
-
|
|
309
|
-
end
|
|
310
|
+
%(<option value="#{html_escape(value)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{html_escape(text)}</option>)
|
|
311
|
+
end.join("\n").html_safe
|
|
310
312
|
|
|
311
|
-
options_for_select.join("\n").html_safe
|
|
312
313
|
end
|
|
313
314
|
|
|
314
315
|
# Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the
|
|
@@ -493,7 +494,7 @@ module ActionView
|
|
|
493
494
|
end
|
|
494
495
|
|
|
495
496
|
zone_options += options_for_select(convert_zones[zones], selected)
|
|
496
|
-
zone_options
|
|
497
|
+
zone_options.html_safe
|
|
497
498
|
end
|
|
498
499
|
|
|
499
500
|
private
|
|
@@ -528,10 +529,12 @@ module ActionView
|
|
|
528
529
|
end
|
|
529
530
|
|
|
530
531
|
def extract_selected_and_disabled(selected)
|
|
531
|
-
if selected.is_a?(
|
|
532
|
-
[selected
|
|
532
|
+
if selected.is_a?(Proc)
|
|
533
|
+
[ selected, nil ]
|
|
533
534
|
else
|
|
534
|
-
|
|
535
|
+
selected = Array.wrap(selected)
|
|
536
|
+
options = selected.extract_options!.symbolize_keys
|
|
537
|
+
[ options[:selected] || selected , options[:disabled] ]
|
|
535
538
|
end
|
|
536
539
|
end
|
|
537
540
|
|
|
@@ -25,7 +25,7 @@ module ActionView
|
|
|
25
25
|
# If "put", "delete", or another verb is used, a hidden input with name <tt>_method</tt>
|
|
26
26
|
# is added to simulate the verb over post.
|
|
27
27
|
# * A list of parameters to feed to the URL the form will be posted to.
|
|
28
|
-
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
|
|
28
|
+
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
|
|
29
29
|
# submit behaviour. By default this behaviour is an ajax submit.
|
|
30
30
|
#
|
|
31
31
|
# ==== Examples
|
|
@@ -42,10 +42,10 @@ module ActionView
|
|
|
42
42
|
# <div><%= submit_tag 'Save' %></div>
|
|
43
43
|
# <% end -%>
|
|
44
44
|
# # => <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
|
|
45
|
-
#
|
|
45
|
+
#
|
|
46
46
|
# <%= form_tag('/posts', :remote => true) %>
|
|
47
47
|
# # => <form action="/posts" method="post" data-remote="true">
|
|
48
|
-
#
|
|
48
|
+
#
|
|
49
49
|
def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
|
|
50
50
|
html_options = html_options_for_form(url_for_options, options, *parameters_for_url)
|
|
51
51
|
if block_given?
|
|
@@ -351,12 +351,12 @@ module ActionView
|
|
|
351
351
|
# Creates a submit button with the text <tt>value</tt> as the caption.
|
|
352
352
|
#
|
|
353
353
|
# ==== Options
|
|
354
|
-
# * <tt>:confirm => 'question?'</tt> - If present the unobtrusive JavaScript
|
|
355
|
-
# drivers will provide a prompt with the question specified. If the user accepts,
|
|
354
|
+
# * <tt>:confirm => 'question?'</tt> - If present the unobtrusive JavaScript
|
|
355
|
+
# drivers will provide a prompt with the question specified. If the user accepts,
|
|
356
356
|
# the form is processed normally, otherwise no action is taken.
|
|
357
357
|
# * <tt>:disabled</tt> - If true, the user will not be able to use this input.
|
|
358
|
-
# * <tt>:disable_with</tt> - Value of this parameter will be used as the value for a
|
|
359
|
-
# disabled version of the submit button when the form is submitted. This feature is
|
|
358
|
+
# * <tt>:disable_with</tt> - Value of this parameter will be used as the value for a
|
|
359
|
+
# disabled version of the submit button when the form is submitted. This feature is
|
|
360
360
|
# provided by the unobtrusive JavaScript driver.
|
|
361
361
|
# * Any other key creates standard HTML options for the tag.
|
|
362
362
|
#
|
|
@@ -383,7 +383,7 @@ module ActionView
|
|
|
383
383
|
# # name="commit" type="submit" value="Edit" />
|
|
384
384
|
#
|
|
385
385
|
# submit_tag "Save", :confirm => "Are you sure?"
|
|
386
|
-
# # => <input name='commit' type='submit' value='Save'
|
|
386
|
+
# # => <input name='commit' type='submit' value='Save'
|
|
387
387
|
# data-confirm="Are you sure?" />
|
|
388
388
|
#
|
|
389
389
|
def submit_tag(value = "Save changes", options = {})
|
|
@@ -538,7 +538,7 @@ module ActionView
|
|
|
538
538
|
|
|
539
539
|
def extra_tags_for_form(html_options)
|
|
540
540
|
snowman_tag = tag(:input, :type => "hidden",
|
|
541
|
-
:name => "
|
|
541
|
+
:name => "utf8", :value => "✓".html_safe)
|
|
542
542
|
|
|
543
543
|
method = html_options.delete("method").to_s
|
|
544
544
|
|
|
@@ -325,7 +325,7 @@ module ActionView
|
|
|
325
325
|
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
|
|
326
326
|
human = I18n.translate(:'number.human.format', :locale => options[:locale], :default => {})
|
|
327
327
|
defaults = defaults.merge(human)
|
|
328
|
-
|
|
328
|
+
|
|
329
329
|
options = options.reverse_merge(defaults)
|
|
330
330
|
#for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
|
|
331
331
|
options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros)
|
|
@@ -2,7 +2,7 @@ module ActionView #:nodoc:
|
|
|
2
2
|
# = Action View Raw Output Helper
|
|
3
3
|
module Helpers #:nodoc:
|
|
4
4
|
module RawOutputHelper
|
|
5
|
-
# This method outputs without escaping a string. Since escaping tags is
|
|
5
|
+
# This method outputs without escaping a string. Since escaping tags is
|
|
6
6
|
# now default, this can be used when you don't want Rails to automatically
|
|
7
7
|
# escape tags. This is not recommended if the data is coming from the user's
|
|
8
8
|
# input.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'active_support/core_ext/object/try'
|
|
1
2
|
require 'action_controller/vendor/html-scanner'
|
|
2
3
|
require 'action_view/helpers/tag_helper'
|
|
3
4
|
|
|
@@ -7,7 +8,8 @@ module ActionView
|
|
|
7
8
|
# The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.
|
|
8
9
|
# These helper methods extend Action View making them callable within your template files.
|
|
9
10
|
module SanitizeHelper
|
|
10
|
-
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
# This +sanitize+ helper will html encode all tags and strip all attributes that
|
|
11
13
|
# aren't specifically allowed.
|
|
12
14
|
#
|
|
13
15
|
# It also strips href/src tags with invalid protocols, like javascript: especially.
|
|
@@ -19,7 +21,7 @@ module ActionView
|
|
|
19
21
|
#
|
|
20
22
|
# You can add or remove tags/attributes if you want to customize it a bit.
|
|
21
23
|
# See ActionView::Base for full docs on the available options. You can add
|
|
22
|
-
# tags/attributes for single uses of +sanitize+ by passing either the
|
|
24
|
+
# tags/attributes for single uses of +sanitize+ by passing either the
|
|
23
25
|
# <tt>:attributes</tt> or <tt>:tags</tt> options:
|
|
24
26
|
#
|
|
25
27
|
# Normal Use
|
|
@@ -10,6 +10,9 @@ module ActionView
|
|
|
10
10
|
# your views. These helper methods extend Action View making them callable
|
|
11
11
|
# within your template files.
|
|
12
12
|
module TextHelper
|
|
13
|
+
extend ActiveSupport::Concern
|
|
14
|
+
|
|
15
|
+
include SanitizeHelper
|
|
13
16
|
# The preferred method of outputting text in your views is to use the
|
|
14
17
|
# <%= "text" %> eRuby syntax. The regular _puts_ and _print_ methods
|
|
15
18
|
# do not operate as expected in an eRuby code block. If you absolutely must
|
|
@@ -459,7 +462,7 @@ module ActionView
|
|
|
459
462
|
text.gsub(AUTO_LINK_RE) do
|
|
460
463
|
scheme, href = $1, $&
|
|
461
464
|
punctuation = []
|
|
462
|
-
|
|
465
|
+
|
|
463
466
|
if auto_linked?($`, $')
|
|
464
467
|
# do not change string; URL is already linked
|
|
465
468
|
href
|
|
@@ -504,7 +507,7 @@ module ActionView
|
|
|
504
507
|
end
|
|
505
508
|
end
|
|
506
509
|
end
|
|
507
|
-
|
|
510
|
+
|
|
508
511
|
# Detects already linked context or position in the middle of a tag
|
|
509
512
|
def auto_linked?(left, right)
|
|
510
513
|
(left =~ AUTO_LINK_CRE[0] and right =~ AUTO_LINK_CRE[1]) or
|
|
@@ -5,21 +5,21 @@ module ActionView
|
|
|
5
5
|
module Helpers
|
|
6
6
|
module TranslationHelper
|
|
7
7
|
# Delegates to I18n#translate but also performs three additional functions.
|
|
8
|
-
# First, it'll catch MissingTranslationData exceptions and turn them into
|
|
9
|
-
# inline spans that contains the missing key, such that you can see in a
|
|
8
|
+
# First, it'll catch MissingTranslationData exceptions and turn them into
|
|
9
|
+
# inline spans that contains the missing key, such that you can see in a
|
|
10
10
|
# view what is missing where.
|
|
11
11
|
#
|
|
12
|
-
# Second, it'll scope the key by the current partial if the key starts
|
|
13
|
-
# with a period. So if you call <tt>translate(".foo")</tt> from the
|
|
14
|
-
# <tt>people/index.html.erb</tt> template, you'll actually be calling
|
|
12
|
+
# Second, it'll scope the key by the current partial if the key starts
|
|
13
|
+
# with a period. So if you call <tt>translate(".foo")</tt> from the
|
|
14
|
+
# <tt>people/index.html.erb</tt> template, you'll actually be calling
|
|
15
15
|
# <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
|
|
16
16
|
# to translate many keys within the same partials and gives you a simple framework
|
|
17
|
-
# for scoping them consistently. If you don't prepend the key with a period,
|
|
17
|
+
# for scoping them consistently. If you don't prepend the key with a period,
|
|
18
18
|
# nothing is converted.
|
|
19
19
|
#
|
|
20
|
-
# Third, it'll mark the translation as safe HTML if the key has the suffix
|
|
21
|
-
# "_html" or the last element of the key is the word "html". For example,
|
|
22
|
-
# calling translate("footer_html") or translate("footer.html") will return
|
|
20
|
+
# Third, it'll mark the translation as safe HTML if the key has the suffix
|
|
21
|
+
# "_html" or the last element of the key is the word "html". For example,
|
|
22
|
+
# calling translate("footer_html") or translate("footer.html") will return
|
|
23
23
|
# a safe HTML string that won't be escaped by other HTML helper methods. This
|
|
24
24
|
# naming convention helps to identify translations that include HTML tags so that
|
|
25
25
|
# you know what kind of output to expect when you call translate in a template.
|
|
@@ -367,8 +367,8 @@ module ActionView
|
|
|
367
367
|
# "Go Back" link instead of a link to the comments page, we could do something like this...
|
|
368
368
|
#
|
|
369
369
|
# <%=
|
|
370
|
-
# link_to_unless_current("Comment", { :controller =>
|
|
371
|
-
# link_to("Go back", { :controller =>
|
|
370
|
+
# link_to_unless_current("Comment", { :controller => "comments", :action => "new" }) do
|
|
371
|
+
# link_to("Go back", { :controller => "posts", :action => "index" })
|
|
372
372
|
# end
|
|
373
373
|
# %>
|
|
374
374
|
def link_to_unless_current(name, options = {}, html_options = {}, &block)
|
|
@@ -7,7 +7,7 @@ module ActionView
|
|
|
7
7
|
message = "Rendered #{from_rails_root(event.payload[:identifier])}"
|
|
8
8
|
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
|
9
9
|
message << (" (%.1fms)" % event.duration)
|
|
10
|
-
info(message)
|
|
10
|
+
info(message)
|
|
11
11
|
end
|
|
12
12
|
alias :render_partial :render_template
|
|
13
13
|
alias :render_collection :render_template
|
|
@@ -47,11 +47,15 @@ module ActionView
|
|
|
47
47
|
# Hello David
|
|
48
48
|
# </html>
|
|
49
49
|
#
|
|
50
|
-
def _layout_for(
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
def _layout_for(*args, &block) #:nodoc:
|
|
51
|
+
name = args.first
|
|
52
|
+
|
|
53
|
+
if name.is_a?(Symbol)
|
|
54
|
+
@_content_for[name].html_safe
|
|
55
|
+
elsif block
|
|
56
|
+
capture(*args, &block)
|
|
53
57
|
else
|
|
54
|
-
|
|
58
|
+
@_content_for[:layout].html_safe
|
|
55
59
|
end
|
|
56
60
|
end
|
|
57
61
|
|
|
@@ -56,7 +56,7 @@ module ActionView
|
|
|
56
56
|
# you're following its conventions for RecordIdentifier#partial_path. Examples:
|
|
57
57
|
#
|
|
58
58
|
# # @account is an Account instance, so it uses the RecordIdentifier to replace
|
|
59
|
-
# # <%= render :partial => "accounts/account", :locals => { :account => @
|
|
59
|
+
# # <%= render :partial => "accounts/account", :locals => { :account => @account} %>
|
|
60
60
|
# <%= render :partial => @account %>
|
|
61
61
|
#
|
|
62
62
|
# # @posts is an array of Post instances, so it uses the RecordIdentifier to replace
|
|
@@ -69,6 +69,9 @@ module ActionView
|
|
|
69
69
|
query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}'
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
query.gsub!(/\{\.html,/, "{.html,.text.html,")
|
|
73
|
+
query.gsub!(/\{\.text,/, "{.text,.text.plain,")
|
|
74
|
+
|
|
72
75
|
Dir[query].reject { |p| File.directory?(p) }.map do |p|
|
|
73
76
|
handler, format = extract_handler_and_format(p, formats)
|
|
74
77
|
|
|
@@ -87,6 +90,18 @@ module ActionView
|
|
|
87
90
|
pieces.shift
|
|
88
91
|
|
|
89
92
|
handler = Template.handler_class_for_extension(pieces.pop)
|
|
93
|
+
|
|
94
|
+
if pieces.last == "html" && pieces[-2] == "text"
|
|
95
|
+
correct_path = path.gsub(/\.text\.html/, ".html")
|
|
96
|
+
ActiveSupport::Deprecation.warn "The file `#{path}` uses the deprecated format `text.html`. Please rename it to #{correct_path}", caller
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
if pieces.last == "plain" && pieces[-2] == "text"
|
|
100
|
+
correct_path = path.gsub(/\.text\.plain/, ".text")
|
|
101
|
+
pieces.pop
|
|
102
|
+
ActiveSupport::Deprecation.warn "The file `#{path}` uses the deprecated format `text.plain`. Please rename it to #{correct_path}", caller
|
|
103
|
+
end
|
|
104
|
+
|
|
90
105
|
format = pieces.last && Mime[pieces.last] && pieces.pop.to_sym
|
|
91
106
|
format ||= handler.default_format if handler.respond_to?(:default_format)
|
|
92
107
|
format ||= default_formats
|