actionview 8.0.5.2 → 8.1.0.beta1
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 +28 -171
- data/lib/action_view/base.rb +4 -2
- data/lib/action_view/buffers.rb +1 -1
- data/lib/action_view/dependency_tracker/erb_tracker.rb +1 -1
- data/lib/action_view/dependency_tracker.rb +6 -1
- data/lib/action_view/gem_version.rb +3 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +20 -4
- 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 +17 -0
- data/lib/action_view/helpers/form_helper.rb +2 -3
- data/lib/action_view/helpers/form_options_helper.rb +10 -12
- data/lib/action_view/helpers/form_tag_helper.rb +17 -10
- 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/sanitize_helper.rb +1 -6
- data/lib/action_view/helpers/tag_helper.rb +37 -52
- data/lib/action_view/helpers/tags/base.rb +9 -11
- data/lib/action_view/helpers/tags/check_box.rb +2 -2
- data/lib/action_view/helpers/tags/datetime_field.rb +1 -1
- data/lib/action_view/helpers/tags/file_field.rb +1 -4
- data/lib/action_view/helpers/tags/hidden_field.rb +1 -1
- data/lib/action_view/helpers/tags/label.rb +10 -3
- 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 +3 -3
- 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/text_helper.rb +7 -23
- data/lib/action_view/helpers/translation_helper.rb +6 -1
- data/lib/action_view/helpers/url_helper.rb +37 -9
- data/lib/action_view/locale/en.yml +3 -0
- data/lib/action_view/railtie.rb +11 -0
- data/lib/action_view/record_identifier.rb +21 -0
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +1 -5
- data/lib/action_view/renderer/partial_renderer.rb +16 -0
- data/lib/action_view/template/error.rb +7 -3
- data/lib/action_view/template/handlers/erb.rb +36 -11
- data/lib/action_view/template.rb +2 -8
- data/lib/action_view/test_case.rb +50 -52
- data/lib/action_view.rb +3 -0
- metadata +11 -17
|
@@ -111,11 +111,7 @@ module ActionView
|
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
unless entries_to_write.empty?
|
|
114
|
-
|
|
115
|
-
collection_cache.write_multi(entries_to_write, expires_in: @options[:cached][:expires_in])
|
|
116
|
-
else
|
|
117
|
-
collection_cache.write_multi(entries_to_write)
|
|
118
|
-
end
|
|
114
|
+
collection_cache.write_multi(entries_to_write)
|
|
119
115
|
end
|
|
120
116
|
|
|
121
117
|
keyed_partials
|
|
@@ -48,6 +48,22 @@ module ActionView
|
|
|
48
48
|
#
|
|
49
49
|
# <%= render partial: "account", locals: { user: @buyer } %>
|
|
50
50
|
#
|
|
51
|
+
# == \Rendering variants of a partial
|
|
52
|
+
#
|
|
53
|
+
# The <tt>:variants</tt> option can be used to render a different template variant of a partial. For instance:
|
|
54
|
+
#
|
|
55
|
+
# <%= render partial: "account", variants: :mobile %>
|
|
56
|
+
#
|
|
57
|
+
# This will render <tt>_account.html+mobile.erb</tt>. This option also accepts multiple variants
|
|
58
|
+
# like so:
|
|
59
|
+
#
|
|
60
|
+
# <%= render partial: "account", variants: [:desktop, :mobile] %>
|
|
61
|
+
#
|
|
62
|
+
# This will look for the following templates and render the first one that exists:
|
|
63
|
+
# * <tt>_account.html+desktop.erb</tt>
|
|
64
|
+
# * <tt>_account.html+mobile.erb</tt>
|
|
65
|
+
# * <tt>_account.html.erb</tt>
|
|
66
|
+
#
|
|
51
67
|
# == \Rendering a collection of partials
|
|
52
68
|
#
|
|
53
69
|
# The example of partial use describes a familiar pattern where a template needs to iterate over an array and
|
|
@@ -260,9 +260,13 @@ module ActionView
|
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
def message
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
263
|
+
if template.is_a?(Template::Inline)
|
|
264
|
+
<<~MESSAGE
|
|
265
|
+
Encountered a syntax error while rendering template: check #{@offending_code_string}
|
|
266
|
+
MESSAGE
|
|
267
|
+
else
|
|
268
|
+
"Encountered a syntax error while rendering template located at: #{template.short_identifier}"
|
|
269
|
+
end
|
|
266
270
|
end
|
|
267
271
|
|
|
268
272
|
def annotated_source_code
|
|
@@ -40,17 +40,19 @@ module ActionView
|
|
|
40
40
|
|
|
41
41
|
# Translate an error location returned by ErrorHighlight to the correct
|
|
42
42
|
# source location inside the template.
|
|
43
|
-
def translate_location(spot,
|
|
44
|
-
|
|
43
|
+
def translate_location(spot, _backtrace_location, source)
|
|
44
|
+
compiled = spot[:script_lines]
|
|
45
|
+
highlight = compiled[spot[:first_lineno] - 1]&.byteslice((spot[:first_column] - 1)...spot[:last_column])
|
|
46
|
+
return nil if highlight.blank?
|
|
47
|
+
|
|
45
48
|
source_lines = source.lines
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
lineno_delta = find_lineno_offset(compiled, source_lines, highlight, spot[:first_lineno])
|
|
50
|
+
|
|
51
|
+
tokens = ::ERB::Util.tokenize(source_lines[spot[:first_lineno] - lineno_delta - 1])
|
|
52
|
+
column_delta = find_offset(spot[:snippet], tokens, spot[:first_column])
|
|
53
|
+
|
|
50
54
|
spot[:first_lineno] -= lineno_delta
|
|
51
55
|
spot[:last_lineno] -= lineno_delta
|
|
52
|
-
|
|
53
|
-
column_delta = spot[:first_column] - new_first_column
|
|
54
56
|
spot[:first_column] -= column_delta
|
|
55
57
|
spot[:last_column] -= column_delta
|
|
56
58
|
spot[:script_lines] = source_lines
|
|
@@ -107,6 +109,28 @@ module ActionView
|
|
|
107
109
|
raise WrongEncodingError.new(string, string.encoding)
|
|
108
110
|
end
|
|
109
111
|
|
|
112
|
+
# Return the offset between the error lineno and the source lineno.
|
|
113
|
+
# Searches in reverse from the backtrace lineno so we have a better
|
|
114
|
+
# chance of finding the correct line
|
|
115
|
+
#
|
|
116
|
+
# The compiled template is likely to be longer than the source.
|
|
117
|
+
# Use the difference between the compiled and source sizes to
|
|
118
|
+
# determine the earliest line that could contain the highlight.
|
|
119
|
+
def find_lineno_offset(compiled, source_lines, highlight, error_lineno)
|
|
120
|
+
first_index = error_lineno - 1 - compiled.size + source_lines.size
|
|
121
|
+
first_index = 0 if first_index < 0
|
|
122
|
+
|
|
123
|
+
last_index = error_lineno - 1
|
|
124
|
+
last_index = source_lines.size - 1 if last_index >= source_lines.size
|
|
125
|
+
|
|
126
|
+
last_index.downto(first_index) do |line_index|
|
|
127
|
+
next unless source_lines[line_index].include?(highlight)
|
|
128
|
+
return error_lineno - 1 - line_index
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
raise LocationParsingError, "Couldn't find code snippet"
|
|
132
|
+
end
|
|
133
|
+
|
|
110
134
|
# Find which token in the source template spans the byte range that
|
|
111
135
|
# contains the error_column, then return the offset compared to the
|
|
112
136
|
# original source template.
|
|
@@ -137,7 +161,7 @@ module ActionView
|
|
|
137
161
|
matched_str = true
|
|
138
162
|
|
|
139
163
|
if name == :CODE && compiled.pos <= error_column && compiled.pos + str.bytesize >= error_column
|
|
140
|
-
return
|
|
164
|
+
return compiled.pos - offset
|
|
141
165
|
end
|
|
142
166
|
|
|
143
167
|
compiled.pos += str.bytesize
|
|
@@ -152,8 +176,9 @@ module ActionView
|
|
|
152
176
|
|
|
153
177
|
def offset_source_tokens(source_tokens)
|
|
154
178
|
source_offset = 0
|
|
155
|
-
with_offset = source_tokens.filter_map do |
|
|
156
|
-
result = [
|
|
179
|
+
with_offset = source_tokens.filter_map do |name, str|
|
|
180
|
+
result = [:CODE, str, source_offset] if name == :CODE || name == :PLAIN
|
|
181
|
+
result = [:TEXT, str, source_offset] if name == :TEXT
|
|
157
182
|
source_offset += str.bytesize
|
|
158
183
|
result
|
|
159
184
|
end
|
data/lib/action_view/template.rb
CHANGED
|
@@ -7,7 +7,7 @@ module ActionView
|
|
|
7
7
|
class Template
|
|
8
8
|
extend ActiveSupport::Autoload
|
|
9
9
|
|
|
10
|
-
STRICT_LOCALS_REGEX = /\#\s+locals:\s+\((
|
|
10
|
+
STRICT_LOCALS_REGEX = /\#\s+locals:\s+\((.*)\)/
|
|
11
11
|
|
|
12
12
|
# === Encodings in ActionView::Template
|
|
13
13
|
#
|
|
@@ -366,16 +366,10 @@ module ActionView
|
|
|
366
366
|
def strict_locals!
|
|
367
367
|
if @strict_locals == NONE
|
|
368
368
|
self.source.sub!(STRICT_LOCALS_REGEX, "")
|
|
369
|
-
@strict_locals = $1
|
|
369
|
+
@strict_locals = $1
|
|
370
370
|
|
|
371
371
|
return if @strict_locals.nil? # Magic comment not found
|
|
372
372
|
|
|
373
|
-
# Tag with the assumed encoding before encode! runs, same as
|
|
374
|
-
# encode! does for the source itself (see above).
|
|
375
|
-
if @strict_locals.encoding == Encoding::BINARY
|
|
376
|
-
@strict_locals.force_encoding(Encoding.default_external)
|
|
377
|
-
end
|
|
378
|
-
|
|
379
373
|
@strict_locals = "**nil" if @strict_locals.blank?
|
|
380
374
|
end
|
|
381
375
|
|
|
@@ -60,7 +60,56 @@ module ActionView
|
|
|
60
60
|
include ActiveSupport::Testing::ConstantLookup
|
|
61
61
|
|
|
62
62
|
delegate :lookup_context, to: :controller
|
|
63
|
-
attr_accessor :controller, :request, :output_buffer
|
|
63
|
+
attr_accessor :controller, :request, :output_buffer
|
|
64
|
+
|
|
65
|
+
# Returns the content rendered by the last +render+ call.
|
|
66
|
+
#
|
|
67
|
+
# The returned object behaves like a string but also exposes a number of methods
|
|
68
|
+
# that allows you to parse the content string in formats registered using
|
|
69
|
+
# <tt>.register_parser</tt>.
|
|
70
|
+
#
|
|
71
|
+
# By default includes the following parsers:
|
|
72
|
+
#
|
|
73
|
+
# +.html+
|
|
74
|
+
#
|
|
75
|
+
# Parse the <tt>rendered</tt> content String into HTML. By default, this means
|
|
76
|
+
# a <tt>Nokogiri::XML::Node</tt>.
|
|
77
|
+
#
|
|
78
|
+
# test "renders HTML" do
|
|
79
|
+
# article = Article.create!(title: "Hello, world")
|
|
80
|
+
#
|
|
81
|
+
# render partial: "articles/article", locals: { article: article }
|
|
82
|
+
#
|
|
83
|
+
# assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
|
|
84
|
+
# end
|
|
85
|
+
#
|
|
86
|
+
# To parse the rendered content into a <tt>Capybara::Simple::Node</tt>,
|
|
87
|
+
# re-register an <tt>:html</tt> parser with a call to
|
|
88
|
+
# <tt>Capybara.string</tt>:
|
|
89
|
+
#
|
|
90
|
+
# register_parser :html, -> rendered { Capybara.string(rendered) }
|
|
91
|
+
#
|
|
92
|
+
# test "renders HTML" do
|
|
93
|
+
# article = Article.create!(title: "Hello, world")
|
|
94
|
+
#
|
|
95
|
+
# render partial: article
|
|
96
|
+
#
|
|
97
|
+
# rendered.html.assert_css "h1", text: "Hello, world"
|
|
98
|
+
# end
|
|
99
|
+
#
|
|
100
|
+
# +.json+
|
|
101
|
+
#
|
|
102
|
+
# Parse the <tt>rendered</tt> content String into JSON. By default, this means
|
|
103
|
+
# a <tt>ActiveSupport::HashWithIndifferentAccess</tt>.
|
|
104
|
+
#
|
|
105
|
+
# test "renders JSON" do
|
|
106
|
+
# article = Article.create!(title: "Hello, world")
|
|
107
|
+
#
|
|
108
|
+
# render formats: :json, partial: "articles/article", locals: { article: article }
|
|
109
|
+
#
|
|
110
|
+
# assert_pattern { rendered.json => { title: "Hello, world" } }
|
|
111
|
+
# end
|
|
112
|
+
attr_accessor :rendered
|
|
64
113
|
|
|
65
114
|
module ClassMethods
|
|
66
115
|
def inherited(descendant) # :nodoc:
|
|
@@ -243,57 +292,6 @@ module ActionView
|
|
|
243
292
|
@_rendered_views ||= RenderedViewsCollection.new
|
|
244
293
|
end
|
|
245
294
|
|
|
246
|
-
##
|
|
247
|
-
# :method: rendered
|
|
248
|
-
#
|
|
249
|
-
# Returns the content rendered by the last +render+ call.
|
|
250
|
-
#
|
|
251
|
-
# The returned object behaves like a string but also exposes a number of methods
|
|
252
|
-
# that allows you to parse the content string in formats registered using
|
|
253
|
-
# <tt>.register_parser</tt>.
|
|
254
|
-
#
|
|
255
|
-
# By default includes the following parsers:
|
|
256
|
-
#
|
|
257
|
-
# +.html+
|
|
258
|
-
#
|
|
259
|
-
# Parse the <tt>rendered</tt> content String into HTML. By default, this means
|
|
260
|
-
# a <tt>Nokogiri::XML::Node</tt>.
|
|
261
|
-
#
|
|
262
|
-
# test "renders HTML" do
|
|
263
|
-
# article = Article.create!(title: "Hello, world")
|
|
264
|
-
#
|
|
265
|
-
# render partial: "articles/article", locals: { article: article }
|
|
266
|
-
#
|
|
267
|
-
# assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
|
|
268
|
-
# end
|
|
269
|
-
#
|
|
270
|
-
# To parse the rendered content into a <tt>Capybara::Simple::Node</tt>,
|
|
271
|
-
# re-register an <tt>:html</tt> parser with a call to
|
|
272
|
-
# <tt>Capybara.string</tt>:
|
|
273
|
-
#
|
|
274
|
-
# register_parser :html, -> rendered { Capybara.string(rendered) }
|
|
275
|
-
#
|
|
276
|
-
# test "renders HTML" do
|
|
277
|
-
# article = Article.create!(title: "Hello, world")
|
|
278
|
-
#
|
|
279
|
-
# render partial: article
|
|
280
|
-
#
|
|
281
|
-
# rendered.html.assert_css "h1", text: "Hello, world"
|
|
282
|
-
# end
|
|
283
|
-
#
|
|
284
|
-
# +.json+
|
|
285
|
-
#
|
|
286
|
-
# Parse the <tt>rendered</tt> content String into JSON. By default, this means
|
|
287
|
-
# a <tt>ActiveSupport::HashWithIndifferentAccess</tt>.
|
|
288
|
-
#
|
|
289
|
-
# test "renders JSON" do
|
|
290
|
-
# article = Article.create!(title: "Hello, world")
|
|
291
|
-
#
|
|
292
|
-
# render formats: :json, partial: "articles/article", locals: { article: article }
|
|
293
|
-
#
|
|
294
|
-
# assert_pattern { rendered.json => { title: "Hello, world" } }
|
|
295
|
-
# end
|
|
296
|
-
|
|
297
295
|
def _routes
|
|
298
296
|
@controller._routes if @controller.respond_to?(:_routes)
|
|
299
297
|
end
|
data/lib/action_view.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: actionview
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.0.
|
|
4
|
+
version: 8.1.0.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 8.0.
|
|
18
|
+
version: 8.1.0.beta1
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 8.0.
|
|
25
|
+
version: 8.1.0.beta1
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: builder
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,9 +58,6 @@ dependencies:
|
|
|
58
58
|
- - "~>"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
60
|
version: '1.6'
|
|
61
|
-
- - ">="
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version: 1.7.2
|
|
64
61
|
type: :runtime
|
|
65
62
|
prerelease: false
|
|
66
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -68,9 +65,6 @@ dependencies:
|
|
|
68
65
|
- - "~>"
|
|
69
66
|
- !ruby/object:Gem::Version
|
|
70
67
|
version: '1.6'
|
|
71
|
-
- - ">="
|
|
72
|
-
- !ruby/object:Gem::Version
|
|
73
|
-
version: 1.7.2
|
|
74
68
|
- !ruby/object:Gem::Dependency
|
|
75
69
|
name: rails-dom-testing
|
|
76
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -91,28 +85,28 @@ dependencies:
|
|
|
91
85
|
requirements:
|
|
92
86
|
- - '='
|
|
93
87
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: 8.0.
|
|
88
|
+
version: 8.1.0.beta1
|
|
95
89
|
type: :development
|
|
96
90
|
prerelease: false
|
|
97
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
98
92
|
requirements:
|
|
99
93
|
- - '='
|
|
100
94
|
- !ruby/object:Gem::Version
|
|
101
|
-
version: 8.0.
|
|
95
|
+
version: 8.1.0.beta1
|
|
102
96
|
- !ruby/object:Gem::Dependency
|
|
103
97
|
name: activemodel
|
|
104
98
|
requirement: !ruby/object:Gem::Requirement
|
|
105
99
|
requirements:
|
|
106
100
|
- - '='
|
|
107
101
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: 8.0.
|
|
102
|
+
version: 8.1.0.beta1
|
|
109
103
|
type: :development
|
|
110
104
|
prerelease: false
|
|
111
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
112
106
|
requirements:
|
|
113
107
|
- - '='
|
|
114
108
|
- !ruby/object:Gem::Version
|
|
115
|
-
version: 8.0.
|
|
109
|
+
version: 8.1.0.beta1
|
|
116
110
|
description: Simple, battle-tested conventions and helpers for building web pages.
|
|
117
111
|
email: david@loudthinking.com
|
|
118
112
|
executables: []
|
|
@@ -252,10 +246,10 @@ licenses:
|
|
|
252
246
|
- MIT
|
|
253
247
|
metadata:
|
|
254
248
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
255
|
-
changelog_uri: https://github.com/rails/rails/blob/v8.0.
|
|
256
|
-
documentation_uri: https://api.rubyonrails.org/v8.0.
|
|
249
|
+
changelog_uri: https://github.com/rails/rails/blob/v8.1.0.beta1/actionview/CHANGELOG.md
|
|
250
|
+
documentation_uri: https://api.rubyonrails.org/v8.1.0.beta1/
|
|
257
251
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
258
|
-
source_code_uri: https://github.com/rails/rails/tree/v8.0.
|
|
252
|
+
source_code_uri: https://github.com/rails/rails/tree/v8.1.0.beta1/actionview
|
|
259
253
|
rubygems_mfa_required: 'true'
|
|
260
254
|
rdoc_options: []
|
|
261
255
|
require_paths:
|
|
@@ -272,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
272
266
|
version: '0'
|
|
273
267
|
requirements:
|
|
274
268
|
- none
|
|
275
|
-
rubygems_version:
|
|
269
|
+
rubygems_version: 3.6.9
|
|
276
270
|
specification_version: 4
|
|
277
271
|
summary: Rendering framework putting the V in MVC (part of Rails).
|
|
278
272
|
test_files: []
|