actionview 7.2.3.1 → 8.0.5
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 +74 -109
- data/lib/action_view/dependency_tracker/erb_tracker.rb +36 -27
- data/lib/action_view/dependency_tracker/ruby_tracker.rb +2 -19
- data/lib/action_view/dependency_tracker/wildcard_resolver.rb +32 -0
- data/lib/action_view/dependency_tracker.rb +1 -0
- data/lib/action_view/gem_version.rb +4 -4
- 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/date_helper.rb +3 -3
- data/lib/action_view/helpers/form_helper.rb +76 -75
- data/lib/action_view/helpers/form_options_helper.rb +25 -22
- data/lib/action_view/helpers/form_tag_helper.rb +20 -17
- data/lib/action_view/helpers/rendering_helper.rb +160 -50
- data/lib/action_view/helpers/sanitize_helper.rb +6 -0
- data/lib/action_view/helpers/tag_helper.rb +26 -39
- data/lib/action_view/helpers/tags/base.rb +11 -9
- data/lib/action_view/helpers/tags/check_box.rb +2 -2
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
- data/lib/action_view/helpers/tags/file_field.rb +4 -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_renderer.rb +1 -1
- 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/url_helper.rb +2 -4
- data/lib/action_view/layouts.rb +1 -1
- data/lib/action_view/record_identifier.rb +1 -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/streaming_template_renderer.rb +8 -2
- data/lib/action_view/rendering.rb +2 -3
- data/lib/action_view/template/handlers/erb/erubi.rb +1 -1
- 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 +9 -4
- metadata +12 -25
|
@@ -1,32 +1,140 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionView
|
|
4
6
|
module Helpers # :nodoc:
|
|
5
|
-
#
|
|
7
|
+
# # Action View Rendering Helpers
|
|
6
8
|
#
|
|
7
|
-
# Implements methods that allow rendering from a view context.
|
|
8
|
-
#
|
|
9
|
-
#
|
|
9
|
+
# Implements methods that allow rendering from a view context. In order to use
|
|
10
|
+
# this module, all you need is to implement view_renderer that returns an
|
|
11
|
+
# ActionView::Renderer object.
|
|
10
12
|
module RenderingHelper
|
|
11
|
-
#
|
|
13
|
+
# Renders a template and returns the result.
|
|
14
|
+
#
|
|
15
|
+
# Pass the template to render as the first argument. This is shorthand
|
|
16
|
+
# syntax for partial rendering, so the template filename should be
|
|
17
|
+
# prefixed with an underscore. The partial renderer looks for the partial
|
|
18
|
+
# template in the directory of the calling template first.
|
|
19
|
+
#
|
|
20
|
+
# <% # app/views/posts/new.html.erb %>
|
|
21
|
+
# <%= render "form" %>
|
|
22
|
+
# # => renders app/views/posts/_form.html.erb
|
|
23
|
+
#
|
|
24
|
+
# Use the complete view path to render a partial from another directory.
|
|
25
|
+
#
|
|
26
|
+
# <% # app/views/posts/show.html.erb %>
|
|
27
|
+
# <%= render "comments/form" %>
|
|
28
|
+
# # => renders app/views/comments/_form.html.erb
|
|
29
|
+
#
|
|
30
|
+
# Without the rendering mode, the second argument can be a Hash of local
|
|
31
|
+
# variable assignments for the template.
|
|
32
|
+
#
|
|
33
|
+
# <% # app/views/posts/new.html.erb %>
|
|
34
|
+
# <%= render "form", post: Post.new %>
|
|
35
|
+
# # => renders app/views/posts/_form.html.erb
|
|
36
|
+
#
|
|
37
|
+
# If the first argument responds to `render_in`, the template will be rendered
|
|
38
|
+
# by calling `render_in` with the current view context.
|
|
39
|
+
#
|
|
40
|
+
# class Greeting
|
|
41
|
+
# def render_in(view_context)
|
|
42
|
+
# view_context.render html: "<h1>Hello, World</h1>"
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# def format
|
|
46
|
+
# :html
|
|
47
|
+
# end
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# <%= render Greeting.new %>
|
|
51
|
+
# # => "<h1>Hello, World</h1>"
|
|
52
|
+
#
|
|
53
|
+
# #### Rendering Mode
|
|
54
|
+
#
|
|
55
|
+
# Pass the rendering mode as first argument to override it.
|
|
56
|
+
#
|
|
57
|
+
# `:partial`
|
|
58
|
+
# : See ActionView::PartialRenderer for details.
|
|
59
|
+
#
|
|
60
|
+
# <%= render partial: "form", locals: { post: Post.new } %>
|
|
61
|
+
# # => renders app/views/posts/_form.html.erb
|
|
62
|
+
#
|
|
63
|
+
# `:file`
|
|
64
|
+
# : Renders the contents of a file. This option should **not** be used with
|
|
65
|
+
# unsanitized user input.
|
|
66
|
+
#
|
|
67
|
+
# <%= render file: "/path/to/some/file" %>
|
|
68
|
+
# # => renders /path/to/some/file
|
|
69
|
+
#
|
|
70
|
+
# `:inline`
|
|
71
|
+
# : Renders an ERB template string.
|
|
72
|
+
#
|
|
73
|
+
# <% name = "World" %>
|
|
74
|
+
# <%= render inline: "<h1>Hello, <%= name %>!</h1>" %>
|
|
75
|
+
# # => renders "<h1>Hello, World!</h1>"
|
|
76
|
+
#
|
|
77
|
+
# `:body`
|
|
78
|
+
# : Renders the provided text, and sets the format as `:text`.
|
|
79
|
+
#
|
|
80
|
+
# <%= render body: "Hello, World!" %>
|
|
81
|
+
# # => renders "Hello, World!"
|
|
82
|
+
#
|
|
83
|
+
# `:plain`
|
|
84
|
+
# : Renders the provided text, and sets the format as `:text`.
|
|
85
|
+
#
|
|
86
|
+
# <%= render plain: "Hello, World!" %>
|
|
87
|
+
# # => renders "Hello, World!"
|
|
88
|
+
#
|
|
89
|
+
# `:html`
|
|
90
|
+
# : Renders the provided HTML string, and sets the format as
|
|
91
|
+
# `:html`. If the string is not `html_safe?`, performs HTML escaping on
|
|
92
|
+
# the string before rendering.
|
|
93
|
+
#
|
|
94
|
+
# <%= render html: "<h1>Hello, World!</h1>".html_safe %>
|
|
95
|
+
# # => renders "<h1>Hello, World!</h1>"
|
|
96
|
+
#
|
|
97
|
+
# <%= render html: "<h1>Hello, World!</h1>" %>
|
|
98
|
+
# # => renders "<h1>Hello, World!</h1>"
|
|
99
|
+
#
|
|
100
|
+
# `:renderable`
|
|
101
|
+
# : Renders the provided object by calling `render_in` with the current view
|
|
102
|
+
# context. The format is determined by calling `format` on the
|
|
103
|
+
# renderable if it responds to `format`, falling back to `:html` by
|
|
104
|
+
# default.
|
|
105
|
+
#
|
|
106
|
+
# <%= render renderable: Greeting.new %>
|
|
107
|
+
# # => renders "<h1>Hello, World</h1>"
|
|
108
|
+
#
|
|
109
|
+
#
|
|
110
|
+
# #### Options
|
|
111
|
+
#
|
|
112
|
+
# `:locals`
|
|
113
|
+
# : Hash of local variable assignments for the template.
|
|
114
|
+
#
|
|
115
|
+
# <%= render inline: "<h1>Hello, <%= name %>!</h1>", locals: { name: "World" } %>
|
|
116
|
+
# # => renders "<h1>Hello, World!</h1>"
|
|
117
|
+
#
|
|
118
|
+
# `:formats`
|
|
119
|
+
# : Override the current format to render a template for a different format.
|
|
120
|
+
#
|
|
121
|
+
# <% # app/views/posts/show.html.erb %>
|
|
122
|
+
# <%= render template: "posts/content", formats: [:text] %>
|
|
123
|
+
# # => renders app/views/posts/content.text.erb
|
|
12
124
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# * <tt>:inline</tt> - Renders an inline template similar to how it's done in the controller.
|
|
16
|
-
# * <tt>:plain</tt> - Renders the text passed in out. Setting the content
|
|
17
|
-
# type as <tt>text/plain</tt>.
|
|
18
|
-
# * <tt>:html</tt> - Renders the HTML safe string passed in out, otherwise
|
|
19
|
-
# performs HTML escape on the string first. Setting the content type as
|
|
20
|
-
# <tt>text/html</tt>.
|
|
21
|
-
# * <tt>:body</tt> - Renders the text passed in, and inherits the content
|
|
22
|
-
# type of <tt>text/plain</tt> from ActionDispatch::Response object.
|
|
125
|
+
# `:variants`
|
|
126
|
+
# : Render a template for a different variant.
|
|
23
127
|
#
|
|
24
|
-
#
|
|
128
|
+
# <% # app/views/posts/show.html.erb %>
|
|
129
|
+
# <%= render template: "posts/content", variants: [:tablet] %>
|
|
130
|
+
# # => renders app/views/posts/content.html+tablet.erb
|
|
25
131
|
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
132
|
+
# `:handlers`
|
|
133
|
+
# : Render a template for a different handler.
|
|
28
134
|
#
|
|
29
|
-
#
|
|
135
|
+
# <% # app/views/posts/show.html.erb %>
|
|
136
|
+
# <%= render template: "posts/content", handlers: [:builder] %>
|
|
137
|
+
# # => renders app/views/posts/content.html.builder
|
|
30
138
|
def render(options = {}, locals = {}, &block)
|
|
31
139
|
case options
|
|
32
140
|
when Hash
|
|
@@ -47,52 +155,54 @@ module ActionView
|
|
|
47
155
|
end
|
|
48
156
|
|
|
49
157
|
# Overrides _layout_for in the context object so it supports the case a block is
|
|
50
|
-
# passed to a partial. Returns the contents that are yielded to a layout, given
|
|
51
|
-
# name or a block.
|
|
158
|
+
# passed to a partial. Returns the contents that are yielded to a layout, given
|
|
159
|
+
# a name or a block.
|
|
52
160
|
#
|
|
53
|
-
# You can think of a layout as a method that is called with a block. If the user
|
|
54
|
-
#
|
|
55
|
-
# If the user calls simply
|
|
161
|
+
# You can think of a layout as a method that is called with a block. If the user
|
|
162
|
+
# calls `yield :some_name`, the block, by default, returns
|
|
163
|
+
# `content_for(:some_name)`. If the user calls simply `yield`, the default block
|
|
164
|
+
# returns `content_for(:layout)`.
|
|
56
165
|
#
|
|
57
166
|
# The user can override this default by passing a block to the layout:
|
|
58
167
|
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
168
|
+
# # The template
|
|
169
|
+
# <%= render layout: "my_layout" do %>
|
|
170
|
+
# Content
|
|
171
|
+
# <% end %>
|
|
63
172
|
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
173
|
+
# # The layout
|
|
174
|
+
# <html>
|
|
175
|
+
# <%= yield %>
|
|
176
|
+
# </html>
|
|
68
177
|
#
|
|
69
|
-
# In this case, instead of the default block, which would return
|
|
70
|
-
# this method returns the block that was passed in to
|
|
178
|
+
# In this case, instead of the default block, which would return `content_for(:layout)`,
|
|
179
|
+
# this method returns the block that was passed in to `render :layout`, and the response
|
|
71
180
|
# would be
|
|
72
181
|
#
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
182
|
+
# <html>
|
|
183
|
+
# Content
|
|
184
|
+
# </html>
|
|
76
185
|
#
|
|
77
|
-
# Finally, the block can take block arguments, which can be passed in by
|
|
186
|
+
# Finally, the block can take block arguments, which can be passed in by
|
|
187
|
+
# `yield`:
|
|
78
188
|
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
189
|
+
# # The template
|
|
190
|
+
# <%= render layout: "my_layout" do |customer| %>
|
|
191
|
+
# Hello <%= customer.name %>
|
|
192
|
+
# <% end %>
|
|
83
193
|
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
194
|
+
# # The layout
|
|
195
|
+
# <html>
|
|
196
|
+
# <%= yield Struct.new(:name).new("David") %>
|
|
197
|
+
# </html>
|
|
88
198
|
#
|
|
89
|
-
# In this case, the layout would receive the block passed into
|
|
199
|
+
# In this case, the layout would receive the block passed into `render :layout`,
|
|
90
200
|
# and the struct specified would be passed into the block as an argument. The result
|
|
91
201
|
# would be
|
|
92
202
|
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
203
|
+
# <html>
|
|
204
|
+
# Hello David
|
|
205
|
+
# </html>
|
|
96
206
|
#
|
|
97
207
|
def _layout_for(*args, &block)
|
|
98
208
|
name = args.first
|
|
@@ -24,6 +24,12 @@ module ActionView
|
|
|
24
24
|
#
|
|
25
25
|
# Custom sanitization rules can also be provided.
|
|
26
26
|
#
|
|
27
|
+
# <b>Warning</b>: Adding disallowed tags or attributes to the allowlists may introduce
|
|
28
|
+
# vulnerabilities into your application. Please rely on the default allowlists whenever
|
|
29
|
+
# possible, because they are curated to maintain security and safety. If you think that the
|
|
30
|
+
# default allowlists should be expanded, please {open an issue on the rails-html-sanitizer
|
|
31
|
+
# project}[https://github.com/rails/rails-html-sanitizer/issues].
|
|
32
|
+
#
|
|
27
33
|
# Please note that sanitizing user-provided text does not guarantee that the
|
|
28
34
|
# resulting markup is valid or even well-formed.
|
|
29
35
|
#
|
|
@@ -4,7 +4,6 @@ require "active_support/code_generator"
|
|
|
4
4
|
require "active_support/core_ext/enumerable"
|
|
5
5
|
require "active_support/core_ext/string/output_safety"
|
|
6
6
|
require "active_support/core_ext/string/inflections"
|
|
7
|
-
require "set"
|
|
8
7
|
require "action_view/helpers/capture_helper"
|
|
9
8
|
require "action_view/helpers/output_safety_helper"
|
|
10
9
|
|
|
@@ -48,48 +47,36 @@ module ActionView
|
|
|
48
47
|
include CaptureHelper
|
|
49
48
|
include OutputSafetyHelper
|
|
50
49
|
|
|
51
|
-
def self.define_element(name, code_generator:, method_name: name
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
def self.define_element(name, code_generator:, method_name: name)
|
|
51
|
+
return if method_defined?(name)
|
|
52
|
+
|
|
53
|
+
code_generator.class_eval do |batch|
|
|
54
|
+
batch << "\n" <<
|
|
55
|
+
"def #{method_name}(content = nil, escape: true, **options, &block)" <<
|
|
56
|
+
" tag_string(#{name.inspect}, content, options, escape: escape, &block)" <<
|
|
57
|
+
"end"
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
def self.define_void_element(name, code_generator:, method_name: name
|
|
62
|
-
code_generator.
|
|
63
|
-
batch
|
|
64
|
-
def #{method_name}(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Putting content inside a void element (#{name}) is invalid
|
|
68
|
-
according to the HTML5 spec, and so it is being deprecated
|
|
69
|
-
without replacement. In Rails 8.0, passing content as a
|
|
70
|
-
positional argument will raise, and using a block will have
|
|
71
|
-
no effect.
|
|
72
|
-
TEXT
|
|
73
|
-
tag_string("#{name}", content, options, escape: escape, &block)
|
|
74
|
-
else
|
|
75
|
-
self_closing_tag_string("#{name}", options, escape, ">")
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
RUBY
|
|
61
|
+
def self.define_void_element(name, code_generator:, method_name: name)
|
|
62
|
+
code_generator.class_eval do |batch|
|
|
63
|
+
batch << "\n" <<
|
|
64
|
+
"def #{method_name}(escape: true, **options, &block)" <<
|
|
65
|
+
" self_closing_tag_string(#{name.inspect}, options, escape, '>')" <<
|
|
66
|
+
"end"
|
|
79
67
|
end
|
|
80
68
|
end
|
|
81
69
|
|
|
82
|
-
def self.define_self_closing_element(name, code_generator:, method_name: name
|
|
83
|
-
code_generator.
|
|
84
|
-
batch
|
|
85
|
-
def #{method_name}(content = nil, escape: true, **options, &block)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
RUBY
|
|
70
|
+
def self.define_self_closing_element(name, code_generator:, method_name: name)
|
|
71
|
+
code_generator.class_eval do |batch|
|
|
72
|
+
batch << "\n" <<
|
|
73
|
+
"def #{method_name}(content = nil, escape: true, **options, &block)" <<
|
|
74
|
+
" if content || block" <<
|
|
75
|
+
" tag_string(#{name.inspect}, content, options, escape: escape, &block)" <<
|
|
76
|
+
" else" <<
|
|
77
|
+
" self_closing_tag_string(#{name.inspect}, options, escape)" <<
|
|
78
|
+
" end" <<
|
|
79
|
+
"end"
|
|
93
80
|
end
|
|
94
81
|
end
|
|
95
82
|
|
|
@@ -110,8 +97,8 @@ module ActionView
|
|
|
110
97
|
define_void_element :wbr, code_generator: code_generator
|
|
111
98
|
|
|
112
99
|
define_self_closing_element :animate, code_generator: code_generator
|
|
113
|
-
define_self_closing_element :animateMotion, code_generator: code_generator
|
|
114
|
-
define_self_closing_element :animateTransform, code_generator: code_generator
|
|
100
|
+
define_self_closing_element :animateMotion, code_generator: code_generator, method_name: :animate_motion
|
|
101
|
+
define_self_closing_element :animateTransform, code_generator: code_generator, method_name: :animate_transform
|
|
115
102
|
define_self_closing_element :circle, code_generator: code_generator
|
|
116
103
|
define_self_closing_element :ellipse, code_generator: code_generator
|
|
117
104
|
define_self_closing_element :line, code_generator: code_generator
|
|
@@ -80,30 +80,32 @@ module ActionView
|
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
def
|
|
83
|
+
def add_default_name_and_field_for_value(tag_value, options, field = "id")
|
|
84
84
|
if tag_value.nil?
|
|
85
|
-
|
|
85
|
+
add_default_name_and_field(options, field)
|
|
86
86
|
else
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
specified_field = options[field]
|
|
88
|
+
add_default_name_and_field(options, field)
|
|
89
89
|
|
|
90
|
-
if
|
|
91
|
-
options[
|
|
90
|
+
if specified_field.blank? && options[field].present?
|
|
91
|
+
options[field] += "_#{sanitized_value(tag_value)}"
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
|
+
alias_method :add_default_name_and_id_for_value, :add_default_name_and_field_for_value
|
|
95
96
|
|
|
96
|
-
def
|
|
97
|
+
def add_default_name_and_field(options, field = "id")
|
|
97
98
|
index = name_and_id_index(options)
|
|
98
99
|
options["name"] = options.fetch("name") { tag_name(options["multiple"], index) }
|
|
99
100
|
|
|
100
101
|
if generate_ids?
|
|
101
|
-
options[
|
|
102
|
+
options[field] = options.fetch(field) { tag_id(index, options.delete("namespace")) }
|
|
102
103
|
if namespace = options.delete("namespace")
|
|
103
|
-
options[
|
|
104
|
+
options[field] = options[field] ? "#{namespace}_#{options[field]}" : namespace
|
|
104
105
|
end
|
|
105
106
|
end
|
|
106
107
|
end
|
|
108
|
+
alias_method :add_default_name_and_id, :add_default_name_and_field
|
|
107
109
|
|
|
108
110
|
def tag_name(multiple = false, index = nil)
|
|
109
111
|
@template_object.field_name(@object_name, sanitized_method_name, multiple: multiple, index: index)
|
|
@@ -21,10 +21,10 @@ module ActionView
|
|
|
21
21
|
options["checked"] = "checked" if input_checked?(options)
|
|
22
22
|
|
|
23
23
|
if options["multiple"]
|
|
24
|
-
|
|
24
|
+
add_default_name_and_field_for_value(@checked_value, options)
|
|
25
25
|
options.delete("multiple")
|
|
26
26
|
else
|
|
27
|
-
|
|
27
|
+
add_default_name_and_field(options)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
include_hidden = options.delete("include_hidden") { true }
|
|
@@ -10,12 +10,13 @@ module ActionView
|
|
|
10
10
|
include FormOptionsHelper
|
|
11
11
|
|
|
12
12
|
class CheckBoxBuilder < Builder # :nodoc:
|
|
13
|
-
def
|
|
13
|
+
def checkbox(extra_html_options = {})
|
|
14
14
|
html_options = extra_html_options.merge(@input_html_options)
|
|
15
15
|
html_options[:multiple] = true
|
|
16
16
|
html_options[:skip_default_ids] = false
|
|
17
|
-
@template_object.
|
|
17
|
+
@template_object.checkbox(@object_name, @method_name, html_options, @value, nil)
|
|
18
18
|
end
|
|
19
|
+
alias_method :check_box, :checkbox
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def render(&block)
|
|
@@ -24,7 +25,7 @@ module ActionView
|
|
|
24
25
|
|
|
25
26
|
private
|
|
26
27
|
def render_component(builder)
|
|
27
|
-
builder.
|
|
28
|
+
builder.checkbox + builder.label
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def hidden_field_name
|
|
@@ -6,8 +6,11 @@ module ActionView
|
|
|
6
6
|
class FileField < TextField # :nodoc:
|
|
7
7
|
def render
|
|
8
8
|
include_hidden = @options.delete(:include_hidden)
|
|
9
|
+
if @options[:accept].is_a?(Array)
|
|
10
|
+
@options[:accept] = @options[:accept].join(",")
|
|
11
|
+
end
|
|
9
12
|
options = @options.stringify_keys
|
|
10
|
-
|
|
13
|
+
add_default_name_and_field(options)
|
|
11
14
|
|
|
12
15
|
if options["multiple"] && include_hidden
|
|
13
16
|
hidden_field_for_multiple_file(options) + super
|
|
@@ -48,18 +48,11 @@ module ActionView
|
|
|
48
48
|
def render(&block)
|
|
49
49
|
options = @options.stringify_keys
|
|
50
50
|
tag_value = options.delete("value")
|
|
51
|
-
name_and_id = options.dup
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
name_and_id["id"] = name_and_id["for"]
|
|
55
|
-
else
|
|
56
|
-
name_and_id.delete("id")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
add_default_name_and_id_for_value(tag_value, name_and_id)
|
|
52
|
+
add_default_name_and_field_for_value(tag_value, options, "for")
|
|
60
53
|
options.delete("index")
|
|
54
|
+
options.delete("name")
|
|
61
55
|
options.delete("namespace")
|
|
62
|
-
options["for"] = name_and_id["id"] unless options.key?("for")
|
|
63
56
|
|
|
64
57
|
builder = LabelBuilder.new(@template_object, @object_name, @method_name, @object, tag_value)
|
|
65
58
|
|
|
@@ -71,7 +64,7 @@ module ActionView
|
|
|
71
64
|
render_component(builder)
|
|
72
65
|
end
|
|
73
66
|
|
|
74
|
-
label_tag(
|
|
67
|
+
label_tag(options["for"], content, options)
|
|
75
68
|
end
|
|
76
69
|
|
|
77
70
|
private
|
|
@@ -18,7 +18,7 @@ module ActionView
|
|
|
18
18
|
options["type"] = "radio"
|
|
19
19
|
options["value"] = @tag_value
|
|
20
20
|
options["checked"] = "checked" if input_checked?(options)
|
|
21
|
-
|
|
21
|
+
add_default_name_and_field_for_value(@tag_value, options)
|
|
22
22
|
tag("input", options)
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -11,7 +11,7 @@ module ActionView
|
|
|
11
11
|
html_options[prop.to_s] = options.delete(prop) if options.key?(prop) && !html_options.key?(prop.to_s)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
add_default_name_and_field(html_options)
|
|
15
15
|
|
|
16
16
|
if placeholder_required?(html_options)
|
|
17
17
|
raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
|
|
@@ -10,7 +10,7 @@ module ActionView
|
|
|
10
10
|
|
|
11
11
|
def render
|
|
12
12
|
options = @options.stringify_keys
|
|
13
|
-
|
|
13
|
+
add_default_name_and_field(options)
|
|
14
14
|
|
|
15
15
|
if size = options.delete("size")
|
|
16
16
|
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
|
|
@@ -13,7 +13,7 @@ module ActionView
|
|
|
13
13
|
options["size"] = options["maxlength"] unless options.key?("size")
|
|
14
14
|
options["type"] ||= field_type
|
|
15
15
|
options["value"] = options.fetch("value") { value_before_type_cast } unless field_type == "file"
|
|
16
|
-
|
|
16
|
+
add_default_name_and_field(options)
|
|
17
17
|
tag("input", options)
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -500,8 +500,6 @@ module ActionView
|
|
|
500
500
|
content_tag("a", name || email_address, html_options, &block)
|
|
501
501
|
end
|
|
502
502
|
|
|
503
|
-
RFC2396_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new
|
|
504
|
-
|
|
505
503
|
# True if the current request URI was generated by the given +options+.
|
|
506
504
|
#
|
|
507
505
|
# ==== Examples
|
|
@@ -558,14 +556,14 @@ module ActionView
|
|
|
558
556
|
|
|
559
557
|
options ||= options_as_kwargs
|
|
560
558
|
check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters)
|
|
561
|
-
url_string = RFC2396_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
|
|
559
|
+
url_string = URI::RFC2396_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
|
|
562
560
|
|
|
563
561
|
# We ignore any extra parameters in the request_uri if the
|
|
564
562
|
# submitted URL doesn't have any either. This lets the function
|
|
565
563
|
# work with things like ?order=asc
|
|
566
564
|
# the behavior can be disabled with check_parameters: true
|
|
567
565
|
request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
|
|
568
|
-
request_uri = RFC2396_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
|
|
566
|
+
request_uri = URI::RFC2396_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
|
|
569
567
|
|
|
570
568
|
if %r{^\w+://}.match?(url_string)
|
|
571
569
|
request_uri = +"#{request.protocol}#{request.host_with_port}#{request_uri}"
|
data/lib/action_view/layouts.rb
CHANGED
|
@@ -97,9 +97,21 @@ module ActionView
|
|
|
97
97
|
def render_call_template(node)
|
|
98
98
|
object_template = false
|
|
99
99
|
template =
|
|
100
|
-
|
|
100
|
+
case node.type
|
|
101
|
+
when :string_node
|
|
101
102
|
path = node.unescaped
|
|
102
103
|
path.include?("/") ? path : "#{directory}/#{path}"
|
|
104
|
+
when :interpolated_string_node
|
|
105
|
+
node.parts.map do |node|
|
|
106
|
+
case node.type
|
|
107
|
+
when :string_node
|
|
108
|
+
node.unescaped
|
|
109
|
+
when :embedded_statements_node
|
|
110
|
+
"*"
|
|
111
|
+
else
|
|
112
|
+
return
|
|
113
|
+
end
|
|
114
|
+
end.join("")
|
|
103
115
|
else
|
|
104
116
|
dependency =
|
|
105
117
|
case node.type
|
|
@@ -66,7 +66,16 @@ module ActionView
|
|
|
66
66
|
|
|
67
67
|
def to_string
|
|
68
68
|
raise unless string?
|
|
69
|
-
|
|
69
|
+
|
|
70
|
+
# s(:string_literal, s(:string_content, map))
|
|
71
|
+
self[0].map do |node|
|
|
72
|
+
case node.type
|
|
73
|
+
when :@tstring_content
|
|
74
|
+
node[0]
|
|
75
|
+
when :string_embexpr
|
|
76
|
+
"*"
|
|
77
|
+
end
|
|
78
|
+
end.join("")
|
|
70
79
|
end
|
|
71
80
|
|
|
72
81
|
def hash?
|
|
@@ -111,7 +111,11 @@ module ActionView
|
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
unless entries_to_write.empty?
|
|
114
|
-
|
|
114
|
+
if @options[:cached].is_a?(Hash) && @options[:cached].key?(:expires_in)
|
|
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
|
|
115
119
|
end
|
|
116
120
|
|
|
117
121
|
keyed_partials
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "fiber"
|
|
4
3
|
|
|
5
4
|
module ActionView
|
|
6
5
|
# == TODO
|
|
@@ -26,6 +25,13 @@ module ActionView
|
|
|
26
25
|
self
|
|
27
26
|
end
|
|
28
27
|
|
|
28
|
+
# Returns the complete body as a string.
|
|
29
|
+
def body
|
|
30
|
+
buffer = String.new
|
|
31
|
+
each { |part| buffer << part }
|
|
32
|
+
buffer
|
|
33
|
+
end
|
|
34
|
+
|
|
29
35
|
private
|
|
30
36
|
# This is the same logging logic as in ShowExceptions middleware.
|
|
31
37
|
def log_error(exception)
|
|
@@ -43,7 +49,7 @@ module ActionView
|
|
|
43
49
|
# object that responds to each. This object is initialized with a block
|
|
44
50
|
# that knows how to render the template.
|
|
45
51
|
def render_template(view, template, layout_name = nil, locals = {}) # :nodoc:
|
|
46
|
-
return [super.body] unless
|
|
52
|
+
return [super.body] unless template.supports_streaming?
|
|
47
53
|
|
|
48
54
|
locals ||= {}
|
|
49
55
|
layout = find_layout(layout_name, locals.keys, [formats.first])
|