actionview 4.2.11.1 → 6.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +201 -192
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -8
- data/lib/action_view/base.rb +144 -37
- data/lib/action_view/buffers.rb +18 -1
- data/lib/action_view/cache_expiry.rb +53 -0
- data/lib/action_view/context.rb +8 -12
- data/lib/action_view/dependency_tracker.rb +54 -20
- data/lib/action_view/digestor.rb +88 -85
- data/lib/action_view/flows.rb +11 -12
- data/lib/action_view/gem_version.rb +6 -4
- data/lib/action_view/helpers/active_model_helper.rb +16 -11
- data/lib/action_view/helpers/asset_tag_helper.rb +241 -82
- data/lib/action_view/helpers/asset_url_helper.rb +171 -67
- data/lib/action_view/helpers/atom_feed_helper.rb +19 -17
- data/lib/action_view/helpers/cache_helper.rb +112 -42
- data/lib/action_view/helpers/capture_helper.rb +20 -13
- data/lib/action_view/helpers/controller_helper.rb +15 -4
- data/lib/action_view/helpers/csp_helper.rb +26 -0
- data/lib/action_view/helpers/csrf_helper.rb +8 -6
- data/lib/action_view/helpers/date_helper.rb +230 -129
- data/lib/action_view/helpers/debug_helper.rb +7 -6
- data/lib/action_view/helpers/form_helper.rb +755 -129
- data/lib/action_view/helpers/form_options_helper.rb +130 -75
- data/lib/action_view/helpers/form_tag_helper.rb +116 -71
- data/lib/action_view/helpers/javascript_helper.rb +30 -14
- data/lib/action_view/helpers/number_helper.rb +84 -59
- data/lib/action_view/helpers/output_safety_helper.rb +36 -4
- data/lib/action_view/helpers/rendering_helper.rb +11 -8
- data/lib/action_view/helpers/sanitize_helper.rb +30 -31
- data/lib/action_view/helpers/tag_helper.rb +201 -75
- data/lib/action_view/helpers/tags/base.rb +138 -98
- data/lib/action_view/helpers/tags/check_box.rb +20 -19
- data/lib/action_view/helpers/tags/checkable.rb +4 -2
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -34
- data/lib/action_view/helpers/tags/collection_helpers.rb +69 -36
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -12
- data/lib/action_view/helpers/tags/collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/color_field.rb +4 -3
- data/lib/action_view/helpers/tags/date_field.rb +2 -1
- data/lib/action_view/helpers/tags/date_select.rb +37 -36
- data/lib/action_view/helpers/tags/datetime_field.rb +4 -3
- data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -1
- data/lib/action_view/helpers/tags/datetime_select.rb +2 -0
- data/lib/action_view/helpers/tags/email_field.rb +2 -0
- data/lib/action_view/helpers/tags/file_field.rb +2 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/hidden_field.rb +2 -0
- data/lib/action_view/helpers/tags/label.rb +3 -2
- data/lib/action_view/helpers/tags/month_field.rb +2 -1
- data/lib/action_view/helpers/tags/number_field.rb +2 -0
- data/lib/action_view/helpers/tags/password_field.rb +3 -1
- data/lib/action_view/helpers/tags/placeholderable.rb +3 -1
- data/lib/action_view/helpers/tags/radio_button.rb +7 -6
- data/lib/action_view/helpers/tags/range_field.rb +2 -0
- data/lib/action_view/helpers/tags/search_field.rb +14 -9
- data/lib/action_view/helpers/tags/select.rb +11 -10
- data/lib/action_view/helpers/tags/tel_field.rb +2 -0
- data/lib/action_view/helpers/tags/text_area.rb +4 -2
- data/lib/action_view/helpers/tags/text_field.rb +8 -8
- data/lib/action_view/helpers/tags/time_field.rb +2 -1
- data/lib/action_view/helpers/tags/time_select.rb +2 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +3 -1
- data/lib/action_view/helpers/tags/translator.rb +15 -16
- data/lib/action_view/helpers/tags/url_field.rb +2 -0
- data/lib/action_view/helpers/tags/week_field.rb +2 -1
- data/lib/action_view/helpers/tags.rb +3 -1
- data/lib/action_view/helpers/text_helper.rb +56 -38
- data/lib/action_view/helpers/translation_helper.rb +91 -47
- data/lib/action_view/helpers/url_helper.rb +160 -105
- data/lib/action_view/helpers.rb +5 -3
- data/lib/action_view/layouts.rb +65 -61
- data/lib/action_view/log_subscriber.rb +61 -10
- data/lib/action_view/lookup_context.rb +147 -89
- data/lib/action_view/model_naming.rb +3 -1
- data/lib/action_view/path_set.rb +28 -23
- data/lib/action_view/railtie.rb +62 -6
- data/lib/action_view/record_identifier.rb +53 -26
- data/lib/action_view/renderer/abstract_renderer.rb +71 -13
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
- data/lib/action_view/renderer/partial_renderer.rb +239 -225
- data/lib/action_view/renderer/renderer.rb +22 -8
- data/lib/action_view/renderer/streaming_template_renderer.rb +54 -54
- data/lib/action_view/renderer/template_renderer.rb +79 -73
- data/lib/action_view/rendering.rb +68 -44
- data/lib/action_view/routing_url_for.rb +33 -22
- data/lib/action_view/tasks/cache_digests.rake +25 -0
- data/lib/action_view/template/error.rb +44 -29
- data/lib/action_view/template/handlers/builder.rb +12 -13
- data/lib/action_view/template/handlers/erb/erubi.rb +87 -0
- data/lib/action_view/template/handlers/erb.rb +24 -86
- data/lib/action_view/template/handlers/html.rb +11 -0
- data/lib/action_view/template/handlers/raw.rb +4 -4
- data/lib/action_view/template/handlers.rb +38 -8
- data/lib/action_view/template/html.rb +19 -10
- data/lib/action_view/template/inline.rb +22 -0
- data/lib/action_view/template/raw_file.rb +28 -0
- data/lib/action_view/template/resolver.rb +217 -193
- data/lib/action_view/template/sources/file.rb +17 -0
- data/lib/action_view/template/sources.rb +13 -0
- data/lib/action_view/template/text.rb +11 -10
- data/lib/action_view/template/types.rb +18 -18
- data/lib/action_view/template.rb +146 -90
- data/lib/action_view/test_case.rb +52 -32
- data/lib/action_view/testing/resolvers.rb +46 -34
- data/lib/action_view/unbound_template.rb +31 -0
- data/lib/action_view/version.rb +3 -1
- data/lib/action_view/view_paths.rb +48 -31
- data/lib/action_view.rb +11 -8
- data/lib/assets/compiled/rails-ujs.js +746 -0
- metadata +38 -29
- data/lib/action_view/helpers/record_tag_helper.rb +0 -108
- data/lib/action_view/tasks/dependencies.rake +0 -23
data/lib/action_view/digestor.rb
CHANGED
@@ -1,123 +1,126 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/dependency_tracker"
|
4
4
|
|
5
5
|
module ActionView
|
6
6
|
class Digestor
|
7
|
-
|
8
|
-
@@cache = ThreadSafe::Cache.new
|
9
|
-
@@digest_monitor = Monitor.new
|
7
|
+
@@digest_mutex = Mutex.new
|
10
8
|
|
11
9
|
class << self
|
12
10
|
# Supported options:
|
13
11
|
#
|
14
|
-
# * <tt>name</tt>
|
15
|
-
# * <tt>
|
16
|
-
# * <tt>
|
17
|
-
# * <tt>
|
18
|
-
def digest(
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
# * <tt>name</tt> - Template name
|
13
|
+
# * <tt>format</tt> - Template format
|
14
|
+
# * <tt>finder</tt> - An instance of <tt>ActionView::LookupContext</tt>
|
15
|
+
# * <tt>dependencies</tt> - An array of dependent views
|
16
|
+
def digest(name:, format: nil, finder:, dependencies: nil)
|
17
|
+
if dependencies.nil? || dependencies.empty?
|
18
|
+
cache_key = "#{name}.#{format}"
|
19
|
+
else
|
20
|
+
cache_key = [ name, format, dependencies ].flatten.compact.join(".")
|
21
|
+
end
|
22
22
|
|
23
23
|
# this is a correctly done double-checked locking idiom
|
24
|
-
# (
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# (Concurrent::Map's lookups have volatile semantics)
|
25
|
+
finder.digest_cache[cache_key] || @@digest_mutex.synchronize do
|
26
|
+
finder.digest_cache.fetch(cache_key) do # re-check under lock
|
27
|
+
partial = name.include?("/_")
|
28
|
+
root = tree(name, finder, partial)
|
29
|
+
dependencies.each do |injected_dep|
|
30
|
+
root.children << Injected.new(injected_dep, nil, nil)
|
31
|
+
end if dependencies
|
32
|
+
finder.digest_cache[cache_key] = root.digest(finder)
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# Prevent re-entry or else recursive templates will blow the stack.
|
36
|
-
# There is no need to worry about other threads seeing the +false+ value,
|
37
|
-
# as they will then have to wait for this thread to let go of the @@digest_monitor lock.
|
38
|
-
pre_stored = @@cache.put_if_absent(cache_key, false).nil? # put_if_absent returns nil on insertion
|
39
|
-
PartialDigestor
|
40
|
-
else
|
41
|
-
Digestor
|
42
|
-
end
|
37
|
+
def logger
|
38
|
+
ActionView::Base.logger || NullLogger
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
digest
|
48
|
-
ensure
|
49
|
-
# something went wrong or ActionView::Resolver.caching? is false, make sure not to corrupt the @@cache
|
50
|
-
@@cache.delete_pair(cache_key, false) if pre_stored && !stored_digest
|
51
|
-
end
|
52
|
-
end
|
41
|
+
# Create a dependency tree for template named +name+.
|
42
|
+
def tree(name, finder, partial = false, seen = {})
|
43
|
+
logical_name = name.gsub(%r|/_|, "/")
|
53
44
|
|
54
|
-
|
45
|
+
if template = find_template(finder, logical_name, [], partial, [])
|
46
|
+
if node = seen[template.identifier] # handle cycles in the tree
|
47
|
+
node
|
48
|
+
else
|
49
|
+
node = seen[template.identifier] = Node.create(name, logical_name, template, partial)
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
deps = DependencyTracker.find_dependencies(name, template, finder.view_paths)
|
52
|
+
deps.uniq { |n| n.gsub(%r|/_|, "/") }.each do |dep_file|
|
53
|
+
node.children << tree(dep_file, finder, true, seen)
|
54
|
+
end
|
55
|
+
node
|
56
|
+
end
|
57
|
+
else
|
58
|
+
unless name.include?("#") # Dynamic template partial names can never be tracked
|
59
|
+
logger.error " Couldn't find template for digesting: #{name}"
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
logger.try :debug, " Cache digest for #{template.inspect}: #{digest}"
|
62
|
+
seen[name] ||= Missing.new(name, logical_name, nil)
|
63
|
+
end
|
64
64
|
end
|
65
|
-
rescue ActionView::MissingTemplate
|
66
|
-
logger.try :error, " Couldn't find template for digesting: #{name}"
|
67
|
-
''
|
68
|
-
end
|
69
65
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
private
|
67
|
+
def find_template(finder, name, prefixes, partial, keys)
|
68
|
+
finder.disable_cache do
|
69
|
+
finder.find_all(name, prefixes, partial, keys).first
|
70
|
+
end
|
71
|
+
end
|
75
72
|
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
dependencies = PartialDigestor.new(name: dependency, finder: finder).nested_dependencies
|
80
|
-
dependencies.any? ? { dependency => dependencies } : dependency
|
81
|
-
end
|
82
|
-
end
|
74
|
+
class Node
|
75
|
+
attr_reader :name, :logical_name, :template, :children
|
83
76
|
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
def self.create(name, logical_name, template, partial)
|
78
|
+
klass = partial ? Partial : Node
|
79
|
+
klass.new(name, logical_name, template, [])
|
87
80
|
end
|
88
81
|
|
89
|
-
def logical_name
|
90
|
-
name
|
82
|
+
def initialize(name, logical_name, template, children = [])
|
83
|
+
@name = name
|
84
|
+
@logical_name = logical_name
|
85
|
+
@template = template
|
86
|
+
@children = children
|
91
87
|
end
|
92
88
|
|
93
|
-
def
|
94
|
-
|
89
|
+
def digest(finder, stack = [])
|
90
|
+
ActiveSupport::Digest.hexdigest("#{template.source}-#{dependency_digest(finder, stack)}")
|
95
91
|
end
|
96
92
|
|
97
|
-
def
|
98
|
-
|
93
|
+
def dependency_digest(finder, stack)
|
94
|
+
children.map do |node|
|
95
|
+
if stack.include?(node)
|
96
|
+
false
|
97
|
+
else
|
98
|
+
finder.digest_cache[node.name] ||= begin
|
99
|
+
stack.push node
|
100
|
+
node.digest(finder, stack).tap { stack.pop }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end.join("-")
|
99
104
|
end
|
100
105
|
|
101
|
-
def
|
102
|
-
|
106
|
+
def to_dep_map
|
107
|
+
children.any? ? { name => children.map(&:to_dep_map) } : name
|
103
108
|
end
|
109
|
+
end
|
104
110
|
|
105
|
-
|
106
|
-
template_digests = dependencies.collect do |template_name|
|
107
|
-
Digestor.digest(name: template_name, finder: finder, partial: true)
|
108
|
-
end
|
111
|
+
class Partial < Node; end
|
109
112
|
|
110
|
-
|
111
|
-
end
|
113
|
+
class Missing < Node
|
114
|
+
def digest(finder, _ = []) "" end
|
115
|
+
end
|
112
116
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
+
class Injected < Node
|
118
|
+
def digest(finder, _ = []) name end
|
119
|
+
end
|
117
120
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
+
class NullLogger
|
122
|
+
def self.debug(_); end
|
123
|
+
def self.error(_); end
|
121
124
|
end
|
122
125
|
end
|
123
126
|
end
|
data/lib/action_view/flows.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/string/output_safety"
|
2
4
|
|
3
5
|
module ActionView
|
4
6
|
class OutputFlow #:nodoc:
|
5
7
|
attr_reader :content
|
6
8
|
|
7
9
|
def initialize
|
8
|
-
@content = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
|
10
|
+
@content = Hash.new { |h, k| h[k] = ActiveSupport::SafeBuffer.new }
|
9
11
|
end
|
10
12
|
|
11
13
|
# Called by _layout_for to read stored values.
|
@@ -23,7 +25,6 @@ module ActionView
|
|
23
25
|
@content[key] << value
|
24
26
|
end
|
25
27
|
alias_method :append!, :append
|
26
|
-
|
27
28
|
end
|
28
29
|
|
29
30
|
class StreamingFlow < OutputFlow #:nodoc:
|
@@ -37,9 +38,8 @@ module ActionView
|
|
37
38
|
end
|
38
39
|
|
39
40
|
# Try to get stored content. If the content
|
40
|
-
# is not available and we
|
41
|
-
#
|
42
|
-
# key and yield.
|
41
|
+
# is not available and we're inside the layout fiber,
|
42
|
+
# then it will begin waiting for the given key and yield.
|
43
43
|
def get(key)
|
44
44
|
return super if @content.key?(key)
|
45
45
|
|
@@ -60,17 +60,16 @@ module ActionView
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# Appends the contents for the given key. This is called
|
63
|
-
# by
|
64
|
-
# the key it
|
63
|
+
# by providing and resuming back to the fiber,
|
64
|
+
# if that's the key it's waiting for.
|
65
65
|
def append!(key, value)
|
66
66
|
super
|
67
67
|
@fiber.resume if @waiting_for == key
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
71
|
+
def inside_fiber?
|
72
|
+
Fiber.current.object_id != @root
|
73
|
+
end
|
75
74
|
end
|
76
75
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionView
|
2
4
|
# Returns the version of the currently loaded Action View as a <tt>Gem::Version</tt>
|
3
5
|
def self.gem_version
|
@@ -5,10 +7,10 @@ module ActionView
|
|
5
7
|
end
|
6
8
|
|
7
9
|
module VERSION
|
8
|
-
MAJOR =
|
9
|
-
MINOR =
|
10
|
-
TINY =
|
11
|
-
PRE =
|
10
|
+
MAJOR = 6
|
11
|
+
MINOR = 0
|
12
|
+
TINY = 4
|
13
|
+
PRE = nil
|
12
14
|
|
13
15
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
14
16
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/core_ext/enumerable"
|
3
5
|
|
4
6
|
module ActionView
|
5
7
|
# = Active Model Helpers
|
6
|
-
module Helpers
|
8
|
+
module Helpers #:nodoc:
|
7
9
|
module ActiveModelHelper
|
8
10
|
end
|
9
11
|
|
@@ -15,8 +17,8 @@ module ActionView
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
def content_tag(*)
|
19
|
-
error_wrapping(super)
|
20
|
+
def content_tag(type, options, *)
|
21
|
+
select_markup_helper?(type) ? super : error_wrapping(super)
|
20
22
|
end
|
21
23
|
|
22
24
|
def tag(type, options, *)
|
@@ -36,14 +38,17 @@ module ActionView
|
|
36
38
|
end
|
37
39
|
|
38
40
|
private
|
41
|
+
def object_has_errors?
|
42
|
+
object.respond_to?(:errors) && object.errors.respond_to?(:[]) && error_message.present?
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
def select_markup_helper?(type)
|
46
|
+
["optgroup", "option"].include?(type)
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
def tag_generate_errors?(options)
|
50
|
+
options["type"] != "hidden"
|
51
|
+
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|