actionview 7.2.3.1 → 8.1.4.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +198 -109
- data/lib/action_view/base.rb +5 -2
- data/lib/action_view/buffers.rb +1 -1
- data/lib/action_view/dependency_tracker/erb_tracker.rb +37 -28
- data/lib/action_view/dependency_tracker/ruby_tracker.rb +3 -20
- data/lib/action_view/dependency_tracker/wildcard_resolver.rb +32 -0
- data/lib/action_view/dependency_tracker.rb +7 -1
- data/lib/action_view/gem_version.rb +3 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +21 -2
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -2
- data/lib/action_view/helpers/cache_helper.rb +8 -0
- data/lib/action_view/helpers/capture_helper.rb +2 -2
- data/lib/action_view/helpers/controller_helper.rb +6 -2
- data/lib/action_view/helpers/date_helper.rb +20 -3
- data/lib/action_view/helpers/form_helper.rb +77 -77
- data/lib/action_view/helpers/form_options_helper.rb +42 -36
- data/lib/action_view/helpers/form_tag_helper.rb +35 -25
- data/lib/action_view/helpers/javascript_helper.rb +5 -1
- data/lib/action_view/helpers/number_helper.rb +14 -0
- data/lib/action_view/helpers/rendering_helper.rb +160 -50
- data/lib/action_view/helpers/sanitize_helper.rb +12 -1
- data/lib/action_view/helpers/tag_helper.rb +70 -77
- data/lib/action_view/helpers/tags/base.rb +11 -9
- data/lib/action_view/helpers/tags/check_box.rb +9 -3
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
- data/lib/action_view/helpers/tags/collection_helpers.rb +11 -1
- data/lib/action_view/helpers/tags/datetime_field.rb +1 -1
- data/lib/action_view/helpers/tags/file_field.rb +7 -2
- data/lib/action_view/helpers/tags/hidden_field.rb +1 -1
- data/lib/action_view/helpers/tags/label.rb +3 -10
- data/lib/action_view/helpers/tags/radio_button.rb +1 -1
- data/lib/action_view/helpers/tags/select.rb +6 -1
- data/lib/action_view/helpers/tags/select_renderer.rb +6 -4
- data/lib/action_view/helpers/tags/text_area.rb +1 -1
- data/lib/action_view/helpers/tags/text_field.rb +1 -1
- data/lib/action_view/helpers/tags/week_field.rb +1 -1
- data/lib/action_view/helpers/text_helper.rb +23 -7
- data/lib/action_view/helpers/translation_helper.rb +6 -1
- data/lib/action_view/helpers/url_helper.rb +39 -13
- data/lib/action_view/layouts.rb +1 -1
- data/lib/action_view/locale/en.yml +3 -0
- data/lib/action_view/log_subscriber.rb +1 -4
- data/lib/action_view/railtie.rb +12 -1
- data/lib/action_view/record_identifier.rb +22 -1
- data/lib/action_view/render_parser/prism_render_parser.rb +13 -1
- data/lib/action_view/render_parser/ripper_render_parser.rb +10 -1
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +5 -1
- data/lib/action_view/renderer/partial_renderer.rb +16 -0
- data/lib/action_view/renderer/streaming_template_renderer.rb +8 -2
- data/lib/action_view/rendering.rb +2 -3
- data/lib/action_view/structured_event_subscriber.rb +97 -0
- data/lib/action_view/template/error.rb +7 -3
- data/lib/action_view/template/handlers/erb/erubi.rb +1 -1
- data/lib/action_view/template/handlers/erb.rb +37 -12
- data/lib/action_view/template/raw_file.rb +4 -0
- data/lib/action_view/template/resolver.rb +0 -1
- data/lib/action_view/template.rb +12 -6
- data/lib/action_view/test_case.rb +68 -55
- data/lib/action_view.rb +16 -0
- metadata +20 -26
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "cgi"
|
|
4
3
|
require "erb"
|
|
5
4
|
require "active_support/core_ext/string/output_safety"
|
|
6
5
|
require "active_support/core_ext/array/extract_options"
|
|
@@ -13,7 +12,7 @@ module ActionView
|
|
|
13
12
|
#
|
|
14
13
|
# Provides a number of methods for turning different kinds of containers into a set of option tags.
|
|
15
14
|
#
|
|
16
|
-
# The
|
|
15
|
+
# The #collection_select, #select and #time_zone_select methods take an <tt>options</tt> parameter, a hash:
|
|
17
16
|
#
|
|
18
17
|
# * <tt>:include_blank</tt> - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.
|
|
19
18
|
#
|
|
@@ -55,7 +54,7 @@ module ActionView
|
|
|
55
54
|
# <option value="3">Rafael</option>
|
|
56
55
|
# </select>
|
|
57
56
|
#
|
|
58
|
-
# * <tt>:index</tt> - like the other form helpers,
|
|
57
|
+
# * <tt>:index</tt> - 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
|
|
59
58
|
# option to be in the +html_options+ parameter.
|
|
60
59
|
#
|
|
61
60
|
# select("album[]", :genre, %w[ rap rock country ], {}, { index: nil })
|
|
@@ -80,7 +79,7 @@ module ActionView
|
|
|
80
79
|
# <option disabled="disabled" value="restricted">restricted</option>
|
|
81
80
|
# </select>
|
|
82
81
|
#
|
|
83
|
-
# When used with the
|
|
82
|
+
# When used with the #collection_select helper, <tt>:disabled</tt> can also be a Proc that identifies those options that should be disabled.
|
|
84
83
|
#
|
|
85
84
|
# collection_select(:post, :category_id, Category.all, :id, :name, { disabled: -> (category) { category.archived? } })
|
|
86
85
|
#
|
|
@@ -105,7 +104,7 @@ module ActionView
|
|
|
105
104
|
#
|
|
106
105
|
# Example with <tt>@post.person_id => 2</tt>:
|
|
107
106
|
#
|
|
108
|
-
# select :post, :person_id, Person.all.collect { |p| [ p.name, p.id ] }, { include_blank: true }
|
|
107
|
+
# select :post, :person_id, Person.all.collect { |p| [ p.name, p.id ] }, { include_blank: true }
|
|
109
108
|
#
|
|
110
109
|
# would become:
|
|
111
110
|
#
|
|
@@ -126,7 +125,7 @@ module ActionView
|
|
|
126
125
|
# or <tt>selected: nil</tt> to leave all options unselected. Similarly, you can specify values to be disabled in the option
|
|
127
126
|
# tags by specifying the <tt>:disabled</tt> option. This can either be a single value or an array of values to be disabled.
|
|
128
127
|
#
|
|
129
|
-
# A block can be passed to
|
|
128
|
+
# A block can be passed to #select to customize how the options tags will be rendered. This
|
|
130
129
|
# is useful when the options tag has complex attributes.
|
|
131
130
|
#
|
|
132
131
|
# select(report, :campaign_ids) do
|
|
@@ -265,7 +264,7 @@ module ActionView
|
|
|
265
264
|
# In addition to the <tt>:include_blank</tt> option documented above,
|
|
266
265
|
# this method also supports a <tt>:model</tt> option, which defaults
|
|
267
266
|
# to ActiveSupport::TimeZone. This may be used by users to specify a
|
|
268
|
-
# different time zone model object. (See
|
|
267
|
+
# different time zone model object. (See #time_zone_options_for_select
|
|
269
268
|
# for more information.)
|
|
270
269
|
#
|
|
271
270
|
# You can also supply an array of ActiveSupport::TimeZone objects
|
|
@@ -294,7 +293,7 @@ module ActionView
|
|
|
294
293
|
end
|
|
295
294
|
|
|
296
295
|
# Returns select and option tags for the given object and method, using
|
|
297
|
-
#
|
|
296
|
+
# #weekday_options_for_select to generate the list of option tags.
|
|
298
297
|
def weekday_select(object, method, options = {}, html_options = {}, &block)
|
|
299
298
|
Tags::WeekdaySelect.new(object, method, self, options, html_options, &block).render
|
|
300
299
|
end
|
|
@@ -370,7 +369,7 @@ module ActionView
|
|
|
370
369
|
html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled)
|
|
371
370
|
html_attributes[:value] = value
|
|
372
371
|
|
|
373
|
-
tag_builder.
|
|
372
|
+
tag_builder.option(text, **html_attributes)
|
|
374
373
|
end.join("\n").html_safe
|
|
375
374
|
end
|
|
376
375
|
|
|
@@ -384,6 +383,11 @@ module ActionView
|
|
|
384
383
|
#
|
|
385
384
|
# select_tag 'person', options_from_collection_for_select(@people, 'id', 'name')
|
|
386
385
|
#
|
|
386
|
+
# The +value_method+ and +text_method+ can be a method name to call on each member of the +collection+,
|
|
387
|
+
# or a Proc that will be called for each member of the +collection+:
|
|
388
|
+
#
|
|
389
|
+
# options_from_collection_for_select(@people, Proc.new { |person| person.id }, Proc.new { |person| person.name })
|
|
390
|
+
#
|
|
387
391
|
# If +selected+ is specified as a value or array of values, the element(s) returning a match on +value_method+
|
|
388
392
|
# will be selected option tag(s).
|
|
389
393
|
#
|
|
@@ -411,19 +415,19 @@ module ActionView
|
|
|
411
415
|
options_for_select(options, select_deselect)
|
|
412
416
|
end
|
|
413
417
|
|
|
414
|
-
# Returns a string of <tt><option></tt> tags, like
|
|
418
|
+
# Returns a string of <tt><option></tt> tags, like #options_from_collection_for_select, but
|
|
415
419
|
# groups them by <tt><optgroup></tt> tags based on the object relationships of the arguments.
|
|
416
420
|
#
|
|
417
421
|
# Parameters:
|
|
418
422
|
# * +collection+ - An array of objects representing the <tt><optgroup></tt> tags.
|
|
419
|
-
# * +group_method+ - The name of a method which, when called on a member of +collection+, returns an
|
|
423
|
+
# * +group_method+ - The name of a method which, when called on a member of +collection+, or a Proc, which when called with a member of +collection+, returns an
|
|
420
424
|
# array of child objects representing the <tt><option></tt> tags.
|
|
421
|
-
# * +group_label_method+ - The name of a method which, when called on a member of +collection+, returns a
|
|
425
|
+
# * +group_label_method+ - The name of a method which, when called on a member of +collection+, or a Proc, which when called with a member of +collection+, returns a
|
|
422
426
|
# string to be used as the +label+ attribute for its <tt><optgroup></tt> tag.
|
|
423
427
|
# * +option_key_method+ - The name of a method which, when called on a child object of a member of
|
|
424
|
-
# +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag.
|
|
428
|
+
# +collection+, or a Proc, which when called with a child object of a member of +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag.
|
|
425
429
|
# * +option_value_method+ - The name of a method which, when called on a child object of a member of
|
|
426
|
-
# +collection+, returns a value to be used as the contents of its <tt><option></tt> tag.
|
|
430
|
+
# +collection+, or a Proc, which when called with a child object of a member of +collection+, returns a value to be used as the contents of its <tt><option></tt> tag.
|
|
427
431
|
# * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
|
|
428
432
|
# which will have the +selected+ attribute set. Corresponds to the return value of one of the calls
|
|
429
433
|
# to +option_key_method+. If +nil+, no selection is made. Can also be a hash if disabled values are
|
|
@@ -468,7 +472,7 @@ module ActionView
|
|
|
468
472
|
end.join.html_safe
|
|
469
473
|
end
|
|
470
474
|
|
|
471
|
-
# Returns a string of <tt><option></tt> tags, like
|
|
475
|
+
# Returns a string of <tt><option></tt> tags, like #options_for_select, but
|
|
472
476
|
# wraps them with <tt><optgroup></tt> tags:
|
|
473
477
|
#
|
|
474
478
|
# grouped_options = [
|
|
@@ -689,7 +693,7 @@ module ActionView
|
|
|
689
693
|
# if a +User+ model has a +category_id+ field and in the form no category is selected, no +category_id+ parameter is sent. So,
|
|
690
694
|
# any strong parameters idiom like:
|
|
691
695
|
#
|
|
692
|
-
# params.
|
|
696
|
+
# params.expect(user: [...])
|
|
693
697
|
#
|
|
694
698
|
# will raise an error since no <tt>{user: ...}</tt> will be present.
|
|
695
699
|
#
|
|
@@ -726,7 +730,7 @@ module ActionView
|
|
|
726
730
|
# end
|
|
727
731
|
#
|
|
728
732
|
# Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
|
|
729
|
-
#
|
|
733
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial)
|
|
730
734
|
#
|
|
731
735
|
# If <tt>@post.author_ids</tt> is already <tt>[1]</tt>, this would return:
|
|
732
736
|
# <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
|
|
@@ -739,8 +743,8 @@ module ActionView
|
|
|
739
743
|
#
|
|
740
744
|
# It is also possible to customize the way the elements will be shown by
|
|
741
745
|
# giving a block to the method:
|
|
742
|
-
#
|
|
743
|
-
# b.label { b.
|
|
746
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
|
747
|
+
# b.label { b.checkbox }
|
|
744
748
|
# end
|
|
745
749
|
#
|
|
746
750
|
# The argument passed to the block is a special kind of builder for this
|
|
@@ -749,17 +753,17 @@ module ActionView
|
|
|
749
753
|
# Using it, you can change the label and check box display order or even
|
|
750
754
|
# use the label as wrapper, as in the example above.
|
|
751
755
|
#
|
|
752
|
-
# The builder methods <tt>label</tt> and <tt>
|
|
756
|
+
# The builder methods <tt>label</tt> and <tt>checkbox</tt> also accept
|
|
753
757
|
# extra HTML options:
|
|
754
|
-
#
|
|
755
|
-
# b.label(class: "
|
|
758
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
|
759
|
+
# b.label(class: "checkbox") { b.checkbox(class: "checkbox") }
|
|
756
760
|
# end
|
|
757
761
|
#
|
|
758
762
|
# There are also three special methods available: <tt>object</tt>, <tt>text</tt> and
|
|
759
763
|
# <tt>value</tt>, which are the current item being rendered, its text and value methods,
|
|
760
764
|
# respectively. You can use them like this:
|
|
761
|
-
#
|
|
762
|
-
# b.label(:"data-value" => b.value) { b.
|
|
765
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
|
766
|
+
# b.label(:"data-value" => b.value) { b.checkbox + b.text }
|
|
763
767
|
# end
|
|
764
768
|
#
|
|
765
769
|
# ==== Gotcha
|
|
@@ -782,9 +786,10 @@ module ActionView
|
|
|
782
786
|
#
|
|
783
787
|
# In the rare case you don't want this hidden field, you can pass the
|
|
784
788
|
# <tt>include_hidden: false</tt> option to the helper method.
|
|
785
|
-
def
|
|
789
|
+
def collection_checkboxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
|
786
790
|
Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
|
|
787
791
|
end
|
|
792
|
+
alias_method :collection_check_boxes, :collection_checkboxes
|
|
788
793
|
|
|
789
794
|
private
|
|
790
795
|
def option_html_attributes(element)
|
|
@@ -842,7 +847,7 @@ module ActionView
|
|
|
842
847
|
class FormBuilder
|
|
843
848
|
# Wraps ActionView::Helpers::FormOptionsHelper#select for form builders:
|
|
844
849
|
#
|
|
845
|
-
# <%=
|
|
850
|
+
# <%= form_with model: @post do |f| %>
|
|
846
851
|
# <%= f.select :person_id, Person.all.collect { |p| [ p.name, p.id ] }, include_blank: true %>
|
|
847
852
|
# <%= f.submit %>
|
|
848
853
|
# <% end %>
|
|
@@ -854,7 +859,7 @@ module ActionView
|
|
|
854
859
|
|
|
855
860
|
# Wraps ActionView::Helpers::FormOptionsHelper#collection_select for form builders:
|
|
856
861
|
#
|
|
857
|
-
# <%=
|
|
862
|
+
# <%= form_with model: @post do |f| %>
|
|
858
863
|
# <%= f.collection_select :person_id, Author.all, :id, :name_with_initial, prompt: true %>
|
|
859
864
|
# <%= f.submit %>
|
|
860
865
|
# <% end %>
|
|
@@ -866,7 +871,7 @@ module ActionView
|
|
|
866
871
|
|
|
867
872
|
# Wraps ActionView::Helpers::FormOptionsHelper#grouped_collection_select for form builders:
|
|
868
873
|
#
|
|
869
|
-
# <%=
|
|
874
|
+
# <%= form_with model: @city do |f| %>
|
|
870
875
|
# <%= f.grouped_collection_select :country_id, @continents, :countries, :name, :id, :name %>
|
|
871
876
|
# <%= f.submit %>
|
|
872
877
|
# <% end %>
|
|
@@ -878,7 +883,7 @@ module ActionView
|
|
|
878
883
|
|
|
879
884
|
# Wraps ActionView::Helpers::FormOptionsHelper#time_zone_select for form builders:
|
|
880
885
|
#
|
|
881
|
-
# <%=
|
|
886
|
+
# <%= form_with model: @user do |f| %>
|
|
882
887
|
# <%= f.time_zone_select :time_zone, nil, include_blank: true %>
|
|
883
888
|
# <%= f.submit %>
|
|
884
889
|
# <% end %>
|
|
@@ -890,7 +895,7 @@ module ActionView
|
|
|
890
895
|
|
|
891
896
|
# Wraps ActionView::Helpers::FormOptionsHelper#weekday_select for form builders:
|
|
892
897
|
#
|
|
893
|
-
# <%=
|
|
898
|
+
# <%= form_with model: @user do |f| %>
|
|
894
899
|
# <%= f.weekday_select :weekday, include_blank: true %>
|
|
895
900
|
# <%= f.submit %>
|
|
896
901
|
# <% end %>
|
|
@@ -900,21 +905,22 @@ module ActionView
|
|
|
900
905
|
@template.weekday_select(@object_name, method, objectify_options(options), @default_html_options.merge(html_options))
|
|
901
906
|
end
|
|
902
907
|
|
|
903
|
-
# Wraps ActionView::Helpers::FormOptionsHelper#
|
|
908
|
+
# Wraps ActionView::Helpers::FormOptionsHelper#collection_checkboxes for form builders:
|
|
904
909
|
#
|
|
905
|
-
# <%=
|
|
906
|
-
# <%= f.
|
|
910
|
+
# <%= form_with model: @post do |f| %>
|
|
911
|
+
# <%= f.collection_checkboxes :author_ids, Author.all, :id, :name_with_initial %>
|
|
907
912
|
# <%= f.submit %>
|
|
908
913
|
# <% end %>
|
|
909
914
|
#
|
|
910
915
|
# Please refer to the documentation of the base helper for details.
|
|
911
|
-
def
|
|
912
|
-
@template.
|
|
916
|
+
def collection_checkboxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
|
917
|
+
@template.collection_checkboxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options), &block)
|
|
913
918
|
end
|
|
919
|
+
alias_method :collection_check_boxes, :collection_checkboxes
|
|
914
920
|
|
|
915
921
|
# Wraps ActionView::Helpers::FormOptionsHelper#collection_radio_buttons for form builders:
|
|
916
922
|
#
|
|
917
|
-
# <%=
|
|
923
|
+
# <%= form_with model: @post do |f| %>
|
|
918
924
|
# <%= f.collection_radio_buttons :author_id, Author.all, :id, :name_with_initial %>
|
|
919
925
|
# <%= f.submit %>
|
|
920
926
|
# <% end %>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "cgi"
|
|
4
3
|
require "action_view/helpers/content_exfiltration_prevention_helper"
|
|
5
4
|
require "action_view/helpers/url_helper"
|
|
6
5
|
require "action_view/helpers/text_helper"
|
|
@@ -306,7 +305,11 @@ module ActionView
|
|
|
306
305
|
# # => <input type="hidden" name="collected_input" id="collected_input"
|
|
307
306
|
# value="" onchange="alert('Input collected!')" autocomplete="off" />
|
|
308
307
|
def hidden_field_tag(name, value = nil, options = {})
|
|
309
|
-
|
|
308
|
+
html_options = options.merge(type: :hidden)
|
|
309
|
+
unless ActionView::Base.remove_hidden_field_autocomplete
|
|
310
|
+
html_options[:autocomplete] = "off" unless html_options.key?(:autocomplete)
|
|
311
|
+
end
|
|
312
|
+
text_field_tag(name, value, html_options)
|
|
310
313
|
end
|
|
311
314
|
|
|
312
315
|
# Creates a file upload field. If you are using file uploads then you will also need
|
|
@@ -393,24 +396,24 @@ module ActionView
|
|
|
393
396
|
# * Any other key creates standard HTML attributes for the tag.
|
|
394
397
|
#
|
|
395
398
|
# ==== Examples
|
|
396
|
-
#
|
|
399
|
+
# textarea_tag 'post'
|
|
397
400
|
# # => <textarea id="post" name="post"></textarea>
|
|
398
401
|
#
|
|
399
|
-
#
|
|
402
|
+
# textarea_tag 'bio', @user.bio
|
|
400
403
|
# # => <textarea id="bio" name="bio">This is my biography.</textarea>
|
|
401
404
|
#
|
|
402
|
-
#
|
|
405
|
+
# textarea_tag 'body', nil, rows: 10, cols: 25
|
|
403
406
|
# # => <textarea cols="25" id="body" name="body" rows="10"></textarea>
|
|
404
407
|
#
|
|
405
|
-
#
|
|
408
|
+
# textarea_tag 'body', nil, size: "25x10"
|
|
406
409
|
# # => <textarea name="body" id="body" cols="25" rows="10"></textarea>
|
|
407
410
|
#
|
|
408
|
-
#
|
|
411
|
+
# textarea_tag 'description', "Description goes here.", disabled: true
|
|
409
412
|
# # => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
|
|
410
413
|
#
|
|
411
|
-
#
|
|
414
|
+
# textarea_tag 'comment', nil, class: 'comment_input'
|
|
412
415
|
# # => <textarea class="comment_input" id="comment" name="comment"></textarea>
|
|
413
|
-
def
|
|
416
|
+
def textarea_tag(name, content = nil, options = {})
|
|
414
417
|
options = options.stringify_keys
|
|
415
418
|
|
|
416
419
|
if size = options.delete("size")
|
|
@@ -422,12 +425,13 @@ module ActionView
|
|
|
422
425
|
|
|
423
426
|
content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)
|
|
424
427
|
end
|
|
428
|
+
alias_method :text_area_tag, :textarea_tag
|
|
425
429
|
|
|
426
430
|
##
|
|
427
431
|
# :call-seq:
|
|
428
|
-
#
|
|
429
|
-
#
|
|
430
|
-
#
|
|
432
|
+
# checkbox_tag(name, options = {})
|
|
433
|
+
# checkbox_tag(name, value, options = {})
|
|
434
|
+
# checkbox_tag(name, value, checked, options = {})
|
|
431
435
|
#
|
|
432
436
|
# Creates a check box form input tag.
|
|
433
437
|
#
|
|
@@ -438,21 +442,21 @@ module ActionView
|
|
|
438
442
|
# * Any other key creates standard HTML options for the tag.
|
|
439
443
|
#
|
|
440
444
|
# ==== Examples
|
|
441
|
-
#
|
|
445
|
+
# checkbox_tag 'accept'
|
|
442
446
|
# # => <input id="accept" name="accept" type="checkbox" value="1" />
|
|
443
447
|
#
|
|
444
|
-
#
|
|
448
|
+
# checkbox_tag 'rock', 'rock music'
|
|
445
449
|
# # => <input id="rock" name="rock" type="checkbox" value="rock music" />
|
|
446
450
|
#
|
|
447
|
-
#
|
|
451
|
+
# checkbox_tag 'receive_email', 'yes', true
|
|
448
452
|
# # => <input checked="checked" id="receive_email" name="receive_email" type="checkbox" value="yes" />
|
|
449
453
|
#
|
|
450
|
-
#
|
|
454
|
+
# checkbox_tag 'tos', 'yes', false, class: 'accept_tos'
|
|
451
455
|
# # => <input class="accept_tos" id="tos" name="tos" type="checkbox" value="yes" />
|
|
452
456
|
#
|
|
453
|
-
#
|
|
457
|
+
# checkbox_tag 'eula', 'accepted', false, disabled: true
|
|
454
458
|
# # => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" />
|
|
455
|
-
def
|
|
459
|
+
def checkbox_tag(name, *args)
|
|
456
460
|
if args.length >= 4
|
|
457
461
|
raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 1..4)"
|
|
458
462
|
end
|
|
@@ -462,6 +466,7 @@ module ActionView
|
|
|
462
466
|
html_options["checked"] = "checked" if checked
|
|
463
467
|
tag :input, html_options
|
|
464
468
|
end
|
|
469
|
+
alias_method :check_box_tag, :checkbox_tag
|
|
465
470
|
|
|
466
471
|
##
|
|
467
472
|
# :call-seq:
|
|
@@ -974,10 +979,15 @@ module ActionView
|
|
|
974
979
|
# Creates the hidden UTF-8 enforcer tag. Override this method in a helper
|
|
975
980
|
# to customize the tag.
|
|
976
981
|
def utf8_enforcer_tag
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
982
|
+
options = {
|
|
983
|
+
type: "hidden",
|
|
984
|
+
name: "utf8",
|
|
985
|
+
value: "✓".html_safe
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
options[:autocomplete] = "off" unless ActionView::Base.remove_hidden_field_autocomplete
|
|
989
|
+
|
|
990
|
+
tag(:input, options)
|
|
981
991
|
end
|
|
982
992
|
|
|
983
993
|
private
|
|
@@ -1045,9 +1055,9 @@ module ActionView
|
|
|
1045
1055
|
end
|
|
1046
1056
|
|
|
1047
1057
|
def form_tag_with_body(html_options, content)
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1058
|
+
extra_tags = extra_tags_for_form(html_options)
|
|
1059
|
+
html = content_tag(:form, safe_join([extra_tags, content]), html_options)
|
|
1060
|
+
prevent_content_exfiltration(html)
|
|
1051
1061
|
end
|
|
1052
1062
|
|
|
1053
1063
|
# see http://www.w3.org/TR/html4/types.html#type-name
|
|
@@ -4,6 +4,8 @@ module ActionView
|
|
|
4
4
|
module Helpers # :nodoc:
|
|
5
5
|
# = Action View JavaScript \Helpers
|
|
6
6
|
module JavaScriptHelper
|
|
7
|
+
mattr_accessor :auto_include_nonce
|
|
8
|
+
|
|
7
9
|
JS_ESCAPE_MAP = {
|
|
8
10
|
"\\" => "\\\\",
|
|
9
11
|
"</" => '<\/',
|
|
@@ -81,8 +83,10 @@ module ActionView
|
|
|
81
83
|
content_or_options_with_block
|
|
82
84
|
end
|
|
83
85
|
|
|
84
|
-
if html_options[:nonce] == true
|
|
86
|
+
if html_options[:nonce] == true || (!html_options.key?(:nonce) && auto_include_nonce)
|
|
85
87
|
html_options[:nonce] = content_security_policy_nonce
|
|
88
|
+
elsif html_options[:nonce] == false
|
|
89
|
+
html_options.delete(:nonce)
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
content_tag("script", javascript_cdata_section(content), html_options)
|
|
@@ -26,6 +26,8 @@ module ActionView
|
|
|
26
26
|
|
|
27
27
|
# Delegates to ActiveSupport::NumberHelper#number_to_phone.
|
|
28
28
|
#
|
|
29
|
+
# number_to_phone("1234567890") # => "123-456-7890"
|
|
30
|
+
#
|
|
29
31
|
# Additionally, supports a +:raise+ option that will cause
|
|
30
32
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
31
33
|
#
|
|
@@ -42,6 +44,8 @@ module ActionView
|
|
|
42
44
|
|
|
43
45
|
# Delegates to ActiveSupport::NumberHelper#number_to_currency.
|
|
44
46
|
#
|
|
47
|
+
# number_to_currency("1234") # => "$1234.00"
|
|
48
|
+
#
|
|
45
49
|
# Additionally, supports a +:raise+ option that will cause
|
|
46
50
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
47
51
|
#
|
|
@@ -54,6 +58,8 @@ module ActionView
|
|
|
54
58
|
|
|
55
59
|
# Delegates to ActiveSupport::NumberHelper#number_to_percentage.
|
|
56
60
|
#
|
|
61
|
+
# number_to_percentage("99") # => "99.000%"
|
|
62
|
+
#
|
|
57
63
|
# Additionally, supports a +:raise+ option that will cause
|
|
58
64
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
59
65
|
#
|
|
@@ -66,6 +72,8 @@ module ActionView
|
|
|
66
72
|
|
|
67
73
|
# Delegates to ActiveSupport::NumberHelper#number_to_delimited.
|
|
68
74
|
#
|
|
75
|
+
# number_with_delimiter("1234") # => "1,234"
|
|
76
|
+
#
|
|
69
77
|
# Additionally, supports a +:raise+ option that will cause
|
|
70
78
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
71
79
|
#
|
|
@@ -78,6 +86,8 @@ module ActionView
|
|
|
78
86
|
|
|
79
87
|
# Delegates to ActiveSupport::NumberHelper#number_to_rounded.
|
|
80
88
|
#
|
|
89
|
+
# number_with_precision("1234") # => "1234.000"
|
|
90
|
+
#
|
|
81
91
|
# Additionally, supports a +:raise+ option that will cause
|
|
82
92
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
83
93
|
#
|
|
@@ -90,6 +100,8 @@ module ActionView
|
|
|
90
100
|
|
|
91
101
|
# Delegates to ActiveSupport::NumberHelper#number_to_human_size.
|
|
92
102
|
#
|
|
103
|
+
# number_to_human_size("1234") # => "1.21 KB"
|
|
104
|
+
#
|
|
93
105
|
# Additionally, supports a +:raise+ option that will cause
|
|
94
106
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
95
107
|
#
|
|
@@ -102,6 +114,8 @@ module ActionView
|
|
|
102
114
|
|
|
103
115
|
# Delegates to ActiveSupport::NumberHelper#number_to_human.
|
|
104
116
|
#
|
|
117
|
+
# number_to_human("1234") # => "1.23 Thousand"
|
|
118
|
+
#
|
|
105
119
|
# Additionally, supports a +:raise+ option that will cause
|
|
106
120
|
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
107
121
|
#
|