actionview 7.0.8.1 → 7.2.2.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 +60 -425
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/app/assets/javascripts/rails-ujs.esm.js +686 -0
- data/app/assets/javascripts/rails-ujs.js +630 -0
- data/lib/action_view/base.rb +52 -14
- data/lib/action_view/buffers.rb +106 -8
- data/lib/action_view/cache_expiry.rb +44 -41
- data/lib/action_view/context.rb +1 -1
- data/lib/action_view/dependency_tracker/{ripper_tracker.rb → ruby_tracker.rb} +4 -3
- data/lib/action_view/dependency_tracker.rb +1 -1
- data/lib/action_view/deprecator.rb +7 -0
- data/lib/action_view/digestor.rb +1 -1
- data/lib/action_view/gem_version.rb +3 -3
- data/lib/action_view/helpers/active_model_helper.rb +1 -1
- data/lib/action_view/helpers/asset_tag_helper.rb +151 -55
- data/lib/action_view/helpers/asset_url_helper.rb +6 -5
- data/lib/action_view/helpers/atom_feed_helper.rb +5 -5
- data/lib/action_view/helpers/cache_helper.rb +7 -13
- data/lib/action_view/helpers/capture_helper.rb +30 -10
- data/lib/action_view/helpers/content_exfiltration_prevention_helper.rb +70 -0
- data/lib/action_view/helpers/controller_helper.rb +6 -0
- data/lib/action_view/helpers/csp_helper.rb +2 -2
- data/lib/action_view/helpers/csrf_helper.rb +3 -3
- data/lib/action_view/helpers/date_helper.rb +17 -19
- data/lib/action_view/helpers/debug_helper.rb +3 -3
- data/lib/action_view/helpers/form_helper.rb +248 -214
- data/lib/action_view/helpers/form_options_helper.rb +2 -1
- data/lib/action_view/helpers/form_tag_helper.rb +125 -58
- data/lib/action_view/helpers/javascript_helper.rb +1 -0
- data/lib/action_view/helpers/number_helper.rb +37 -330
- data/lib/action_view/helpers/output_safety_helper.rb +6 -6
- data/lib/action_view/helpers/rendering_helper.rb +1 -1
- data/lib/action_view/helpers/sanitize_helper.rb +51 -21
- data/lib/action_view/helpers/tag_helper.rb +210 -42
- data/lib/action_view/helpers/tags/base.rb +11 -52
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +1 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +1 -0
- data/lib/action_view/helpers/tags/collection_select.rb +3 -0
- data/lib/action_view/helpers/tags/date_field.rb +1 -1
- data/lib/action_view/helpers/tags/date_select.rb +2 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +14 -6
- data/lib/action_view/helpers/tags/datetime_local_field.rb +11 -2
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +3 -0
- data/lib/action_view/helpers/tags/month_field.rb +1 -1
- data/lib/action_view/helpers/tags/select.rb +3 -0
- data/lib/action_view/helpers/tags/select_renderer.rb +56 -0
- data/lib/action_view/helpers/tags/time_field.rb +1 -1
- data/lib/action_view/helpers/tags/time_zone_select.rb +3 -0
- data/lib/action_view/helpers/tags/week_field.rb +1 -1
- data/lib/action_view/helpers/tags/weekday_select.rb +3 -0
- data/lib/action_view/helpers/tags.rb +2 -0
- data/lib/action_view/helpers/text_helper.rb +157 -85
- data/lib/action_view/helpers/translation_helper.rb +3 -3
- data/lib/action_view/helpers/url_helper.rb +35 -80
- data/lib/action_view/helpers.rb +2 -0
- data/lib/action_view/layouts.rb +8 -8
- data/lib/action_view/log_subscriber.rb +57 -36
- data/lib/action_view/lookup_context.rb +29 -13
- data/lib/action_view/path_registry.rb +57 -0
- data/lib/action_view/path_set.rb +13 -14
- data/lib/action_view/railtie.rb +25 -3
- data/lib/action_view/record_identifier.rb +15 -8
- data/lib/action_view/render_parser/prism_render_parser.rb +127 -0
- data/lib/action_view/render_parser/ripper_render_parser.rb +341 -0
- data/lib/action_view/render_parser.rb +21 -169
- data/lib/action_view/renderer/abstract_renderer.rb +2 -2
- data/lib/action_view/renderer/collection_renderer.rb +10 -2
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +2 -1
- data/lib/action_view/renderer/partial_renderer.rb +2 -1
- data/lib/action_view/renderer/renderer.rb +34 -38
- data/lib/action_view/renderer/streaming_template_renderer.rb +3 -2
- data/lib/action_view/renderer/template_renderer.rb +3 -2
- data/lib/action_view/rendering.rb +26 -8
- data/lib/action_view/template/error.rb +14 -1
- data/lib/action_view/template/handlers/builder.rb +4 -4
- data/lib/action_view/template/handlers/erb/erubi.rb +23 -27
- data/lib/action_view/template/handlers/erb.rb +73 -1
- data/lib/action_view/template/handlers.rb +1 -1
- data/lib/action_view/template/html.rb +1 -1
- data/lib/action_view/template/raw_file.rb +1 -1
- data/lib/action_view/template/renderable.rb +8 -2
- data/lib/action_view/template/resolver.rb +9 -3
- data/lib/action_view/template/text.rb +1 -1
- data/lib/action_view/template/types.rb +25 -34
- data/lib/action_view/template.rb +278 -55
- data/lib/action_view/template_path.rb +2 -0
- data/lib/action_view/test_case.rb +181 -28
- data/lib/action_view/unbound_template.rb +17 -7
- data/lib/action_view/version.rb +1 -1
- data/lib/action_view/view_paths.rb +15 -24
- data/lib/action_view.rb +4 -1
- metadata +31 -31
- data/lib/action_view/ripper_ast_parser.rb +0 -198
- data/lib/assets/compiled/rails-ujs.js +0 -777
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "strscan"
|
4
|
+
require "active_support/core_ext/erb/util"
|
5
|
+
|
3
6
|
module ActionView
|
4
7
|
class Template
|
5
8
|
module Handlers
|
@@ -21,6 +24,8 @@ module ActionView
|
|
21
24
|
|
22
25
|
ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
|
23
26
|
|
27
|
+
LocationParsingError = Class.new(StandardError) # :nodoc:
|
28
|
+
|
24
29
|
def self.call(template, source)
|
25
30
|
new.call(template, source)
|
26
31
|
end
|
@@ -33,6 +38,26 @@ module ActionView
|
|
33
38
|
true
|
34
39
|
end
|
35
40
|
|
41
|
+
# Translate an error location returned by ErrorHighlight to the correct
|
42
|
+
# source location inside the template.
|
43
|
+
def translate_location(spot, backtrace_location, source)
|
44
|
+
# Tokenize the source line
|
45
|
+
tokens = ::ERB::Util.tokenize(source.lines[backtrace_location.lineno - 1])
|
46
|
+
new_first_column = find_offset(spot[:snippet], tokens, spot[:first_column])
|
47
|
+
lineno_delta = spot[:first_lineno] - backtrace_location.lineno
|
48
|
+
spot[:first_lineno] -= lineno_delta
|
49
|
+
spot[:last_lineno] -= lineno_delta
|
50
|
+
|
51
|
+
column_delta = spot[:first_column] - new_first_column
|
52
|
+
spot[:first_column] -= column_delta
|
53
|
+
spot[:last_column] -= column_delta
|
54
|
+
spot[:script_lines] = source.lines
|
55
|
+
|
56
|
+
spot
|
57
|
+
rescue NotImplementedError, LocationParsingError
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
36
61
|
def call(template, source)
|
37
62
|
# First, convert to BINARY, so in case the encoding is
|
38
63
|
# wrong, we can still find an encoding tag
|
@@ -58,7 +83,7 @@ module ActionView
|
|
58
83
|
|
59
84
|
if ActionView::Base.annotate_rendered_view_with_filenames && template.format == :html
|
60
85
|
options[:preamble] = "@output_buffer.safe_append='<!-- BEGIN #{template.short_identifier} -->';"
|
61
|
-
options[:postamble] = "@output_buffer.safe_append='<!-- END #{template.short_identifier} -->';@output_buffer
|
86
|
+
options[:postamble] = "@output_buffer.safe_append='<!-- END #{template.short_identifier} -->';@output_buffer"
|
62
87
|
end
|
63
88
|
|
64
89
|
self.class.erb_implementation.new(erb, options).src
|
@@ -79,6 +104,53 @@ module ActionView
|
|
79
104
|
# Otherwise, raise an exception
|
80
105
|
raise WrongEncodingError.new(string, string.encoding)
|
81
106
|
end
|
107
|
+
|
108
|
+
def find_offset(compiled, source_tokens, error_column)
|
109
|
+
compiled = StringScanner.new(compiled)
|
110
|
+
|
111
|
+
passed_tokens = []
|
112
|
+
|
113
|
+
while tok = source_tokens.shift
|
114
|
+
tok_name, str = *tok
|
115
|
+
case tok_name
|
116
|
+
when :TEXT
|
117
|
+
loop do
|
118
|
+
break if compiled.match?(str)
|
119
|
+
compiled.getch
|
120
|
+
end
|
121
|
+
raise LocationParsingError unless compiled.scan(str)
|
122
|
+
when :CODE
|
123
|
+
if compiled.pos > error_column
|
124
|
+
raise LocationParsingError, "We went too far"
|
125
|
+
end
|
126
|
+
|
127
|
+
if compiled.pos + str.bytesize >= error_column
|
128
|
+
offset = error_column - compiled.pos
|
129
|
+
return passed_tokens.map(&:last).join.bytesize + offset
|
130
|
+
else
|
131
|
+
unless compiled.scan(str)
|
132
|
+
raise LocationParsingError, "Couldn't find code snippet"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
when :OPEN
|
136
|
+
next_tok = source_tokens.first.last
|
137
|
+
loop do
|
138
|
+
break if compiled.match?(next_tok)
|
139
|
+
compiled.getch
|
140
|
+
end
|
141
|
+
when :CLOSE
|
142
|
+
next_tok = source_tokens.first.last
|
143
|
+
loop do
|
144
|
+
break if compiled.match?(next_tok)
|
145
|
+
compiled.getch
|
146
|
+
end
|
147
|
+
else
|
148
|
+
raise LocationParsingError, "Not implemented: #{tok.first}"
|
149
|
+
end
|
150
|
+
|
151
|
+
passed_tokens << tok
|
152
|
+
end
|
153
|
+
end
|
82
154
|
end
|
83
155
|
end
|
84
156
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionView # :nodoc:
|
4
|
-
# = Action View Template Handlers
|
5
4
|
class Template # :nodoc:
|
5
|
+
# = Action View Template Handlers
|
6
6
|
module Handlers # :nodoc:
|
7
7
|
autoload :Raw, "action_view/template/handlers/raw"
|
8
8
|
autoload :ERB, "action_view/template/handlers/erb"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionView
|
4
|
-
# = Action View Renderable Template for objects that respond to #render_in
|
5
4
|
class Template
|
5
|
+
# = Action View Renderable Template for objects that respond to #render_in
|
6
6
|
class Renderable # :nodoc:
|
7
7
|
def initialize(renderable)
|
8
8
|
@renderable = renderable
|
@@ -14,10 +14,16 @@ module ActionView
|
|
14
14
|
|
15
15
|
def render(context, *args)
|
16
16
|
@renderable.render_in(context)
|
17
|
+
rescue NoMethodError
|
18
|
+
if !@renderable.respond_to?(:render_in)
|
19
|
+
raise ArgumentError, "'#{@renderable.inspect}' is not a renderable object. It must implement #render_in."
|
20
|
+
else
|
21
|
+
raise
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
def format
|
20
|
-
@renderable.format
|
26
|
+
@renderable.try(:format)
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -10,9 +10,6 @@ require "concurrent/map"
|
|
10
10
|
module ActionView
|
11
11
|
# = Action View Resolver
|
12
12
|
class Resolver
|
13
|
-
Path = ActionView::TemplatePath
|
14
|
-
deprecate_constant :Path
|
15
|
-
|
16
13
|
class PathParser # :nodoc:
|
17
14
|
ParsedPath = Struct.new(:path, :details)
|
18
15
|
|
@@ -65,6 +62,11 @@ module ActionView
|
|
65
62
|
_find_all(name, prefix, partial, details, key, locals)
|
66
63
|
end
|
67
64
|
|
65
|
+
def built_templates # :nodoc:
|
66
|
+
# Used for error pages
|
67
|
+
[]
|
68
|
+
end
|
69
|
+
|
68
70
|
def all_template_paths # :nodoc:
|
69
71
|
# Not implemented by default
|
70
72
|
[]
|
@@ -122,6 +124,10 @@ module ActionView
|
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
127
|
+
def built_templates # :nodoc:
|
128
|
+
@unbound_templates.values.flatten.flat_map(&:built_templates)
|
129
|
+
end
|
130
|
+
|
125
131
|
private
|
126
132
|
def _find_all(name, prefix, partial, details, key, locals)
|
127
133
|
requested_details = key || TemplateDetails::Requested.new(**details)
|
@@ -4,11 +4,14 @@ require "active_support/core_ext/module/attribute_accessors"
|
|
4
4
|
|
5
5
|
module ActionView
|
6
6
|
class Template # :nodoc:
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# SimpleType is mostly just a stub implementation for when Action View
|
8
|
+
# is used without Action Dispatch.
|
9
|
+
class SimpleType # :nodoc:
|
10
|
+
@symbols = [ :html, :text, :js, :css, :xml, :json ]
|
11
|
+
class << self
|
12
|
+
attr_reader :symbols
|
10
13
|
|
11
|
-
def
|
14
|
+
def [](type)
|
12
15
|
if type.is_a?(self)
|
13
16
|
type
|
14
17
|
else
|
@@ -16,44 +19,32 @@ module ActionView
|
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
def initialize(symbol)
|
22
|
-
@symbol = symbol.to_sym
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
@symbol.to_s
|
27
|
-
end
|
28
|
-
alias to_str to_s
|
29
|
-
|
30
|
-
def ref
|
31
|
-
@symbol
|
32
|
-
end
|
33
|
-
alias to_sym ref
|
34
|
-
|
35
|
-
def ==(type)
|
36
|
-
@symbol == type.to_sym unless type.blank?
|
22
|
+
def valid_symbols?(symbols) # :nodoc
|
23
|
+
symbols.all? { |s| @symbols.include?(s) }
|
37
24
|
end
|
38
25
|
end
|
39
26
|
|
40
|
-
|
41
|
-
attr_accessor :type_klass
|
27
|
+
attr_reader :symbol
|
42
28
|
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
def initialize(symbol)
|
30
|
+
@symbol = symbol.to_sym
|
31
|
+
end
|
46
32
|
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
def to_s
|
34
|
+
@symbol.to_s
|
35
|
+
end
|
36
|
+
alias to_str to_s
|
50
37
|
|
51
|
-
|
52
|
-
|
53
|
-
end
|
38
|
+
def ref
|
39
|
+
@symbol
|
54
40
|
end
|
41
|
+
alias to_sym ref
|
55
42
|
|
56
|
-
|
43
|
+
def ==(type)
|
44
|
+
@symbol == type.to_sym unless type.blank?
|
45
|
+
end
|
57
46
|
end
|
47
|
+
|
48
|
+
Types = SimpleType # :nodoc:
|
58
49
|
end
|
59
50
|
end
|