actionview 5.0.7.2 → 5.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 actionview might be problematic. Click here for more details.

Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +92 -384
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/action_view.rb +5 -5
  6. data/lib/action_view/base.rb +19 -19
  7. data/lib/action_view/buffers.rb +1 -1
  8. data/lib/action_view/context.rb +1 -1
  9. data/lib/action_view/dependency_tracker.rb +4 -5
  10. data/lib/action_view/digestor.rb +6 -7
  11. data/lib/action_view/flows.rb +5 -6
  12. data/lib/action_view/gem_version.rb +3 -3
  13. data/lib/action_view/helpers.rb +1 -1
  14. data/lib/action_view/helpers/active_model_helper.rb +8 -8
  15. data/lib/action_view/helpers/asset_tag_helper.rb +62 -36
  16. data/lib/action_view/helpers/asset_url_helper.rb +111 -49
  17. data/lib/action_view/helpers/atom_feed_helper.rb +12 -13
  18. data/lib/action_view/helpers/cache_helper.rb +34 -20
  19. data/lib/action_view/helpers/capture_helper.rb +2 -2
  20. data/lib/action_view/helpers/controller_helper.rb +3 -11
  21. data/lib/action_view/helpers/csrf_helper.rb +3 -3
  22. data/lib/action_view/helpers/date_helper.rb +109 -107
  23. data/lib/action_view/helpers/debug_helper.rb +2 -3
  24. data/lib/action_view/helpers/form_helper.rb +406 -31
  25. data/lib/action_view/helpers/form_options_helper.rb +12 -12
  26. data/lib/action_view/helpers/form_tag_helper.rb +19 -18
  27. data/lib/action_view/helpers/javascript_helper.rb +6 -6
  28. data/lib/action_view/helpers/number_helper.rb +48 -46
  29. data/lib/action_view/helpers/output_safety_helper.rb +8 -8
  30. data/lib/action_view/helpers/rendering_helper.rb +2 -2
  31. data/lib/action_view/helpers/sanitize_helper.rb +6 -8
  32. data/lib/action_view/helpers/tag_helper.rb +194 -77
  33. data/lib/action_view/helpers/tags/base.rb +121 -102
  34. data/lib/action_view/helpers/tags/check_box.rb +17 -17
  35. data/lib/action_view/helpers/tags/collection_check_boxes.rb +8 -8
  36. data/lib/action_view/helpers/tags/collection_helpers.rb +60 -60
  37. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +2 -2
  38. data/lib/action_view/helpers/tags/collection_select.rb +2 -2
  39. data/lib/action_view/helpers/tags/date_select.rb +36 -36
  40. data/lib/action_view/helpers/tags/grouped_collection_select.rb +2 -2
  41. data/lib/action_view/helpers/tags/label.rb +4 -0
  42. data/lib/action_view/helpers/tags/password_field.rb +1 -1
  43. data/lib/action_view/helpers/tags/radio_button.rb +4 -4
  44. data/lib/action_view/helpers/tags/select.rb +9 -9
  45. data/lib/action_view/helpers/tags/text_area.rb +1 -1
  46. data/lib/action_view/helpers/tags/text_field.rb +5 -5
  47. data/lib/action_view/helpers/tags/translator.rb +14 -12
  48. data/lib/action_view/helpers/text_helper.rb +20 -19
  49. data/lib/action_view/helpers/translation_helper.rb +6 -6
  50. data/lib/action_view/helpers/url_helper.rb +42 -38
  51. data/lib/action_view/layouts.rb +51 -47
  52. data/lib/action_view/log_subscriber.rb +24 -9
  53. data/lib/action_view/lookup_context.rb +19 -25
  54. data/lib/action_view/path_set.rb +19 -19
  55. data/lib/action_view/railtie.rb +3 -3
  56. data/lib/action_view/record_identifier.rb +6 -6
  57. data/lib/action_view/renderer/abstract_renderer.rb +17 -17
  58. data/lib/action_view/renderer/partial_renderer.rb +188 -187
  59. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +7 -1
  60. data/lib/action_view/renderer/streaming_template_renderer.rb +45 -47
  61. data/lib/action_view/renderer/template_renderer.rb +64 -66
  62. data/lib/action_view/rendering.rb +4 -5
  63. data/lib/action_view/routing_url_for.rb +9 -13
  64. data/lib/action_view/tasks/cache_digests.rake +7 -7
  65. data/lib/action_view/template.rb +26 -27
  66. data/lib/action_view/template/error.rb +5 -15
  67. data/lib/action_view/template/handlers.rb +4 -4
  68. data/lib/action_view/template/handlers/builder.rb +7 -7
  69. data/lib/action_view/template/handlers/erb.rb +9 -76
  70. data/lib/action_view/template/handlers/erb/deprecated_erubis.rb +9 -0
  71. data/lib/action_view/template/handlers/erb/erubi.rb +81 -0
  72. data/lib/action_view/template/handlers/erb/erubis.rb +81 -0
  73. data/lib/action_view/template/html.rb +2 -4
  74. data/lib/action_view/template/resolver.rb +107 -90
  75. data/lib/action_view/template/text.rb +5 -8
  76. data/lib/action_view/template/types.rb +1 -1
  77. data/lib/action_view/test_case.rb +20 -21
  78. data/lib/action_view/testing/resolvers.rb +29 -30
  79. data/lib/action_view/version.rb +1 -1
  80. data/lib/action_view/view_paths.rb +20 -8
  81. data/lib/assets/compiled/rails-ujs.js +648 -0
  82. metadata +19 -14
@@ -1,4 +1,4 @@
1
- require 'action_view/helpers/tags/collection_helpers'
1
+ require "action_view/helpers/tags/collection_helpers"
2
2
 
3
3
  module ActionView
4
4
  module Helpers
@@ -7,7 +7,7 @@ module ActionView
7
7
  include CollectionHelpers
8
8
 
9
9
  class RadioButtonBuilder < Builder # :nodoc:
10
- def radio_button(extra_html_options={})
10
+ def radio_button(extra_html_options = {})
11
11
  html_options = extra_html_options.merge(@input_html_options)
12
12
  @template_object.radio_button(@object_name, @method_name, @value, html_options)
13
13
  end
@@ -13,8 +13,8 @@ module ActionView
13
13
 
14
14
  def render
15
15
  option_tags_options = {
16
- :selected => @options.fetch(:selected) { value(@object) },
17
- :disabled => @options[:disabled]
16
+ selected: @options.fetch(:selected) { value(@object) },
17
+ disabled: @options[:disabled]
18
18
  }
19
19
 
20
20
  select_content_tag(
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/time/calculations'
1
+ require "active_support/core_ext/time/calculations"
2
2
 
3
3
  module ActionView
4
4
  module Helpers
@@ -16,56 +16,56 @@ module ActionView
16
16
 
17
17
  class << self
18
18
  def select_type
19
- @select_type ||= self.name.split("::").last.sub("Select", "").downcase
19
+ @select_type ||= name.split("::").last.sub("Select", "").downcase
20
20
  end
21
21
  end
22
22
 
23
23
  private
24
24
 
25
- def select_type
26
- self.class.select_type
27
- end
25
+ def select_type
26
+ self.class.select_type
27
+ end
28
28
 
29
- def datetime_selector(options, html_options)
30
- datetime = options.fetch(:selected) { value(object) || default_datetime(options) }
31
- @auto_index ||= nil
29
+ def datetime_selector(options, html_options)
30
+ datetime = options.fetch(:selected) { value(object) || default_datetime(options) }
31
+ @auto_index ||= nil
32
32
 
33
- options = options.dup
34
- options[:field_name] = @method_name
35
- options[:include_position] = true
36
- options[:prefix] ||= @object_name
37
- options[:index] = @auto_index if @auto_index && !options.has_key?(:index)
33
+ options = options.dup
34
+ options[:field_name] = @method_name
35
+ options[:include_position] = true
36
+ options[:prefix] ||= @object_name
37
+ options[:index] = @auto_index if @auto_index && !options.has_key?(:index)
38
38
 
39
- DateTimeSelector.new(datetime, options, html_options)
40
- end
39
+ DateTimeSelector.new(datetime, options, html_options)
40
+ end
41
41
 
42
- def default_datetime(options)
43
- return if options[:include_blank] || options[:prompt]
42
+ def default_datetime(options)
43
+ return if options[:include_blank] || options[:prompt]
44
44
 
45
- case options[:default]
46
- when nil
47
- Time.current
48
- when Date, Time
49
- options[:default]
50
- else
51
- default = options[:default].dup
45
+ case options[:default]
46
+ when nil
47
+ Time.current
48
+ when Date, Time
49
+ options[:default]
50
+ else
51
+ default = options[:default].dup
52
52
 
53
- # Rename :minute and :second to :min and :sec
54
- default[:min] ||= default[:minute]
55
- default[:sec] ||= default[:second]
53
+ # Rename :minute and :second to :min and :sec
54
+ default[:min] ||= default[:minute]
55
+ default[:sec] ||= default[:second]
56
56
 
57
- time = Time.current
57
+ time = Time.current
58
58
 
59
- [:year, :month, :day, :hour, :min, :sec].each do |key|
60
- default[key] ||= time.send(key)
61
- end
59
+ [:year, :month, :day, :hour, :min, :sec].each do |key|
60
+ default[key] ||= time.send(key)
61
+ end
62
62
 
63
- Time.utc(
64
- default[:year], default[:month], default[:day],
65
- default[:hour], default[:min], default[:sec]
66
- )
63
+ Time.utc(
64
+ default[:year], default[:month], default[:day],
65
+ default[:hour], default[:min], default[:sec]
66
+ )
67
+ end
67
68
  end
68
- end
69
69
  end
70
70
  end
71
71
  end
@@ -15,8 +15,8 @@ module ActionView
15
15
 
16
16
  def render
17
17
  option_tags_options = {
18
- :selected => @options.fetch(:selected) { value(@object) },
19
- :disabled => @options[:disabled]
18
+ selected: @options.fetch(:selected) { value(@object) },
19
+ disabled: @options[:disabled]
20
20
  }
21
21
 
22
22
  select_content_tag(
@@ -73,6 +73,10 @@ module ActionView
73
73
  def render_component(builder)
74
74
  builder.translation
75
75
  end
76
+
77
+ def skip_default_ids?
78
+ false # The id is used as the `for` attribute.
79
+ end
76
80
  end
77
81
  end
78
82
  end
@@ -3,7 +3,7 @@ module ActionView
3
3
  module Tags # :nodoc:
4
4
  class PasswordField < TextField # :nodoc:
5
5
  def render
6
- @options = {:value => nil}.merge!(@options)
6
+ @options = { value: nil }.merge!(@options)
7
7
  super
8
8
  end
9
9
  end
@@ -1,4 +1,4 @@
1
- require 'action_view/helpers/tags/checkable'
1
+ require "action_view/helpers/tags/checkable"
2
2
 
3
3
  module ActionView
4
4
  module Helpers
@@ -22,9 +22,9 @@ module ActionView
22
22
 
23
23
  private
24
24
 
25
- def checked?(value)
26
- value.to_s == @tag_value.to_s
27
- end
25
+ def checked?(value)
26
+ value.to_s == @tag_value.to_s
27
+ end
28
28
  end
29
29
  end
30
30
  end
@@ -13,8 +13,8 @@ module ActionView
13
13
 
14
14
  def render
15
15
  option_tags_options = {
16
- :selected => @options.fetch(:selected) { value(@object) },
17
- :disabled => @options[:disabled]
16
+ selected: @options.fetch(:selected) { value(@object) },
17
+ disabled: @options[:disabled]
18
18
  }
19
19
 
20
20
  option_tags = if grouped_choices?
@@ -28,13 +28,13 @@ module ActionView
28
28
 
29
29
  private
30
30
 
31
- # Grouped choices look like this:
32
- #
33
- # [nil, []]
34
- # { nil => [] }
35
- def grouped_choices?
36
- !@choices.empty? && @choices.first.respond_to?(:last) && Array === @choices.first.last
37
- end
31
+ # Grouped choices look like this:
32
+ #
33
+ # [nil, []]
34
+ # { nil => [] }
35
+ def grouped_choices?
36
+ !@choices.empty? && @choices.first.respond_to?(:last) && Array === @choices.first.last
37
+ end
38
38
  end
39
39
  end
40
40
  end
@@ -1,4 +1,4 @@
1
- require 'action_view/helpers/tags/placeholderable'
1
+ require "action_view/helpers/tags/placeholderable"
2
2
 
3
3
  module ActionView
4
4
  module Helpers
@@ -1,4 +1,4 @@
1
- require 'action_view/helpers/tags/placeholderable'
1
+ require "action_view/helpers/tags/placeholderable"
2
2
 
3
3
  module ActionView
4
4
  module Helpers
@@ -17,15 +17,15 @@ module ActionView
17
17
 
18
18
  class << self
19
19
  def field_type
20
- @field_type ||= self.name.split("::").last.sub("Field", "").downcase
20
+ @field_type ||= name.split("::").last.sub("Field", "").downcase
21
21
  end
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def field_type
27
- self.class.field_type
28
- end
26
+ def field_type
27
+ self.class.field_type
28
+ end
29
29
  end
30
30
  end
31
31
  end
@@ -14,26 +14,28 @@ module ActionView
14
14
  translated_attribute || human_attribute_name
15
15
  end
16
16
 
17
+ # TODO Change this to private once we've dropped Ruby 2.2 support.
18
+ # Workaround for Ruby 2.2 "private attribute?" warning.
17
19
  protected
18
20
 
19
- attr_reader :object_name, :method_and_value, :scope, :model
21
+ attr_reader :object_name, :method_and_value, :scope, :model
20
22
 
21
23
  private
22
24
 
23
- def i18n_default
24
- if model
25
- key = model.model_name.i18n_key
26
- ["#{key}.#{method_and_value}".to_sym, ""]
27
- else
28
- ""
25
+ def i18n_default
26
+ if model
27
+ key = model.model_name.i18n_key
28
+ ["#{key}.#{method_and_value}".to_sym, ""]
29
+ else
30
+ ""
31
+ end
29
32
  end
30
- end
31
33
 
32
- def human_attribute_name
33
- if model && model.class.respond_to?(:human_attribute_name)
34
- model.class.human_attribute_name(method_and_value)
34
+ def human_attribute_name
35
+ if model && model.class.respond_to?(:human_attribute_name)
36
+ model.class.human_attribute_name(method_and_value)
37
+ end
35
38
  end
36
- end
37
39
  end
38
40
  end
39
41
  end
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/string/filters'
2
- require 'active_support/core_ext/array/extract_options'
1
+ require "active_support/core_ext/string/filters"
2
+ require "active_support/core_ext/array/extract_options"
3
3
 
4
4
  module ActionView
5
5
  # = Action View Text Helpers
@@ -135,7 +135,7 @@ module ActionView
135
135
  else
136
136
  match = Array(phrases).map do |p|
137
137
  Regexp === p ? p.to_s : Regexp.escape(p)
138
- end.join('|')
138
+ end.join("|")
139
139
 
140
140
  if block_given?
141
141
  text.gsub(/(#{match})(?![^<]*?>)/i) { |found| yield found }
@@ -151,7 +151,7 @@ module ActionView
151
151
  # defined in <tt>:radius</tt> (which defaults to 100). If the excerpt radius overflows the beginning or end of the +text+,
152
152
  # then the <tt>:omission</tt> option (which defaults to "...") will be prepended/appended accordingly. Use the
153
153
  # <tt>:separator</tt> option to choose the delimitation. The resulting string will be stripped in any case. If the +phrase+
154
- # isn't found, nil is returned.
154
+ # isn't found, +nil+ is returned.
155
155
  #
156
156
  # excerpt('This is an example', 'an', radius: 5)
157
157
  # # => ...s is an exam...
@@ -187,7 +187,7 @@ module ActionView
187
187
  unless separator.empty?
188
188
  text.split(separator).each do |value|
189
189
  if value.match(regex)
190
- regex = phrase = value
190
+ phrase = value
191
191
  break
192
192
  end
193
193
  end
@@ -262,10 +262,11 @@ module ActionView
262
262
  end
263
263
 
264
264
  # Returns +text+ transformed into HTML using simple formatting rules.
265
- # Two or more consecutive newlines(<tt>\n\n</tt>) are considered as a
266
- # paragraph and wrapped in <tt><p></tt> tags. One newline (<tt>\n</tt>) is
267
- # considered as a linebreak and a <tt><br /></tt> tag is appended. This
268
- # method does not remove the newlines from the +text+.
265
+ # Two or more consecutive newlines(<tt>\n\n</tt> or <tt>\r\n\r\n</tt>) are
266
+ # considered a paragraph and wrapped in <tt><p></tt> tags. One newline
267
+ # (<tt>\n</tt> or <tt>\r\n</tt>) is considered a linebreak and a
268
+ # <tt><br /></tt> tag is appended. This method does not remove the
269
+ # newlines from the +text+.
269
270
  #
270
271
  # You can pass any HTML attributes into <tt>html_options</tt>. These
271
272
  # will be added to all created paragraphs.
@@ -350,7 +351,7 @@ module ActionView
350
351
  # <% end %>
351
352
  def cycle(first_value, *values)
352
353
  options = values.extract_options!
353
- name = options.fetch(:name, 'default')
354
+ name = options.fetch(:name, "default")
354
355
 
355
356
  values.unshift(*first_value)
356
357
 
@@ -424,17 +425,17 @@ module ActionView
424
425
 
425
426
  private
426
427
 
427
- def next_index
428
- step_index(1)
429
- end
428
+ def next_index
429
+ step_index(1)
430
+ end
430
431
 
431
- def previous_index
432
- step_index(-1)
433
- end
432
+ def previous_index
433
+ step_index(-1)
434
+ end
434
435
 
435
- def step_index(n)
436
- (@index + n) % @values.size
437
- end
436
+ def step_index(n)
437
+ (@index + n) % @values.size
438
+ end
438
439
  end
439
440
 
440
441
  private
@@ -1,6 +1,6 @@
1
- require 'action_view/helpers/tag_helper'
2
- require 'active_support/core_ext/string/access'
3
- require 'i18n/exceptions'
1
+ require "action_view/helpers/tag_helper"
2
+ require "active_support/core_ext/string/access"
3
+ require "i18n/exceptions"
4
4
 
5
5
  module ActionView
6
6
  # = Action View Translation Helpers
@@ -100,12 +100,12 @@ module ActionView
100
100
 
101
101
  interpolations = options.except(:default, :scope)
102
102
  if interpolations.any?
103
- title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(', ')
103
+ title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(", ")
104
104
  end
105
105
 
106
106
  return title unless ActionView::Base.debug_missing_translation
107
107
 
108
- content_tag('span', keys.last.to_s.titleize, class: 'translation_missing', title: title)
108
+ content_tag("span", keys.last.to_s.titleize, class: "translation_missing", title: title)
109
109
  end
110
110
  end
111
111
  alias :t :translate
@@ -133,7 +133,7 @@ module ActionView
133
133
  end
134
134
 
135
135
  def html_safe_translation_key?(key)
136
- key.to_s =~ /(\b|_|\.)html$/
136
+ /(\b|_|\.)html$/.match?(key.to_s)
137
137
  end
138
138
  end
139
139
  end
@@ -1,7 +1,7 @@
1
- require 'action_view/helpers/javascript_helper'
2
- require 'active_support/core_ext/array/access'
3
- require 'active_support/core_ext/hash/keys'
4
- require 'active_support/core_ext/string/output_safety'
1
+ require "action_view/helpers/javascript_helper"
2
+ require "active_support/core_ext/array/access"
3
+ require "active_support/core_ext/hash/keys"
4
+ require "active_support/core_ext/string/output_safety"
5
5
 
6
6
  module ActionView
7
7
  # = Action View URL Helpers
@@ -35,20 +35,20 @@ module ActionView
35
35
  when :back
36
36
  _back_url
37
37
  else
38
- raise ArgumentError, "arguments passed to url_for can't be handled. Please require " +
38
+ raise ArgumentError, "arguments passed to url_for can't be handled. Please require " \
39
39
  "routes or provide your own implementation"
40
40
  end
41
41
  end
42
42
 
43
43
  def _back_url # :nodoc:
44
- _filtered_referrer || 'javascript:history.back()'
44
+ _filtered_referrer || "javascript:history.back()"
45
45
  end
46
46
  protected :_back_url
47
47
 
48
48
  def _filtered_referrer # :nodoc:
49
49
  if controller.respond_to?(:request)
50
50
  referrer = controller.request.env["HTTP_REFERER"]
51
- if referrer && URI(referrer).scheme != 'javascript'
51
+ if referrer && URI(referrer).scheme != "javascript"
52
52
  referrer
53
53
  end
54
54
  end
@@ -105,10 +105,9 @@ module ActionView
105
105
  # driver to prompt with the question specified (in this case, the
106
106
  # resulting text would be <tt>question?</tt>. If the user accepts, the
107
107
  # link is processed normally, otherwise no action is taken.
108
- # * <tt>:disable_with</tt> - Value of this parameter will be
109
- # used as the value for a disabled version of the submit
110
- # button when the form is submitted. This feature is provided
111
- # by the unobtrusive JavaScript driver.
108
+ # * <tt>:disable_with</tt> - Value of this parameter will be used as the
109
+ # name for a disabled version of the link. This feature is provided by
110
+ # the unobtrusive JavaScript driver.
112
111
  #
113
112
  # ==== Examples
114
113
  # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
@@ -298,34 +297,34 @@ module ActionView
298
297
  html_options = html_options.stringify_keys
299
298
 
300
299
  url = options.is_a?(String) ? options : url_for(options)
301
- remote = html_options.delete('remote')
302
- params = html_options.delete('params')
300
+ remote = html_options.delete("remote")
301
+ params = html_options.delete("params")
303
302
 
304
- method = html_options.delete('method').to_s
305
- method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : ''.freeze.html_safe
303
+ method = html_options.delete("method").to_s
304
+ method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : "".freeze.html_safe
306
305
 
307
- form_method = method == 'get' ? 'get' : 'post'
308
- form_options = html_options.delete('form') || {}
309
- form_options[:class] ||= html_options.delete('form_class') || 'button_to'
306
+ form_method = method == "get" ? "get" : "post"
307
+ form_options = html_options.delete("form") || {}
308
+ form_options[:class] ||= html_options.delete("form_class") || "button_to"
310
309
  form_options[:method] = form_method
311
310
  form_options[:action] = url
312
311
  form_options[:'data-remote'] = true if remote
313
312
 
314
- request_token_tag = if form_method == 'post'
315
- request_method = method.empty? ? 'post' : method
313
+ request_token_tag = if form_method == "post"
314
+ request_method = method.empty? ? "post" : method
316
315
  token_tag(nil, form_options: { action: url, method: request_method })
317
316
  else
318
- ''.freeze
317
+ "".freeze
319
318
  end
320
319
 
321
320
  html_options = convert_options_to_data_attributes(options, html_options)
322
- html_options['type'] = 'submit'
321
+ html_options["type"] = "submit"
323
322
 
324
323
  button = if block_given?
325
- content_tag('button', html_options, &block)
324
+ content_tag("button", html_options, &block)
326
325
  else
327
- html_options['value'] = name || url
328
- tag('input', html_options)
326
+ html_options["value"] = name || url
327
+ tag("input", html_options)
329
328
  end
330
329
 
331
330
  inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag)
@@ -334,7 +333,7 @@ module ActionView
334
333
  inner_tags.safe_concat tag(:input, type: "hidden", name: param[:name], value: param[:value])
335
334
  end
336
335
  end
337
- content_tag('form', inner_tags, form_options)
336
+ content_tag("form", inner_tags, form_options)
338
337
  end
339
338
 
340
339
  # Creates a link tag of the given +name+ using a URL created by the set of
@@ -481,7 +480,7 @@ module ActionView
481
480
  option = html_options.delete(item).presence || next
482
481
  "#{item.dasherize}=#{ERB::Util.url_encode(option)}"
483
482
  }.compact
484
- extras = extras.empty? ? ''.freeze : '?' + extras.join('&')
483
+ extras = extras.empty? ? "".freeze : "?" + extras.join("&")
485
484
 
486
485
  encoded_email_address = ERB::Util.url_encode(email_address).gsub("%40", "@")
487
486
  html_options["href"] = "mailto:#{encoded_email_address}#{extras}"
@@ -518,6 +517,9 @@ module ActionView
518
517
  # current_page?('http://www.example.com/shop/checkout')
519
518
  # # => true
520
519
  #
520
+ # current_page?('http://www.example.com/shop/checkout', check_parameters: true)
521
+ # # => false
522
+ #
521
523
  # current_page?('/shop/checkout')
522
524
  # # => true
523
525
  #
@@ -531,7 +533,7 @@ module ActionView
531
533
  #
532
534
  # We can also pass in the symbol arguments instead of strings.
533
535
  #
534
- def current_page?(options)
536
+ def current_page?(options, check_parameters: false)
535
537
  unless request
536
538
  raise "You cannot use helpers that need to determine the current " \
537
539
  "page unless your view context provides a Request object " \
@@ -540,17 +542,19 @@ module ActionView
540
542
 
541
543
  return false unless request.get? || request.head?
542
544
 
545
+ check_parameters ||= !options.is_a?(String) && options.try(:delete, :check_parameters)
543
546
  url_string = URI.parser.unescape(url_for(options)).force_encoding(Encoding::BINARY)
544
547
 
545
548
  # We ignore any extra parameters in the request_uri if the
546
549
  # submitted url doesn't have any either. This lets the function
547
550
  # work with things like ?order=asc
548
- request_uri = url_string.index("?") ? request.fullpath : request.path
551
+ # the behaviour can be disabled with check_parameters: true
552
+ request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
549
553
  request_uri = URI.parser.unescape(request_uri).force_encoding(Encoding::BINARY)
550
554
 
551
555
  url_string.chomp!("/") if url_string.start_with?("/") && url_string != "/"
552
556
 
553
- if url_string =~ /^\w+:\/\//
557
+ if %r{^\w+://}.match?(url_string)
554
558
  url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
555
559
  else
556
560
  url_string == request_uri
@@ -561,21 +565,21 @@ module ActionView
561
565
  def convert_options_to_data_attributes(options, html_options)
562
566
  if html_options
563
567
  html_options = html_options.stringify_keys
564
- html_options['data-remote'] = 'true'.freeze if link_to_remote_options?(options) || link_to_remote_options?(html_options)
568
+ html_options["data-remote"] = "true".freeze if link_to_remote_options?(options) || link_to_remote_options?(html_options)
565
569
 
566
- method = html_options.delete('method'.freeze)
570
+ method = html_options.delete("method".freeze)
567
571
 
568
572
  add_method_to_attributes!(html_options, method) if method
569
573
 
570
574
  html_options
571
575
  else
572
- link_to_remote_options?(options) ? {'data-remote' => 'true'.freeze} : {}
576
+ link_to_remote_options?(options) ? { "data-remote" => "true".freeze } : {}
573
577
  end
574
578
  end
575
579
 
576
580
  def link_to_remote_options?(options)
577
581
  if options.is_a?(Hash)
578
- options.delete('remote'.freeze) || options.delete(:remote)
582
+ options.delete("remote".freeze) || options.delete(:remote)
579
583
  end
580
584
  end
581
585
 
@@ -586,17 +590,17 @@ module ActionView
586
590
  html_options["data-method".freeze] = method
587
591
  end
588
592
 
589
- def token_tag(token=nil, form_options: {})
593
+ def token_tag(token = nil, form_options: {})
590
594
  if token != false && protect_against_forgery?
591
595
  token ||= form_authenticity_token(form_options: form_options)
592
596
  tag(:input, type: "hidden", name: request_forgery_protection_token.to_s, value: token)
593
597
  else
594
- ''.freeze
598
+ "".freeze
595
599
  end
596
600
  end
597
601
 
598
602
  def method_tag(method)
599
- tag('input', type: 'hidden', name: '_method', value: method.to_s)
603
+ tag("input", type: "hidden", name: "_method", value: method.to_s)
600
604
  end
601
605
 
602
606
  # Returns an array of hashes each containing :name and :value keys
@@ -615,7 +619,7 @@ module ActionView
615
619
  #
616
620
  # to_form_params({ name: 'Denmark' }, 'country')
617
621
  # # => [{name: 'country[name]', value: 'Denmark'}]
618
- def to_form_params(attribute, namespace = nil) # :nodoc:
622
+ def to_form_params(attribute, namespace = nil)
619
623
  attribute = if attribute.respond_to?(:permitted?)
620
624
  unless attribute.permitted?
621
625
  raise ArgumentError, "Attempting to generate a buttom from non-sanitized request parameters!" \