actionview 5.1.7 → 5.2.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 (107) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +27 -275
  3. data/README.rdoc +1 -1
  4. data/lib/action_view.rb +3 -2
  5. data/lib/action_view/base.rb +8 -10
  6. data/lib/action_view/buffers.rb +2 -0
  7. data/lib/action_view/context.rb +2 -2
  8. data/lib/action_view/dependency_tracker.rb +2 -0
  9. data/lib/action_view/digestor.rb +6 -12
  10. data/lib/action_view/flows.rb +2 -0
  11. data/lib/action_view/gem_version.rb +5 -3
  12. data/lib/action_view/helpers.rb +2 -0
  13. data/lib/action_view/helpers/active_model_helper.rb +9 -3
  14. data/lib/action_view/helpers/asset_tag_helper.rb +79 -22
  15. data/lib/action_view/helpers/asset_url_helper.rb +13 -11
  16. data/lib/action_view/helpers/atom_feed_helper.rb +3 -1
  17. data/lib/action_view/helpers/cache_helper.rb +24 -14
  18. data/lib/action_view/helpers/capture_helper.rb +9 -7
  19. data/lib/action_view/helpers/controller_helper.rb +3 -1
  20. data/lib/action_view/helpers/csrf_helper.rb +4 -2
  21. data/lib/action_view/helpers/date_helper.rb +5 -3
  22. data/lib/action_view/helpers/debug_helper.rb +3 -1
  23. data/lib/action_view/helpers/form_helper.rb +43 -60
  24. data/lib/action_view/helpers/form_options_helper.rb +9 -7
  25. data/lib/action_view/helpers/form_tag_helper.rb +20 -11
  26. data/lib/action_view/helpers/javascript_helper.rb +5 -3
  27. data/lib/action_view/helpers/number_helper.rb +2 -0
  28. data/lib/action_view/helpers/output_safety_helper.rb +2 -0
  29. data/lib/action_view/helpers/record_tag_helper.rb +3 -1
  30. data/lib/action_view/helpers/rendering_helper.rb +4 -1
  31. data/lib/action_view/helpers/sanitize_helper.rb +3 -1
  32. data/lib/action_view/helpers/tag_helper.rb +2 -2
  33. data/lib/action_view/helpers/tags.rb +3 -1
  34. data/lib/action_view/helpers/tags/base.rb +12 -10
  35. data/lib/action_view/helpers/tags/check_box.rb +3 -1
  36. data/lib/action_view/helpers/tags/checkable.rb +4 -2
  37. data/lib/action_view/helpers/tags/collection_check_boxes.rb +2 -0
  38. data/lib/action_view/helpers/tags/collection_helpers.rb +2 -0
  39. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +2 -0
  40. data/lib/action_view/helpers/tags/collection_select.rb +3 -1
  41. data/lib/action_view/helpers/tags/color_field.rb +3 -1
  42. data/lib/action_view/helpers/tags/date_field.rb +2 -0
  43. data/lib/action_view/helpers/tags/date_select.rb +3 -1
  44. data/lib/action_view/helpers/tags/datetime_field.rb +3 -1
  45. data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -0
  46. data/lib/action_view/helpers/tags/datetime_select.rb +2 -0
  47. data/lib/action_view/helpers/tags/email_field.rb +2 -0
  48. data/lib/action_view/helpers/tags/file_field.rb +2 -0
  49. data/lib/action_view/helpers/tags/grouped_collection_select.rb +3 -1
  50. data/lib/action_view/helpers/tags/hidden_field.rb +2 -0
  51. data/lib/action_view/helpers/tags/label.rb +2 -4
  52. data/lib/action_view/helpers/tags/month_field.rb +2 -0
  53. data/lib/action_view/helpers/tags/number_field.rb +2 -0
  54. data/lib/action_view/helpers/tags/password_field.rb +2 -0
  55. data/lib/action_view/helpers/tags/placeholderable.rb +2 -0
  56. data/lib/action_view/helpers/tags/radio_button.rb +3 -1
  57. data/lib/action_view/helpers/tags/range_field.rb +2 -0
  58. data/lib/action_view/helpers/tags/search_field.rb +2 -0
  59. data/lib/action_view/helpers/tags/select.rb +5 -3
  60. data/lib/action_view/helpers/tags/tel_field.rb +2 -0
  61. data/lib/action_view/helpers/tags/text_area.rb +3 -1
  62. data/lib/action_view/helpers/tags/text_field.rb +3 -1
  63. data/lib/action_view/helpers/tags/time_field.rb +2 -0
  64. data/lib/action_view/helpers/tags/time_select.rb +2 -0
  65. data/lib/action_view/helpers/tags/time_zone_select.rb +3 -1
  66. data/lib/action_view/helpers/tags/translator.rb +2 -0
  67. data/lib/action_view/helpers/tags/url_field.rb +2 -0
  68. data/lib/action_view/helpers/tags/week_field.rb +2 -0
  69. data/lib/action_view/helpers/text_helper.rb +4 -2
  70. data/lib/action_view/helpers/translation_helper.rb +5 -4
  71. data/lib/action_view/helpers/url_helper.rb +24 -5
  72. data/lib/action_view/layouts.rb +7 -5
  73. data/lib/action_view/log_subscriber.rb +5 -3
  74. data/lib/action_view/lookup_context.rb +4 -4
  75. data/lib/action_view/model_naming.rb +2 -0
  76. data/lib/action_view/path_set.rb +2 -0
  77. data/lib/action_view/railtie.rb +11 -2
  78. data/lib/action_view/record_identifier.rb +2 -0
  79. data/lib/action_view/renderer/abstract_renderer.rb +2 -0
  80. data/lib/action_view/renderer/partial_renderer.rb +13 -11
  81. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +4 -2
  82. data/lib/action_view/renderer/renderer.rb +2 -0
  83. data/lib/action_view/renderer/streaming_template_renderer.rb +3 -1
  84. data/lib/action_view/renderer/template_renderer.rb +2 -0
  85. data/lib/action_view/rendering.rb +3 -5
  86. data/lib/action_view/routing_url_for.rb +2 -0
  87. data/lib/action_view/tasks/cache_digests.rake +2 -0
  88. data/lib/action_view/template.rb +6 -4
  89. data/lib/action_view/template/error.rb +2 -3
  90. data/lib/action_view/template/handlers.rb +3 -1
  91. data/lib/action_view/template/handlers/builder.rb +3 -4
  92. data/lib/action_view/template/handlers/erb.rb +5 -9
  93. data/lib/action_view/template/handlers/erb/erubi.rb +2 -0
  94. data/lib/action_view/template/handlers/html.rb +2 -0
  95. data/lib/action_view/template/handlers/raw.rb +2 -0
  96. data/lib/action_view/template/html.rb +3 -1
  97. data/lib/action_view/template/resolver.rb +7 -6
  98. data/lib/action_view/template/text.rb +3 -1
  99. data/lib/action_view/template/types.rb +3 -1
  100. data/lib/action_view/test_case.rb +21 -5
  101. data/lib/action_view/testing/resolvers.rb +3 -1
  102. data/lib/action_view/version.rb +2 -0
  103. data/lib/action_view/view_paths.rb +3 -3
  104. data/lib/assets/compiled/rails-ujs.js +3 -3
  105. metadata +14 -15
  106. data/lib/action_view/template/handlers/erb/deprecated_erubis.rb +0 -9
  107. data/lib/action_view/template/handlers/erb/erubis.rb +0 -81
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/string/output_safety"
2
4
 
3
5
  module ActionView
4
6
  # = Action View Capture Helper
5
- module Helpers
7
+ module Helpers #:nodoc:
6
8
  # CaptureHelper exposes methods to let you extract generated markup which
7
9
  # can be used in other parts of a template or layout file.
8
10
  #
9
11
  # 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.
12
+ # a way to capture a block of markup for use in a layout through {content_for}[rdoc-ref:ActionView::Helpers::CaptureHelper#content_for].
11
13
  module CaptureHelper
12
14
  # The capture method extracts part of a template as a String object.
13
15
  # You can then use this object anywhere in your templates, layout, or helpers.
@@ -42,7 +44,7 @@ module ActionView
42
44
  end
43
45
  end
44
46
 
45
- # Calling content_for stores a block of markup in an identifier for later use.
47
+ # Calling <tt>content_for</tt> stores a block of markup in an identifier for later use.
46
48
  # In order to access this stored content in other templates, helper modules
47
49
  # or the layout, you would pass the identifier as an argument to <tt>content_for</tt>.
48
50
  #
@@ -108,7 +110,7 @@ module ActionView
108
110
  # That will place +script+ tags for your default set of JavaScript files on the page;
109
111
  # this technique is useful if you'll only be using these scripts in a few views.
110
112
  #
111
- # Note that content_for concatenates (default) the blocks it is given for a particular
113
+ # Note that <tt>content_for</tt> concatenates (default) the blocks it is given for a particular
112
114
  # identifier in order. For example:
113
115
  #
114
116
  # <% content_for :navigation do %>
@@ -125,7 +127,7 @@ module ActionView
125
127
  #
126
128
  # <ul><%= content_for :navigation %></ul>
127
129
  #
128
- # If the flush parameter is true content_for replaces the blocks it is given. For example:
130
+ # If the flush parameter is +true+ <tt>content_for</tt> replaces the blocks it is given. For example:
129
131
  #
130
132
  # <% content_for :navigation do %>
131
133
  # <li><%= link_to 'Home', action: 'index' %></li>
@@ -145,7 +147,7 @@ module ActionView
145
147
  #
146
148
  # <% content_for :script, javascript_include_tag(:defaults) %>
147
149
  #
148
- # WARNING: content_for is ignored in caches. So you shouldn't use it for elements that will be fragment cached.
150
+ # WARNING: <tt>content_for</tt> is ignored in caches. So you shouldn't use it for elements that will be fragment cached.
149
151
  def content_for(name, content = nil, options = {}, &block)
150
152
  if content || block_given?
151
153
  if block_given?
@@ -172,7 +174,7 @@ module ActionView
172
174
  result unless content
173
175
  end
174
176
 
175
- # content_for? checks whether any content has been captured yet using `content_for`.
177
+ # <tt>content_for?</tt> checks whether any content has been captured yet using <tt>content_for</tt>.
176
178
  # Useful to render parts of your layout differently based on what is in your views.
177
179
  #
178
180
  # <%# This is the layout %>
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/attr_internal"
2
4
 
3
5
  module ActionView
4
- module Helpers
6
+ module Helpers #:nodoc:
5
7
  # This module keeps all methods and behavior in ActionView
6
8
  # that simply delegates to the controller.
7
9
  module ControllerHelper #:nodoc:
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionView
2
4
  # = Action View CSRF Helper
3
- module Helpers
5
+ module Helpers #:nodoc:
4
6
  module CsrfHelper
5
7
  # Returns meta tags "csrf-param" and "csrf-token" with the name of the cross-site
6
8
  # request forgery protection parameter and token, respectively.
@@ -15,7 +17,7 @@ module ActionView
15
17
  # You don't need to use these tags for regular forms as they generate their own hidden fields.
16
18
  #
17
19
  # 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.
20
+ # "X-CSRF-Token" HTTP header. If you are using rails-ujs this happens automatically.
19
21
  #
20
22
  def csrf_meta_tags
21
23
  if protect_against_forgery?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "date"
2
4
  require "action_view/helpers/tag_helper"
3
5
  require "active_support/core_ext/array/extract_options"
@@ -7,7 +9,7 @@ require "active_support/core_ext/object/acts_like"
7
9
  require "active_support/core_ext/object/with_options"
8
10
 
9
11
  module ActionView
10
- module Helpers
12
+ module Helpers #:nodoc:
11
13
  # = Action View Date Helpers
12
14
  #
13
15
  # The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time
@@ -1007,7 +1009,7 @@ module ActionView
1007
1009
  select_options[:disabled] = "disabled" if @options[:disabled]
1008
1010
  select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes]
1009
1011
 
1010
- select_html = "\n"
1012
+ select_html = "\n".dup
1011
1013
  select_html << content_tag("option".freeze, "", value: "") + "\n" if @options[:include_blank]
1012
1014
  select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt]
1013
1015
  select_html << select_options_as_html
@@ -1089,7 +1091,7 @@ module ActionView
1089
1091
  # Given an ordering of datetime components, create the selection HTML
1090
1092
  # and join them with their appropriate separators.
1091
1093
  def build_selects_from_types(order)
1092
- select = ""
1094
+ select = "".dup
1093
1095
  first_visible = order.find { |type| !@options[:"discard_#{type}"] }
1094
1096
  order.reverse_each do |type|
1095
1097
  separator = separator(type) unless type == first_visible # don't add before first visible field
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionView
2
4
  # = Action View Debug Helper
3
5
  #
4
6
  # Provides a set of methods for making it easier to debug Rails objects.
5
- module Helpers
7
+ module Helpers #:nodoc:
6
8
  module DebugHelper
7
9
  include TagHelper
8
10
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
  require "action_view/helpers/date_helper"
3
5
  require "action_view/helpers/tag_helper"
@@ -12,7 +14,7 @@ require "active_support/core_ext/string/inflections"
12
14
 
13
15
  module ActionView
14
16
  # = Action View Form Helpers
15
- module Helpers
17
+ module Helpers #:nodoc:
16
18
  # Form helpers are designed to make working with resources much easier
17
19
  # compared to using vanilla HTML.
18
20
  #
@@ -201,9 +203,9 @@ module ActionView
201
203
  # <%= f.submit %>
202
204
  # <% end %>
203
205
  #
204
- # This also works for the methods in FormOptionHelper and DateHelper that
206
+ # This also works for the methods in FormOptionsHelper and DateHelper that
205
207
  # are designed to work with an object as base, like
206
- # FormOptionHelper#collection_select and DateHelper#datetime_select.
208
+ # FormOptionsHelper#collection_select and DateHelper#datetime_select.
207
209
  #
208
210
  # === #form_for with a model object
209
211
  #
@@ -416,13 +418,13 @@ module ActionView
416
418
  #
417
419
  # To set an authenticity token you need to pass an <tt>:authenticity_token</tt> parameter
418
420
  #
419
- # <%= form_for @invoice, url: external_url, authenticity_token: 'external_token' do |f|
421
+ # <%= form_for @invoice, url: external_url, authenticity_token: 'external_token' do |f| %>
420
422
  # ...
421
423
  # <% end %>
422
424
  #
423
425
  # If you don't want to an authenticity token field be rendered at all just pass <tt>false</tt>:
424
426
  #
425
- # <%= form_for @invoice, url: external_url, authenticity_token: false do |f|
427
+ # <%= form_for @invoice, url: external_url, authenticity_token: false do |f| %>
426
428
  # ...
427
429
  # <% end %>
428
430
  def form_for(record, options = {}, &block)
@@ -474,7 +476,9 @@ module ActionView
474
476
  end
475
477
  private :apply_form_for_options!
476
478
 
477
- mattr_accessor(:form_with_generates_remote_forms) { true }
479
+ mattr_accessor :form_with_generates_remote_forms, default: true
480
+
481
+ mattr_accessor :form_with_generates_ids, default: false
478
482
 
479
483
  # Creates a form tag based on mixing URLs, scopes, or models.
480
484
  #
@@ -638,16 +642,6 @@ module ActionView
638
642
  #
639
643
  # Where <tt>@document = Document.find(params[:id])</tt>.
640
644
  #
641
- # When using labels +form_with+ requires setting the id on the field being
642
- # labelled:
643
- #
644
- # <%= form_with(model: @post) do |form| %>
645
- # <%= form.label :title %>
646
- # <%= form.text_field :title, id: :post_title %>
647
- # <% end %>
648
- #
649
- # See +label+ for more on how the +for+ attribute is derived.
650
- #
651
645
  # === Mixing with other form helpers
652
646
  #
653
647
  # While +form_with+ uses a FormBuilder object it's possible to mix and
@@ -664,9 +658,9 @@ module ActionView
664
658
  # <%= form.submit %>
665
659
  # <% end %>
666
660
  #
667
- # Same goes for the methods in FormOptionHelper and DateHelper designed
661
+ # Same goes for the methods in FormOptionsHelper and DateHelper designed
668
662
  # to work with an object as a base, like
669
- # FormOptionHelper#collection_select and DateHelper#datetime_select.
663
+ # FormOptionsHelper#collection_select and DateHelper#datetime_select.
670
664
  #
671
665
  # === Setting the method
672
666
  #
@@ -744,7 +738,7 @@ module ActionView
744
738
  # end
745
739
  def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
746
740
  options[:allow_method_names_outside_object] = true
747
- options[:skip_default_ids] = true
741
+ options[:skip_default_ids] = !form_with_generates_ids
748
742
 
749
743
  if model
750
744
  url ||= polymorphic_path(model, format: format)
@@ -823,9 +817,9 @@ module ActionView
823
817
  # _class_ of the model object, e.g. if <tt>@person.permission</tt>, is
824
818
  # of class +Permission+, the field will still be named <tt>permission[admin]</tt>.
825
819
  #
826
- # Note: This also works for the methods in FormOptionHelper and
820
+ # Note: This also works for the methods in FormOptionsHelper and
827
821
  # DateHelper that are designed to work with an object as base, like
828
- # FormOptionHelper#collection_select and DateHelper#datetime_select.
822
+ # FormOptionsHelper#collection_select and DateHelper#datetime_select.
829
823
  #
830
824
  # === Nested Attributes Examples
831
825
  #
@@ -1042,16 +1036,6 @@ module ActionView
1042
1036
  # or model is yielded, so any generated field names are prefixed with
1043
1037
  # either the passed scope or the scope inferred from the <tt>:model</tt>.
1044
1038
  #
1045
- # When using labels +fields+ requires setting the id on the field being
1046
- # labelled:
1047
- #
1048
- # <%= fields :comment do |fields| %>
1049
- # <%= fields.label :body %>
1050
- # <%= fields.text_field :body, id: :comment_body %>
1051
- # <% end %>
1052
- #
1053
- # See +label+ for more on how the +for+ attribute is derived.
1054
- #
1055
1039
  # === Mixing with other form helpers
1056
1040
  #
1057
1041
  # While +form_with+ uses a FormBuilder object it's possible to mix and
@@ -1065,12 +1049,12 @@ module ActionView
1065
1049
  # <%= check_box_tag "comment[all_caps]", "1", @comment.commenter.hulk_mode? %>
1066
1050
  # <% end %>
1067
1051
  #
1068
- # Same goes for the methods in FormOptionHelper and DateHelper designed
1052
+ # Same goes for the methods in FormOptionsHelper and DateHelper designed
1069
1053
  # to work with an object as a base, like
1070
- # FormOptionHelper#collection_select and DateHelper#datetime_select.
1054
+ # FormOptionsHelper#collection_select and DateHelper#datetime_select.
1071
1055
  def fields(scope = nil, model: nil, **options, &block)
1072
1056
  options[:allow_method_names_outside_object] = true
1073
- options[:skip_default_ids] = true
1057
+ options[:skip_default_ids] = !form_with_generates_ids
1074
1058
 
1075
1059
  if model
1076
1060
  scope ||= model_name_from_record_or_class(model).param_key
@@ -1221,7 +1205,7 @@ module ActionView
1221
1205
  # file_field(:attachment, :file, class: 'file_input')
1222
1206
  # # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
1223
1207
  def file_field(object_name, method, options = {})
1224
- Tags::FileField.new(object_name, method, self, options).render
1208
+ Tags::FileField.new(object_name, method, self, convert_direct_upload_option_to_url(options.dup)).render
1225
1209
  end
1226
1210
 
1227
1211
  # Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
@@ -1597,7 +1581,7 @@ module ActionView
1597
1581
  # In the above block, a +FormBuilder+ object is yielded as the
1598
1582
  # +person_form+ variable. This allows you to generate the +text_field+
1599
1583
  # and +check_box+ fields by specifying their eponymous methods, which
1600
- # modify the underlying template and associates the +@person+ model object
1584
+ # modify the underlying template and associates the <tt>@person</tt> model object
1601
1585
  # with the form.
1602
1586
  #
1603
1587
  # The +FormBuilder+ object can be thought of as serving as a proxy for the
@@ -1636,14 +1620,15 @@ module ActionView
1636
1620
  include ModelNaming
1637
1621
 
1638
1622
  # The methods which wrap a form helper call.
1639
- class_attribute :field_helpers
1640
- self.field_helpers = [:fields_for, :fields, :label, :text_field, :password_field,
1641
- :hidden_field, :file_field, :text_area, :check_box,
1642
- :radio_button, :color_field, :search_field,
1643
- :telephone_field, :phone_field, :date_field,
1644
- :time_field, :datetime_field, :datetime_local_field,
1645
- :month_field, :week_field, :url_field, :email_field,
1646
- :number_field, :range_field]
1623
+ class_attribute :field_helpers, default: [
1624
+ :fields_for, :fields, :label, :text_field, :password_field,
1625
+ :hidden_field, :file_field, :text_area, :check_box,
1626
+ :radio_button, :color_field, :search_field,
1627
+ :telephone_field, :phone_field, :date_field,
1628
+ :time_field, :datetime_field, :datetime_local_field,
1629
+ :month_field, :week_field, :url_field, :email_field,
1630
+ :number_field, :range_field
1631
+ ]
1647
1632
 
1648
1633
  attr_accessor :object_name, :object, :options
1649
1634
 
@@ -1758,9 +1743,9 @@ module ActionView
1758
1743
  # _class_ of the model object, e.g. if <tt>@person.permission</tt>, is
1759
1744
  # of class +Permission+, the field will still be named <tt>permission[admin]</tt>.
1760
1745
  #
1761
- # Note: This also works for the methods in FormOptionHelper and
1746
+ # Note: This also works for the methods in FormOptionsHelper and
1762
1747
  # DateHelper that are designed to work with an object as base, like
1763
- # FormOptionHelper#collection_select and DateHelper#datetime_select.
1748
+ # FormOptionsHelper#collection_select and DateHelper#datetime_select.
1764
1749
  #
1765
1750
  # === Nested Attributes Examples
1766
1751
  #
@@ -1982,7 +1967,7 @@ module ActionView
1982
1967
  # See the docs for the <tt>ActionView::FormHelper.fields</tt> helper method.
1983
1968
  def fields(scope = nil, model: nil, **options, &block)
1984
1969
  options[:allow_method_names_outside_object] = true
1985
- options[:skip_default_ids] = true
1970
+ options[:skip_default_ids] = !FormHelper.form_with_generates_ids
1986
1971
 
1987
1972
  convert_to_legacy_options(options)
1988
1973
 
@@ -2192,11 +2177,11 @@ module ActionView
2192
2177
  # <%= f.submit %>
2193
2178
  # <% end %>
2194
2179
  #
2195
- # In the example above, if @post is a new record, it will use "Create Post" as
2196
- # submit button label, otherwise, it uses "Update Post".
2180
+ # In the example above, if <tt>@post</tt> is a new record, it will use "Create Post" as
2181
+ # submit button label; otherwise, it uses "Update Post".
2197
2182
  #
2198
- # Those labels can be customized using I18n, under the helpers.submit key and accept
2199
- # the %{model} as translation interpolation:
2183
+ # Those labels can be customized using I18n under the +helpers.submit+ key and using
2184
+ # <tt>%{model}</tt> for translation interpolation:
2200
2185
  #
2201
2186
  # en:
2202
2187
  # helpers:
@@ -2204,7 +2189,7 @@ module ActionView
2204
2189
  # create: "Create a %{model}"
2205
2190
  # update: "Confirm changes to %{model}"
2206
2191
  #
2207
- # It also searches for a key specific for the given object:
2192
+ # It also searches for a key specific to the given object:
2208
2193
  #
2209
2194
  # en:
2210
2195
  # helpers:
@@ -2225,11 +2210,11 @@ module ActionView
2225
2210
  # <%= f.button %>
2226
2211
  # <% end %>
2227
2212
  #
2228
- # In the example above, if @post is a new record, it will use "Create Post" as
2229
- # button label, otherwise, it uses "Update Post".
2213
+ # In the example above, if <tt>@post</tt> is a new record, it will use "Create Post" as
2214
+ # button label; otherwise, it uses "Update Post".
2230
2215
  #
2231
- # Those labels can be customized using I18n, under the helpers.submit key
2232
- # (the same as submit helper) and accept the %{model} as translation interpolation:
2216
+ # Those labels can be customized using I18n under the +helpers.submit+ key
2217
+ # (the same as submit helper) and using <tt>%{model}</tt> for translation interpolation:
2233
2218
  #
2234
2219
  # en:
2235
2220
  # helpers:
@@ -2237,7 +2222,7 @@ module ActionView
2237
2222
  # create: "Create a %{model}"
2238
2223
  # update: "Confirm changes to %{model}"
2239
2224
  #
2240
- # It also searches for a key specific for the given object:
2225
+ # It also searches for a key specific to the given object:
2241
2226
  #
2242
2227
  # en:
2243
2228
  # helpers:
@@ -2347,8 +2332,6 @@ module ActionView
2347
2332
  end
2348
2333
 
2349
2334
  ActiveSupport.on_load(:action_view) do
2350
- cattr_accessor(:default_form_builder, instance_writer: false, instance_reader: false) do
2351
- ::ActionView::Helpers::FormBuilder
2352
- end
2335
+ cattr_accessor :default_form_builder, instance_writer: false, instance_reader: false, default: ::ActionView::Helpers::FormBuilder
2353
2336
  end
2354
2337
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
  require "erb"
3
5
  require "action_view/helpers/form_helper"
@@ -7,7 +9,7 @@ require "active_support/core_ext/array/wrap"
7
9
 
8
10
  module ActionView
9
11
  # = Action View Form Option Helpers
10
- module Helpers
12
+ module Helpers #:nodoc:
11
13
  # Provides a number of methods for turning different kinds of containers into a set of option tags.
12
14
  #
13
15
  # The <tt>collection_select</tt>, <tt>select</tt> and <tt>time_zone_select</tt> methods take an <tt>options</tt> parameter, a hash:
@@ -277,17 +279,17 @@ module ActionView
277
279
  # Finally, this method supports a <tt>:default</tt> option, which selects
278
280
  # a default ActiveSupport::TimeZone if the object's time zone is +nil+.
279
281
  #
280
- # time_zone_select( "user", "time_zone", nil, include_blank: true)
282
+ # time_zone_select("user", "time_zone", nil, include_blank: true)
281
283
  #
282
- # time_zone_select( "user", "time_zone", nil, default: "Pacific Time (US & Canada)" )
284
+ # time_zone_select("user", "time_zone", nil, default: "Pacific Time (US & Canada)")
283
285
  #
284
- # time_zone_select( "user", 'time_zone', ActiveSupport::TimeZone.us_zones, default: "Pacific Time (US & Canada)")
286
+ # time_zone_select("user", 'time_zone', ActiveSupport::TimeZone.us_zones, default: "Pacific Time (US & Canada)")
285
287
  #
286
- # time_zone_select( "user", 'time_zone', [ ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii'] ])
288
+ # time_zone_select("user", 'time_zone', [ ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii'] ])
287
289
  #
288
- # time_zone_select( "user", 'time_zone', /Australia/)
290
+ # time_zone_select("user", 'time_zone', /Australia/)
289
291
  #
290
- # time_zone_select( "user", "time_zone", ActiveSupport::TimeZone.all.sort, model: ActiveSupport::TimeZone)
292
+ # time_zone_select("user", "time_zone", ActiveSupport::TimeZone.all.sort, model: ActiveSupport::TimeZone)
291
293
  def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {})
292
294
  Tags::TimeZoneSelect.new(object, method, self, priority_zones, options, html_options).render
293
295
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
  require "action_view/helpers/tag_helper"
3
5
  require "active_support/core_ext/string/output_safety"
@@ -5,7 +7,7 @@ require "active_support/core_ext/module/attribute_accessors"
5
7
 
6
8
  module ActionView
7
9
  # = Action View Form Tag Helpers
8
- module Helpers
10
+ module Helpers #:nodoc:
9
11
  # Provides a number of methods for creating form tags that don't rely on an Active Record object assigned to the template like
10
12
  # FormHelper does. Instead, you provide the names and values manually.
11
13
  #
@@ -113,7 +115,7 @@ module ActionView
113
115
  # # <option>Write</option></select>
114
116
  #
115
117
  # select_tag "people", options_from_collection_for_select(@people, "id", "name"), include_blank: true
116
- # # => <select id="people" name="people"><option value=""></option><option value="1">David</option></select>
118
+ # # => <select id="people" name="people"><option value="" label=" "></option><option value="1">David</option></select>
117
119
  #
118
120
  # select_tag "people", options_from_collection_for_select(@people, "id", "name"), include_blank: "All"
119
121
  # # => <select id="people" name="people"><option value="">All</option><option value="1">David</option></select>
@@ -272,7 +274,7 @@ module ActionView
272
274
  # file_field_tag 'file', accept: 'text/html', class: 'upload', value: 'index.html'
273
275
  # # => <input accept="text/html" class="upload" id="file" name="file" type="file" value="index.html" />
274
276
  def file_field_tag(name, options = {})
275
- text_field_tag(name, nil, options.merge(type: :file))
277
+ text_field_tag(name, nil, convert_direct_upload_option_to_url(options.merge(type: :file)))
276
278
  end
277
279
 
278
280
  # Creates a password field, a masked text field that will hide the users input behind a mask character.
@@ -392,7 +394,7 @@ module ActionView
392
394
  # # => <input checked="checked" id="receive_updates_no" name="receive_updates" type="radio" value="no" />
393
395
  #
394
396
  # radio_button_tag 'time_slot', "3:00 p.m.", false, disabled: true
395
- # # => <input disabled="disabled" id="time_slot_300_pm" name="time_slot" type="radio" value="3:00 p.m." />
397
+ # # => <input disabled="disabled" id="time_slot_3:00_p.m." name="time_slot" type="radio" value="3:00 p.m." />
396
398
  #
397
399
  # radio_button_tag 'color', "green", true, class: "color_input"
398
400
  # # => <input checked="checked" class="color_input" id="color_green" name="color" type="radio" value="green" />
@@ -454,7 +456,7 @@ module ActionView
454
456
  # submit tag but it isn't supported in legacy browsers. However,
455
457
  # the button tag does allow for richer labels such as images and emphasis,
456
458
  # so this helper will also accept a block. By default, it will create
457
- # a button tag with type `submit`, if type is not given.
459
+ # a button tag with type <tt>submit</tt>, if type is not given.
458
460
  #
459
461
  # ==== Options
460
462
  # * <tt>:data</tt> - This option can be used to add custom data attributes.
@@ -532,22 +534,22 @@ module ActionView
532
534
  #
533
535
  # ==== Examples
534
536
  # image_submit_tag("login.png")
535
- # # => <input alt="Login" src="/assets/login.png" type="image" />
537
+ # # => <input src="/assets/login.png" type="image" />
536
538
  #
537
539
  # image_submit_tag("purchase.png", disabled: true)
538
- # # => <input alt="Purchase" disabled="disabled" src="/assets/purchase.png" type="image" />
540
+ # # => <input disabled="disabled" src="/assets/purchase.png" type="image" />
539
541
  #
540
542
  # image_submit_tag("search.png", class: 'search_button', alt: 'Find')
541
- # # => <input alt="Find" class="search_button" src="/assets/search.png" type="image" />
543
+ # # => <input class="search_button" src="/assets/search.png" type="image" />
542
544
  #
543
545
  # image_submit_tag("agree.png", disabled: true, class: "agree_disagree_button")
544
- # # => <input alt="Agree" class="agree_disagree_button" disabled="disabled" src="/assets/agree.png" type="image" />
546
+ # # => <input class="agree_disagree_button" disabled="disabled" src="/assets/agree.png" type="image" />
545
547
  #
546
548
  # image_submit_tag("save.png", data: { confirm: "Are you sure?" })
547
- # # => <input alt="Save" src="/assets/save.png" data-confirm="Are you sure?" type="image" />
549
+ # # => <input src="/assets/save.png" data-confirm="Are you sure?" type="image" />
548
550
  def image_submit_tag(source, options = {})
549
551
  options = options.stringify_keys
550
- tag :input, { "alt" => image_alt(source), "type" => "image", "src" => path_to_image(source) }.update(options)
552
+ tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options)
551
553
  end
552
554
 
553
555
  # Creates a field set for grouping HTML form elements.
@@ -902,6 +904,13 @@ module ActionView
902
904
 
903
905
  tag_options.delete("data-disable-with")
904
906
  end
907
+
908
+ def convert_direct_upload_option_to_url(options)
909
+ if options.delete(:direct_upload) && respond_to?(:rails_direct_uploads_url)
910
+ options["data-direct-upload-url"] = rails_direct_uploads_url
911
+ end
912
+ options
913
+ end
905
914
  end
906
915
  end
907
916
  end