actionview 6.0.0

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 (113) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +271 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +40 -0
  5. data/lib/action_view.rb +98 -0
  6. data/lib/action_view/base.rb +312 -0
  7. data/lib/action_view/buffers.rb +67 -0
  8. data/lib/action_view/cache_expiry.rb +54 -0
  9. data/lib/action_view/context.rb +32 -0
  10. data/lib/action_view/dependency_tracker.rb +175 -0
  11. data/lib/action_view/digestor.rb +126 -0
  12. data/lib/action_view/flows.rb +76 -0
  13. data/lib/action_view/gem_version.rb +17 -0
  14. data/lib/action_view/helpers.rb +66 -0
  15. data/lib/action_view/helpers/active_model_helper.rb +55 -0
  16. data/lib/action_view/helpers/asset_tag_helper.rb +488 -0
  17. data/lib/action_view/helpers/asset_url_helper.rb +470 -0
  18. data/lib/action_view/helpers/atom_feed_helper.rb +205 -0
  19. data/lib/action_view/helpers/cache_helper.rb +271 -0
  20. data/lib/action_view/helpers/capture_helper.rb +216 -0
  21. data/lib/action_view/helpers/controller_helper.rb +36 -0
  22. data/lib/action_view/helpers/csp_helper.rb +26 -0
  23. data/lib/action_view/helpers/csrf_helper.rb +35 -0
  24. data/lib/action_view/helpers/date_helper.rb +1200 -0
  25. data/lib/action_view/helpers/debug_helper.rb +36 -0
  26. data/lib/action_view/helpers/form_helper.rb +2569 -0
  27. data/lib/action_view/helpers/form_options_helper.rb +896 -0
  28. data/lib/action_view/helpers/form_tag_helper.rb +920 -0
  29. data/lib/action_view/helpers/javascript_helper.rb +95 -0
  30. data/lib/action_view/helpers/number_helper.rb +456 -0
  31. data/lib/action_view/helpers/output_safety_helper.rb +70 -0
  32. data/lib/action_view/helpers/rendering_helper.rb +101 -0
  33. data/lib/action_view/helpers/sanitize_helper.rb +171 -0
  34. data/lib/action_view/helpers/tag_helper.rb +314 -0
  35. data/lib/action_view/helpers/tags.rb +44 -0
  36. data/lib/action_view/helpers/tags/base.rb +196 -0
  37. data/lib/action_view/helpers/tags/check_box.rb +66 -0
  38. data/lib/action_view/helpers/tags/checkable.rb +18 -0
  39. data/lib/action_view/helpers/tags/collection_check_boxes.rb +36 -0
  40. data/lib/action_view/helpers/tags/collection_helpers.rb +119 -0
  41. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +31 -0
  42. data/lib/action_view/helpers/tags/collection_select.rb +30 -0
  43. data/lib/action_view/helpers/tags/color_field.rb +27 -0
  44. data/lib/action_view/helpers/tags/date_field.rb +15 -0
  45. data/lib/action_view/helpers/tags/date_select.rb +74 -0
  46. data/lib/action_view/helpers/tags/datetime_field.rb +32 -0
  47. data/lib/action_view/helpers/tags/datetime_local_field.rb +21 -0
  48. data/lib/action_view/helpers/tags/datetime_select.rb +10 -0
  49. data/lib/action_view/helpers/tags/email_field.rb +10 -0
  50. data/lib/action_view/helpers/tags/file_field.rb +10 -0
  51. data/lib/action_view/helpers/tags/grouped_collection_select.rb +31 -0
  52. data/lib/action_view/helpers/tags/hidden_field.rb +10 -0
  53. data/lib/action_view/helpers/tags/label.rb +81 -0
  54. data/lib/action_view/helpers/tags/month_field.rb +15 -0
  55. data/lib/action_view/helpers/tags/number_field.rb +20 -0
  56. data/lib/action_view/helpers/tags/password_field.rb +14 -0
  57. data/lib/action_view/helpers/tags/placeholderable.rb +24 -0
  58. data/lib/action_view/helpers/tags/radio_button.rb +33 -0
  59. data/lib/action_view/helpers/tags/range_field.rb +10 -0
  60. data/lib/action_view/helpers/tags/search_field.rb +27 -0
  61. data/lib/action_view/helpers/tags/select.rb +43 -0
  62. data/lib/action_view/helpers/tags/tel_field.rb +10 -0
  63. data/lib/action_view/helpers/tags/text_area.rb +24 -0
  64. data/lib/action_view/helpers/tags/text_field.rb +34 -0
  65. data/lib/action_view/helpers/tags/time_field.rb +15 -0
  66. data/lib/action_view/helpers/tags/time_select.rb +10 -0
  67. data/lib/action_view/helpers/tags/time_zone_select.rb +22 -0
  68. data/lib/action_view/helpers/tags/translator.rb +39 -0
  69. data/lib/action_view/helpers/tags/url_field.rb +10 -0
  70. data/lib/action_view/helpers/tags/week_field.rb +15 -0
  71. data/lib/action_view/helpers/text_helper.rb +486 -0
  72. data/lib/action_view/helpers/translation_helper.rb +145 -0
  73. data/lib/action_view/helpers/url_helper.rb +676 -0
  74. data/lib/action_view/layouts.rb +433 -0
  75. data/lib/action_view/locale/en.yml +56 -0
  76. data/lib/action_view/log_subscriber.rb +96 -0
  77. data/lib/action_view/lookup_context.rb +316 -0
  78. data/lib/action_view/model_naming.rb +14 -0
  79. data/lib/action_view/path_set.rb +95 -0
  80. data/lib/action_view/railtie.rb +105 -0
  81. data/lib/action_view/record_identifier.rb +112 -0
  82. data/lib/action_view/renderer/abstract_renderer.rb +108 -0
  83. data/lib/action_view/renderer/partial_renderer.rb +563 -0
  84. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
  85. data/lib/action_view/renderer/renderer.rb +68 -0
  86. data/lib/action_view/renderer/streaming_template_renderer.rb +105 -0
  87. data/lib/action_view/renderer/template_renderer.rb +108 -0
  88. data/lib/action_view/rendering.rb +171 -0
  89. data/lib/action_view/routing_url_for.rb +146 -0
  90. data/lib/action_view/tasks/cache_digests.rake +25 -0
  91. data/lib/action_view/template.rb +393 -0
  92. data/lib/action_view/template/error.rb +161 -0
  93. data/lib/action_view/template/handlers.rb +92 -0
  94. data/lib/action_view/template/handlers/builder.rb +25 -0
  95. data/lib/action_view/template/handlers/erb.rb +84 -0
  96. data/lib/action_view/template/handlers/erb/erubi.rb +87 -0
  97. data/lib/action_view/template/handlers/html.rb +11 -0
  98. data/lib/action_view/template/handlers/raw.rb +11 -0
  99. data/lib/action_view/template/html.rb +43 -0
  100. data/lib/action_view/template/inline.rb +22 -0
  101. data/lib/action_view/template/raw_file.rb +28 -0
  102. data/lib/action_view/template/resolver.rb +394 -0
  103. data/lib/action_view/template/sources.rb +13 -0
  104. data/lib/action_view/template/sources/file.rb +17 -0
  105. data/lib/action_view/template/text.rb +35 -0
  106. data/lib/action_view/template/types.rb +57 -0
  107. data/lib/action_view/test_case.rb +300 -0
  108. data/lib/action_view/testing/resolvers.rb +67 -0
  109. data/lib/action_view/unbound_template.rb +32 -0
  110. data/lib/action_view/version.rb +10 -0
  111. data/lib/action_view/view_paths.rb +129 -0
  112. data/lib/assets/compiled/rails-ujs.js +746 -0
  113. metadata +260 -0
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view/helpers/tags/collection_helpers"
4
+
5
+ module ActionView
6
+ module Helpers
7
+ module Tags # :nodoc:
8
+ class CollectionRadioButtons < Base # :nodoc:
9
+ include CollectionHelpers
10
+
11
+ class RadioButtonBuilder < Builder # :nodoc:
12
+ def radio_button(extra_html_options = {})
13
+ html_options = extra_html_options.merge(@input_html_options)
14
+ html_options[:skip_default_ids] = false
15
+ @template_object.radio_button(@object_name, @method_name, @value, html_options)
16
+ end
17
+ end
18
+
19
+ def render(&block)
20
+ render_collection_for(RadioButtonBuilder, &block)
21
+ end
22
+
23
+ private
24
+
25
+ def render_component(builder)
26
+ builder.radio_button + builder.label
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class CollectionSelect < Base #:nodoc:
7
+ def initialize(object_name, method_name, template_object, collection, value_method, text_method, options, html_options)
8
+ @collection = collection
9
+ @value_method = value_method
10
+ @text_method = text_method
11
+ @html_options = html_options
12
+
13
+ super(object_name, method_name, template_object, options)
14
+ end
15
+
16
+ def render
17
+ option_tags_options = {
18
+ selected: @options.fetch(:selected) { value },
19
+ disabled: @options[:disabled]
20
+ }
21
+
22
+ select_content_tag(
23
+ options_from_collection_for_select(@collection, @value_method, @text_method, option_tags_options),
24
+ @options, @html_options
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class ColorField < TextField # :nodoc:
7
+ def render
8
+ options = @options.stringify_keys
9
+ options["value"] ||= validate_color_string(value)
10
+ @options = options
11
+ super
12
+ end
13
+
14
+ private
15
+
16
+ def validate_color_string(string)
17
+ regex = /#[0-9a-fA-F]{6}/
18
+ if regex.match?(string)
19
+ string.downcase
20
+ else
21
+ "#000000"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class DateField < DatetimeField # :nodoc:
7
+ private
8
+
9
+ def format_date(value)
10
+ value.try(:strftime, "%Y-%m-%d")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/time/calculations"
4
+
5
+ module ActionView
6
+ module Helpers
7
+ module Tags # :nodoc:
8
+ class DateSelect < Base # :nodoc:
9
+ def initialize(object_name, method_name, template_object, options, html_options)
10
+ @html_options = html_options
11
+
12
+ super(object_name, method_name, template_object, options)
13
+ end
14
+
15
+ def render
16
+ error_wrapping(datetime_selector(@options, @html_options).send("select_#{select_type}").html_safe)
17
+ end
18
+
19
+ class << self
20
+ def select_type
21
+ @select_type ||= name.split("::").last.sub("Select", "").downcase
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def select_type
28
+ self.class.select_type
29
+ end
30
+
31
+ def datetime_selector(options, html_options)
32
+ datetime = options.fetch(:selected) { value || default_datetime(options) }
33
+ @auto_index ||= nil
34
+
35
+ options = options.dup
36
+ options[:field_name] = @method_name
37
+ options[:include_position] = true
38
+ options[:prefix] ||= @object_name
39
+ options[:index] = @auto_index if @auto_index && !options.has_key?(:index)
40
+
41
+ DateTimeSelector.new(datetime, options, html_options)
42
+ end
43
+
44
+ def default_datetime(options)
45
+ return if options[:include_blank] || options[:prompt]
46
+
47
+ case options[:default]
48
+ when nil
49
+ Time.current
50
+ when Date, Time
51
+ options[:default]
52
+ else
53
+ default = options[:default].dup
54
+
55
+ # Rename :minute and :second to :min and :sec
56
+ default[:min] ||= default[:minute]
57
+ default[:sec] ||= default[:second]
58
+
59
+ time = Time.current
60
+
61
+ [:year, :month, :day, :hour, :min, :sec].each do |key|
62
+ default[key] ||= time.send(key)
63
+ end
64
+
65
+ Time.utc(
66
+ default[:year], default[:month], default[:day],
67
+ default[:hour], default[:min], default[:sec]
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class DatetimeField < TextField # :nodoc:
7
+ def render
8
+ options = @options.stringify_keys
9
+ options["value"] ||= format_date(value)
10
+ options["min"] = format_date(datetime_value(options["min"]))
11
+ options["max"] = format_date(datetime_value(options["max"]))
12
+ @options = options
13
+ super
14
+ end
15
+
16
+ private
17
+
18
+ def format_date(value)
19
+ raise NotImplementedError
20
+ end
21
+
22
+ def datetime_value(value)
23
+ if value.is_a? String
24
+ DateTime.parse(value) rescue nil
25
+ else
26
+ value
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class DatetimeLocalField < DatetimeField # :nodoc:
7
+ class << self
8
+ def field_type
9
+ @field_type ||= "datetime-local"
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def format_date(value)
16
+ value.try(:strftime, "%Y-%m-%dT%T")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class DatetimeSelect < DateSelect # :nodoc:
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class EmailField < TextField # :nodoc:
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class FileField < TextField # :nodoc:
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class GroupedCollectionSelect < Base # :nodoc:
7
+ def initialize(object_name, method_name, template_object, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
8
+ @collection = collection
9
+ @group_method = group_method
10
+ @group_label_method = group_label_method
11
+ @option_key_method = option_key_method
12
+ @option_value_method = option_value_method
13
+ @html_options = html_options
14
+
15
+ super(object_name, method_name, template_object, options)
16
+ end
17
+
18
+ def render
19
+ option_tags_options = {
20
+ selected: @options.fetch(:selected) { value },
21
+ disabled: @options[:disabled]
22
+ }
23
+
24
+ select_content_tag(
25
+ option_groups_from_collection_for_select(@collection, @group_method, @group_label_method, @option_key_method, @option_value_method, option_tags_options), @options, @html_options
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class HiddenField < TextField # :nodoc:
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class Label < Base # :nodoc:
7
+ class LabelBuilder # :nodoc:
8
+ attr_reader :object
9
+
10
+ def initialize(template_object, object_name, method_name, object, tag_value)
11
+ @template_object = template_object
12
+ @object_name = object_name
13
+ @method_name = method_name
14
+ @object = object
15
+ @tag_value = tag_value
16
+ end
17
+
18
+ def translation
19
+ method_and_value = @tag_value.present? ? "#{@method_name}.#{@tag_value}" : @method_name
20
+
21
+ content ||= Translator
22
+ .new(object, @object_name, method_and_value, scope: "helpers.label")
23
+ .translate
24
+ content ||= @method_name.humanize
25
+
26
+ content
27
+ end
28
+ end
29
+
30
+ def initialize(object_name, method_name, template_object, content_or_options = nil, options = nil)
31
+ options ||= {}
32
+
33
+ content_is_options = content_or_options.is_a?(Hash)
34
+ if content_is_options
35
+ options.merge! content_or_options
36
+ @content = nil
37
+ else
38
+ @content = content_or_options
39
+ end
40
+
41
+ super(object_name, method_name, template_object, options)
42
+ end
43
+
44
+ def render(&block)
45
+ options = @options.stringify_keys
46
+ tag_value = options.delete("value")
47
+ name_and_id = options.dup
48
+
49
+ if name_and_id["for"]
50
+ name_and_id["id"] = name_and_id["for"]
51
+ else
52
+ name_and_id.delete("id")
53
+ end
54
+
55
+ add_default_name_and_id_for_value(tag_value, name_and_id)
56
+ options.delete("index")
57
+ options.delete("namespace")
58
+ options["for"] = name_and_id["id"] unless options.key?("for")
59
+
60
+ builder = LabelBuilder.new(@template_object, @object_name, @method_name, @object, tag_value)
61
+
62
+ content = if block_given?
63
+ @template_object.capture(builder, &block)
64
+ elsif @content.present?
65
+ @content.to_s
66
+ else
67
+ render_component(builder)
68
+ end
69
+
70
+ label_tag(name_and_id["id"], content, options)
71
+ end
72
+
73
+ private
74
+
75
+ def render_component(builder)
76
+ builder.translation
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class MonthField < DatetimeField # :nodoc:
7
+ private
8
+
9
+ def format_date(value)
10
+ value.try(:strftime, "%Y-%m")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class NumberField < TextField # :nodoc:
7
+ def render
8
+ options = @options.stringify_keys
9
+
10
+ if range = options.delete("in") || options.delete("within")
11
+ options.update("min" => range.min, "max" => range.max)
12
+ end
13
+
14
+ @options = options
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class PasswordField < TextField # :nodoc:
7
+ def render
8
+ @options = { value: nil }.merge!(@options)
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end