actionview 4.2.11.1 → 7.0.2.4

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 (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +229 -215
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +9 -8
  5. data/lib/action_view/base.rb +116 -43
  6. data/lib/action_view/buffers.rb +20 -3
  7. data/lib/action_view/cache_expiry.rb +66 -0
  8. data/lib/action_view/context.rb +8 -12
  9. data/lib/action_view/dependency_tracker/erb_tracker.rb +154 -0
  10. data/lib/action_view/dependency_tracker/ripper_tracker.rb +59 -0
  11. data/lib/action_view/dependency_tracker.rb +21 -122
  12. data/lib/action_view/digestor.rb +92 -85
  13. data/lib/action_view/flows.rb +15 -16
  14. data/lib/action_view/gem_version.rb +6 -4
  15. data/lib/action_view/helpers/active_model_helper.rb +17 -12
  16. data/lib/action_view/helpers/asset_tag_helper.rb +356 -101
  17. data/lib/action_view/helpers/asset_url_helper.rb +180 -74
  18. data/lib/action_view/helpers/atom_feed_helper.rb +21 -19
  19. data/lib/action_view/helpers/cache_helper.rb +156 -43
  20. data/lib/action_view/helpers/capture_helper.rb +21 -14
  21. data/lib/action_view/helpers/controller_helper.rb +16 -5
  22. data/lib/action_view/helpers/csp_helper.rb +26 -0
  23. data/lib/action_view/helpers/csrf_helper.rb +8 -6
  24. data/lib/action_view/helpers/date_helper.rb +288 -132
  25. data/lib/action_view/helpers/debug_helper.rb +9 -6
  26. data/lib/action_view/helpers/form_helper.rb +956 -173
  27. data/lib/action_view/helpers/form_options_helper.rb +178 -97
  28. data/lib/action_view/helpers/form_tag_helper.rb +220 -101
  29. data/lib/action_view/helpers/javascript_helper.rb +33 -19
  30. data/lib/action_view/helpers/number_helper.rb +88 -63
  31. data/lib/action_view/helpers/output_safety_helper.rb +38 -6
  32. data/lib/action_view/helpers/rendering_helper.rb +21 -10
  33. data/lib/action_view/helpers/sanitize_helper.rb +31 -32
  34. data/lib/action_view/helpers/tag_helper.rb +332 -71
  35. data/lib/action_view/helpers/tags/base.rb +123 -99
  36. data/lib/action_view/helpers/tags/check_box.rb +21 -20
  37. data/lib/action_view/helpers/tags/checkable.rb +4 -2
  38. data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -34
  39. data/lib/action_view/helpers/tags/collection_helpers.rb +69 -36
  40. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -12
  41. data/lib/action_view/helpers/tags/collection_select.rb +5 -3
  42. data/lib/action_view/helpers/tags/color_field.rb +4 -3
  43. data/lib/action_view/helpers/tags/date_field.rb +3 -2
  44. data/lib/action_view/helpers/tags/date_select.rb +38 -37
  45. data/lib/action_view/helpers/tags/datetime_field.rb +4 -3
  46. data/lib/action_view/helpers/tags/datetime_local_field.rb +3 -2
  47. data/lib/action_view/helpers/tags/datetime_select.rb +2 -0
  48. data/lib/action_view/helpers/tags/email_field.rb +2 -0
  49. data/lib/action_view/helpers/tags/file_field.rb +18 -0
  50. data/lib/action_view/helpers/tags/grouped_collection_select.rb +4 -2
  51. data/lib/action_view/helpers/tags/hidden_field.rb +6 -0
  52. data/lib/action_view/helpers/tags/label.rb +7 -2
  53. data/lib/action_view/helpers/tags/month_field.rb +3 -2
  54. data/lib/action_view/helpers/tags/number_field.rb +2 -0
  55. data/lib/action_view/helpers/tags/password_field.rb +3 -1
  56. data/lib/action_view/helpers/tags/placeholderable.rb +3 -1
  57. data/lib/action_view/helpers/tags/radio_button.rb +7 -6
  58. data/lib/action_view/helpers/tags/range_field.rb +2 -0
  59. data/lib/action_view/helpers/tags/search_field.rb +14 -9
  60. data/lib/action_view/helpers/tags/select.rb +11 -10
  61. data/lib/action_view/helpers/tags/tel_field.rb +2 -0
  62. data/lib/action_view/helpers/tags/text_area.rb +4 -2
  63. data/lib/action_view/helpers/tags/text_field.rb +8 -8
  64. data/lib/action_view/helpers/tags/time_field.rb +12 -2
  65. data/lib/action_view/helpers/tags/time_select.rb +2 -0
  66. data/lib/action_view/helpers/tags/time_zone_select.rb +3 -1
  67. data/lib/action_view/helpers/tags/translator.rb +15 -16
  68. data/lib/action_view/helpers/tags/url_field.rb +2 -0
  69. data/lib/action_view/helpers/tags/week_field.rb +3 -2
  70. data/lib/action_view/helpers/tags/weekday_select.rb +28 -0
  71. data/lib/action_view/helpers/tags.rb +5 -2
  72. data/lib/action_view/helpers/text_helper.rb +80 -51
  73. data/lib/action_view/helpers/translation_helper.rb +120 -69
  74. data/lib/action_view/helpers/url_helper.rb +398 -171
  75. data/lib/action_view/helpers.rb +29 -27
  76. data/lib/action_view/layouts.rb +68 -63
  77. data/lib/action_view/log_subscriber.rb +77 -10
  78. data/lib/action_view/lookup_context.rb +137 -113
  79. data/lib/action_view/model_naming.rb +4 -2
  80. data/lib/action_view/path_set.rb +28 -32
  81. data/lib/action_view/railtie.rb +74 -13
  82. data/lib/action_view/record_identifier.rb +53 -26
  83. data/lib/action_view/render_parser.rb +188 -0
  84. data/lib/action_view/renderer/abstract_renderer.rb +152 -15
  85. data/lib/action_view/renderer/collection_renderer.rb +196 -0
  86. data/lib/action_view/renderer/object_renderer.rb +34 -0
  87. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +102 -0
  88. data/lib/action_view/renderer/partial_renderer.rb +51 -333
  89. data/lib/action_view/renderer/renderer.rb +68 -11
  90. data/lib/action_view/renderer/streaming_template_renderer.rb +60 -56
  91. data/lib/action_view/renderer/template_renderer.rb +87 -74
  92. data/lib/action_view/rendering.rb +73 -47
  93. data/lib/action_view/ripper_ast_parser.rb +198 -0
  94. data/lib/action_view/routing_url_for.rb +35 -24
  95. data/lib/action_view/tasks/cache_digests.rake +25 -0
  96. data/lib/action_view/template/error.rb +151 -41
  97. data/lib/action_view/template/handlers/builder.rb +12 -13
  98. data/lib/action_view/template/handlers/erb/erubi.rb +89 -0
  99. data/lib/action_view/template/handlers/erb.rb +29 -89
  100. data/lib/action_view/template/handlers/html.rb +11 -0
  101. data/lib/action_view/template/handlers/raw.rb +4 -4
  102. data/lib/action_view/template/handlers.rb +14 -10
  103. data/lib/action_view/template/html.rb +12 -13
  104. data/lib/action_view/template/inline.rb +22 -0
  105. data/lib/action_view/template/raw_file.rb +25 -0
  106. data/lib/action_view/template/renderable.rb +24 -0
  107. data/lib/action_view/template/resolver.rb +139 -300
  108. data/lib/action_view/template/sources/file.rb +17 -0
  109. data/lib/action_view/template/sources.rb +13 -0
  110. data/lib/action_view/template/text.rb +10 -12
  111. data/lib/action_view/template/types.rb +28 -26
  112. data/lib/action_view/template.rb +123 -91
  113. data/lib/action_view/template_details.rb +66 -0
  114. data/lib/action_view/template_path.rb +64 -0
  115. data/lib/action_view/test_case.rb +70 -53
  116. data/lib/action_view/testing/resolvers.rb +25 -35
  117. data/lib/action_view/unbound_template.rb +57 -0
  118. data/lib/action_view/version.rb +3 -1
  119. data/lib/action_view/view_paths.rb +73 -58
  120. data/lib/action_view.rb +16 -11
  121. data/lib/assets/compiled/rails-ujs.js +746 -0
  122. metadata +52 -32
  123. data/lib/action_view/helpers/record_tag_helper.rb +0 -108
  124. data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erubi"
4
+
5
+ module ActionView
6
+ class Template
7
+ module Handlers
8
+ class ERB
9
+ class Erubi < ::Erubi::Engine
10
+ # :nodoc: all
11
+ def initialize(input, properties = {})
12
+ @newline_pending = 0
13
+
14
+ # Dup properties so that we don't modify argument
15
+ properties = Hash[properties]
16
+
17
+ properties[:bufvar] ||= "@output_buffer"
18
+ properties[:preamble] ||= ""
19
+ properties[:postamble] ||= "#{properties[:bufvar]}.to_s"
20
+
21
+ properties[:escapefunc] = ""
22
+
23
+ super
24
+ end
25
+
26
+ def evaluate(action_view_erb_handler_context)
27
+ src = @src
28
+ view = Class.new(ActionView::Base) {
29
+ include action_view_erb_handler_context._routes.url_helpers
30
+ class_eval("define_method(:_template) { |local_assigns, output_buffer| #{src} }", defined?(@filename) ? @filename : "(erubi)", 0)
31
+ }.empty
32
+ view._run(:_template, nil, {}, ActionView::OutputBuffer.new)
33
+ end
34
+
35
+ private
36
+ def add_text(text)
37
+ return if text.empty?
38
+
39
+ if text == "\n"
40
+ @newline_pending += 1
41
+ else
42
+ src << bufvar << ".safe_append='"
43
+ src << "\n" * @newline_pending if @newline_pending > 0
44
+ src << text.gsub(/['\\]/, '\\\\\&')
45
+ src << "'.freeze;"
46
+
47
+ @newline_pending = 0
48
+ end
49
+ end
50
+
51
+ BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
52
+
53
+ def add_expression(indicator, code)
54
+ flush_newline_if_pending(src)
55
+
56
+ if (indicator == "==") || @escape
57
+ src << bufvar << ".safe_expr_append="
58
+ else
59
+ src << bufvar << ".append="
60
+ end
61
+
62
+ if BLOCK_EXPR.match?(code)
63
+ src << " " << code
64
+ else
65
+ src << "(" << code << ");"
66
+ end
67
+ end
68
+
69
+ def add_code(code)
70
+ flush_newline_if_pending(src)
71
+ super
72
+ end
73
+
74
+ def add_postamble(_)
75
+ flush_newline_if_pending(src)
76
+ super
77
+ end
78
+
79
+ def flush_newline_if_pending(src)
80
+ if @newline_pending > 0
81
+ src << bufvar << ".safe_append='#{"\n" * @newline_pending}'.freeze;"
82
+ @newline_pending = 0
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,96 +1,28 @@
1
- require 'erubis'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ActionView
4
4
  class Template
5
5
  module Handlers
6
- class Erubis < ::Erubis::Eruby
7
- def add_preamble(src)
8
- @newline_pending = 0
9
- src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
10
- end
11
-
12
- def add_text(src, text)
13
- return if text.empty?
14
-
15
- if text == "\n"
16
- @newline_pending += 1
17
- else
18
- src << "@output_buffer.safe_append='"
19
- src << "\n" * @newline_pending if @newline_pending > 0
20
- src << escape_text(text)
21
- src << "'.freeze;"
22
-
23
- @newline_pending = 0
24
- end
25
- end
26
-
27
- # Erubis toggles <%= and <%== behavior when escaping is enabled.
28
- # We override to always treat <%== as escaped.
29
- def add_expr(src, code, indicator)
30
- case indicator
31
- when '=='
32
- add_expr_escaped(src, code)
33
- else
34
- super
35
- end
36
- end
37
-
38
- BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
39
-
40
- def add_expr_literal(src, code)
41
- flush_newline_if_pending(src)
42
- if code =~ BLOCK_EXPR
43
- src << '@output_buffer.append= ' << code
44
- else
45
- src << '@output_buffer.append=(' << code << ');'
46
- end
47
- end
48
-
49
- def add_expr_escaped(src, code)
50
- flush_newline_if_pending(src)
51
- if code =~ BLOCK_EXPR
52
- src << "@output_buffer.safe_expr_append= " << code
53
- else
54
- src << "@output_buffer.safe_expr_append=(" << code << ");"
55
- end
56
- end
57
-
58
- def add_stmt(src, code)
59
- flush_newline_if_pending(src)
60
- super
61
- end
62
-
63
- def add_postamble(src)
64
- flush_newline_if_pending(src)
65
- src << '@output_buffer.to_s'
66
- end
67
-
68
- def flush_newline_if_pending(src)
69
- if @newline_pending > 0
70
- src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
71
- @newline_pending = 0
72
- end
73
- end
74
- end
75
-
76
6
  class ERB
7
+ autoload :Erubi, "action_view/template/handlers/erb/erubi"
8
+
77
9
  # Specify trim mode for the ERB compiler. Defaults to '-'.
78
10
  # See ERB documentation for suitable values.
79
- class_attribute :erb_trim_mode
80
- self.erb_trim_mode = '-'
11
+ class_attribute :erb_trim_mode, default: "-"
81
12
 
82
13
  # Default implementation used.
83
- class_attribute :erb_implementation
84
- self.erb_implementation = Erubis
14
+ class_attribute :erb_implementation, default: Erubi
85
15
 
86
16
  # Do not escape templates of these mime types.
87
- class_attribute :escape_whitelist
88
- self.escape_whitelist = ["text/plain"]
17
+ class_attribute :escape_ignore_list, default: ["text/plain"]
18
+
19
+ # Strip trailing newlines from rendered output
20
+ class_attribute :strip_trailing_newlines, default: false
89
21
 
90
22
  ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
91
23
 
92
- def self.call(template)
93
- new.call(template)
24
+ def self.call(template, source)
25
+ new.call(template, source)
94
26
  end
95
27
 
96
28
  def supports_streaming?
@@ -101,30 +33,38 @@ module ActionView
101
33
  true
102
34
  end
103
35
 
104
- def call(template)
36
+ def call(template, source)
105
37
  # First, convert to BINARY, so in case the encoding is
106
38
  # wrong, we can still find an encoding tag
107
39
  # (<%# encoding %>) inside the String using a regular
108
40
  # expression
109
- template_source = template.source.dup.force_encoding(Encoding::ASCII_8BIT)
41
+ template_source = source.b
110
42
 
111
- erb = template_source.gsub(ENCODING_TAG, '')
43
+ erb = template_source.gsub(ENCODING_TAG, "")
112
44
  encoding = $2
113
45
 
114
- erb.force_encoding valid_encoding(template.source.dup, encoding)
46
+ erb.force_encoding valid_encoding(source.dup, encoding)
115
47
 
116
48
  # Always make sure we return a String in the default_internal
117
49
  erb.encode!
118
50
 
119
- self.class.erb_implementation.new(
120
- erb,
121
- :escape => (self.class.escape_whitelist.include? template.type),
122
- :trim => (self.class.erb_trim_mode == "-")
123
- ).src
51
+ # Strip trailing newlines from the template if enabled
52
+ erb.chomp! if strip_trailing_newlines
53
+
54
+ options = {
55
+ escape: (self.class.escape_ignore_list.include? template.type),
56
+ trim: (self.class.erb_trim_mode == "-")
57
+ }
58
+
59
+ if ActionView::Base.annotate_rendered_view_with_filenames && template.format == :html
60
+ options[:preamble] = "@output_buffer.safe_append='<!-- BEGIN #{template.short_identifier} -->';"
61
+ options[:postamble] = "@output_buffer.safe_append='<!-- END #{template.short_identifier} -->';@output_buffer.to_s"
62
+ end
63
+
64
+ self.class.erb_implementation.new(erb, options).src
124
65
  end
125
66
 
126
67
  private
127
-
128
68
  def valid_encoding(string, encoding)
129
69
  # If a magic encoding comment was found, tag the
130
70
  # String with this encoding. This is for a case
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Template::Handlers
5
+ class Html < Raw
6
+ def call(template, source)
7
+ "ActionView::OutputBuffer.new #{super}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionView
2
4
  module Template::Handlers
3
5
  class Raw
4
- def call(template)
5
- escaped = template.source.gsub(/:/, '\:')
6
-
7
- '%q:' + escaped + ':;'
6
+ def call(template, source)
7
+ "#{source.inspect}.html_safe;"
8
8
  end
9
9
  end
10
10
  end
@@ -1,16 +1,20 @@
1
- module ActionView #:nodoc:
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView # :nodoc:
2
4
  # = Action View Template Handlers
3
- class Template
4
- module Handlers #:nodoc:
5
- autoload :ERB, 'action_view/template/handlers/erb'
6
- autoload :Builder, 'action_view/template/handlers/builder'
7
- autoload :Raw, 'action_view/template/handlers/raw'
5
+ class Template # :nodoc:
6
+ module Handlers # :nodoc:
7
+ autoload :Raw, "action_view/template/handlers/raw"
8
+ autoload :ERB, "action_view/template/handlers/erb"
9
+ autoload :Html, "action_view/template/handlers/html"
10
+ autoload :Builder, "action_view/template/handlers/builder"
8
11
 
9
12
  def self.extended(base)
10
- base.register_default_template_handler :erb, ERB.new
13
+ base.register_default_template_handler :raw, Raw.new
14
+ base.register_template_handler :erb, ERB.new
15
+ base.register_template_handler :html, Html.new
11
16
  base.register_template_handler :builder, Builder.new
12
- base.register_template_handler :raw, Raw.new
13
- base.register_template_handler :ruby, :source.to_proc
17
+ base.register_template_handler :ruby, lambda { |_, source| source }
14
18
  end
15
19
 
16
20
  @@template_handlers = {}
@@ -42,7 +46,7 @@ module ActionView #:nodoc:
42
46
  end
43
47
 
44
48
  def template_handler_extensions
45
- @@template_handlers.keys.map {|key| key.to_s }.sort
49
+ @@template_handlers.keys.map(&:to_s).sort
46
50
  end
47
51
 
48
52
  def registered_template_handler(extension)
@@ -1,22 +1,21 @@
1
- module ActionView #:nodoc:
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView # :nodoc:
2
4
  # = Action View HTML Template
3
- class Template
4
- class HTML #:nodoc:
5
- attr_accessor :type
5
+ class Template # :nodoc:
6
+ class HTML # :nodoc:
7
+ attr_reader :type
6
8
 
7
- def initialize(string, type = nil)
9
+ def initialize(string, type)
8
10
  @string = string.to_s
9
- @type = Types[type] || type if type
10
- @type ||= Types[:html]
11
+ @type = type
11
12
  end
12
13
 
13
14
  def identifier
14
- 'html template'
15
+ "html template"
15
16
  end
16
17
 
17
- def inspect
18
- 'html template'
19
- end
18
+ alias_method :inspect, :identifier
20
19
 
21
20
  def to_str
22
21
  ERB::Util.h(@string)
@@ -26,8 +25,8 @@ module ActionView #:nodoc:
26
25
  to_str
27
26
  end
28
27
 
29
- def formats
30
- [@type.respond_to?(:ref) ? @type.ref : @type.to_s]
28
+ def format
29
+ @type
31
30
  end
32
31
  end
33
32
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView # :nodoc:
4
+ class Template # :nodoc:
5
+ class Inline < Template # :nodoc:
6
+ # This finalizer is needed (and exactly with a proc inside another proc)
7
+ # otherwise templates leak in development.
8
+ Finalizer = proc do |method_name, mod| # :nodoc:
9
+ proc do
10
+ mod.module_eval do
11
+ remove_possible_method method_name
12
+ end
13
+ end
14
+ end
15
+
16
+ def compile(mod)
17
+ super
18
+ ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView # :nodoc:
4
+ # = Action View RawFile Template
5
+ class Template # :nodoc:
6
+ class RawFile # :nodoc:
7
+ attr_accessor :type, :format
8
+
9
+ def initialize(filename)
10
+ @filename = filename.to_s
11
+ extname = ::File.extname(filename).delete(".")
12
+ @type = Template::Types[extname] || Template::Types[:text]
13
+ @format = @type.symbol
14
+ end
15
+
16
+ def identifier
17
+ @filename
18
+ end
19
+
20
+ def render(*args)
21
+ ::File.read(@filename)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ # = Action View Renderable Template for objects that respond to #render_in
5
+ class Template
6
+ class Renderable # :nodoc:
7
+ def initialize(renderable)
8
+ @renderable = renderable
9
+ end
10
+
11
+ def identifier
12
+ @renderable.class.name
13
+ end
14
+
15
+ def render(context, *args)
16
+ @renderable.render_in(context)
17
+ end
18
+
19
+ def format
20
+ @renderable.format
21
+ end
22
+ end
23
+ end
24
+ end