actionview 4.2.11.1 → 7.0.2.4
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.
Potentially problematic release.
This version of actionview might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +229 -215
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -8
- data/lib/action_view/base.rb +116 -43
- data/lib/action_view/buffers.rb +20 -3
- data/lib/action_view/cache_expiry.rb +66 -0
- data/lib/action_view/context.rb +8 -12
- data/lib/action_view/dependency_tracker/erb_tracker.rb +154 -0
- data/lib/action_view/dependency_tracker/ripper_tracker.rb +59 -0
- data/lib/action_view/dependency_tracker.rb +21 -122
- data/lib/action_view/digestor.rb +92 -85
- data/lib/action_view/flows.rb +15 -16
- data/lib/action_view/gem_version.rb +6 -4
- data/lib/action_view/helpers/active_model_helper.rb +17 -12
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -101
- data/lib/action_view/helpers/asset_url_helper.rb +180 -74
- data/lib/action_view/helpers/atom_feed_helper.rb +21 -19
- data/lib/action_view/helpers/cache_helper.rb +156 -43
- data/lib/action_view/helpers/capture_helper.rb +21 -14
- data/lib/action_view/helpers/controller_helper.rb +16 -5
- 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 +288 -132
- data/lib/action_view/helpers/debug_helper.rb +9 -6
- data/lib/action_view/helpers/form_helper.rb +956 -173
- data/lib/action_view/helpers/form_options_helper.rb +178 -97
- data/lib/action_view/helpers/form_tag_helper.rb +220 -101
- data/lib/action_view/helpers/javascript_helper.rb +33 -19
- data/lib/action_view/helpers/number_helper.rb +88 -63
- data/lib/action_view/helpers/output_safety_helper.rb +38 -6
- data/lib/action_view/helpers/rendering_helper.rb +21 -10
- data/lib/action_view/helpers/sanitize_helper.rb +31 -32
- data/lib/action_view/helpers/tag_helper.rb +332 -71
- data/lib/action_view/helpers/tags/base.rb +123 -99
- data/lib/action_view/helpers/tags/check_box.rb +21 -20
- 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 +5 -3
- data/lib/action_view/helpers/tags/color_field.rb +4 -3
- data/lib/action_view/helpers/tags/date_field.rb +3 -2
- data/lib/action_view/helpers/tags/date_select.rb +38 -37
- data/lib/action_view/helpers/tags/datetime_field.rb +4 -3
- data/lib/action_view/helpers/tags/datetime_local_field.rb +3 -2
- 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 +18 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/hidden_field.rb +6 -0
- data/lib/action_view/helpers/tags/label.rb +7 -2
- data/lib/action_view/helpers/tags/month_field.rb +3 -2
- 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 +12 -2
- 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 +3 -2
- data/lib/action_view/helpers/tags/weekday_select.rb +28 -0
- data/lib/action_view/helpers/tags.rb +5 -2
- data/lib/action_view/helpers/text_helper.rb +80 -51
- data/lib/action_view/helpers/translation_helper.rb +120 -69
- data/lib/action_view/helpers/url_helper.rb +398 -171
- data/lib/action_view/helpers.rb +29 -27
- data/lib/action_view/layouts.rb +68 -63
- data/lib/action_view/log_subscriber.rb +77 -10
- data/lib/action_view/lookup_context.rb +137 -113
- data/lib/action_view/model_naming.rb +4 -2
- data/lib/action_view/path_set.rb +28 -32
- data/lib/action_view/railtie.rb +74 -13
- data/lib/action_view/record_identifier.rb +53 -26
- data/lib/action_view/render_parser.rb +188 -0
- data/lib/action_view/renderer/abstract_renderer.rb +152 -15
- data/lib/action_view/renderer/collection_renderer.rb +196 -0
- data/lib/action_view/renderer/object_renderer.rb +34 -0
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +102 -0
- data/lib/action_view/renderer/partial_renderer.rb +51 -333
- data/lib/action_view/renderer/renderer.rb +68 -11
- data/lib/action_view/renderer/streaming_template_renderer.rb +60 -56
- data/lib/action_view/renderer/template_renderer.rb +87 -74
- data/lib/action_view/rendering.rb +73 -47
- data/lib/action_view/ripper_ast_parser.rb +198 -0
- data/lib/action_view/routing_url_for.rb +35 -24
- data/lib/action_view/tasks/cache_digests.rake +25 -0
- data/lib/action_view/template/error.rb +151 -41
- data/lib/action_view/template/handlers/builder.rb +12 -13
- data/lib/action_view/template/handlers/erb/erubi.rb +89 -0
- data/lib/action_view/template/handlers/erb.rb +29 -89
- 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 +14 -10
- data/lib/action_view/template/html.rb +12 -13
- data/lib/action_view/template/inline.rb +22 -0
- data/lib/action_view/template/raw_file.rb +25 -0
- data/lib/action_view/template/renderable.rb +24 -0
- data/lib/action_view/template/resolver.rb +139 -300
- 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 +10 -12
- data/lib/action_view/template/types.rb +28 -26
- data/lib/action_view/template.rb +123 -91
- data/lib/action_view/template_details.rb +66 -0
- data/lib/action_view/template_path.rb +64 -0
- data/lib/action_view/test_case.rb +70 -53
- data/lib/action_view/testing/resolvers.rb +25 -35
- data/lib/action_view/unbound_template.rb +57 -0
- data/lib/action_view/version.rb +3 -1
- data/lib/action_view/view_paths.rb +73 -58
- data/lib/action_view.rb +16 -11
- data/lib/assets/compiled/rails-ujs.js +746 -0
- metadata +52 -32
- data/lib/action_view/helpers/record_tag_helper.rb +0 -108
- data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
require 'action_controller'
|
3
|
-
require 'action_controller/test_case'
|
4
|
-
require 'action_view'
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
require
|
3
|
+
require "active_support/core_ext/module/redefine_method"
|
4
|
+
require "action_controller"
|
5
|
+
require "action_controller/test_case"
|
6
|
+
require "action_view"
|
7
|
+
|
8
|
+
require "rails-dom-testing"
|
7
9
|
|
8
10
|
module ActionView
|
9
11
|
# = Action View Test Case
|
@@ -14,21 +16,26 @@ module ActionView
|
|
14
16
|
attr_accessor :request, :response, :params
|
15
17
|
|
16
18
|
class << self
|
17
|
-
|
19
|
+
# Overrides AbstractController::Base#controller_path
|
20
|
+
attr_accessor :controller_path
|
18
21
|
end
|
19
22
|
|
20
23
|
def controller_path=(path)
|
21
|
-
self.class.controller_path=
|
24
|
+
self.class.controller_path = path
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.controller_name
|
28
|
+
"test"
|
22
29
|
end
|
23
30
|
|
24
31
|
def initialize
|
25
32
|
super
|
26
33
|
self.class.controller_path = ""
|
27
|
-
@request = ActionController::TestRequest.
|
28
|
-
@response =
|
34
|
+
@request = ActionController::TestRequest.create(self.class)
|
35
|
+
@response = ActionDispatch::TestResponse.new
|
29
36
|
|
30
|
-
@request.env.delete(
|
31
|
-
@params =
|
37
|
+
@request.env.delete("PATH_INFO")
|
38
|
+
@params = ActionController::Parameters.new
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
@@ -49,7 +56,7 @@ module ActionView
|
|
49
56
|
|
50
57
|
include ActiveSupport::Testing::ConstantLookup
|
51
58
|
|
52
|
-
delegate :lookup_context, :
|
59
|
+
delegate :lookup_context, to: :controller
|
53
60
|
attr_accessor :controller, :output_buffer, :rendered
|
54
61
|
|
55
62
|
module ClassMethods
|
@@ -71,10 +78,11 @@ module ActionView
|
|
71
78
|
def helper_method(*methods)
|
72
79
|
# Almost a duplicate from ActionController::Helpers
|
73
80
|
methods.flatten.each do |method|
|
74
|
-
|
81
|
+
_helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
|
75
82
|
def #{method}(*args, &block) # def current_user(*args, &block)
|
76
|
-
_test_case.send(
|
83
|
+
_test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block)
|
77
84
|
end # end
|
85
|
+
ruby2_keywords(:'#{method}')
|
78
86
|
end_eval
|
79
87
|
end
|
80
88
|
end
|
@@ -91,24 +99,24 @@ module ActionView
|
|
91
99
|
end
|
92
100
|
|
93
101
|
private
|
94
|
-
|
95
102
|
def include_helper_modules!
|
96
103
|
helper(helper_class) if helper_class
|
97
104
|
include _helpers
|
98
105
|
end
|
99
|
-
|
100
106
|
end
|
101
107
|
|
102
108
|
def setup_with_controller
|
103
|
-
|
109
|
+
controller_class = Class.new(ActionView::TestCase::TestController)
|
110
|
+
@controller = controller_class.new
|
104
111
|
@request = @controller.request
|
112
|
+
@view_flow = ActionView::OutputFlow.new
|
105
113
|
# empty string ensures buffer has UTF-8 encoding as
|
106
114
|
# new without arguments returns ASCII-8BIT encoded buffer like String#new
|
107
|
-
@output_buffer = ActiveSupport::SafeBuffer.new
|
108
|
-
@rendered =
|
115
|
+
@output_buffer = ActiveSupport::SafeBuffer.new ""
|
116
|
+
@rendered = +""
|
109
117
|
|
110
|
-
|
111
|
-
|
118
|
+
test_case_instance = self
|
119
|
+
controller_class.define_method(:_test_case) { test_case_instance }
|
112
120
|
end
|
113
121
|
|
114
122
|
def config
|
@@ -125,6 +133,10 @@ module ActionView
|
|
125
133
|
@_rendered_views ||= RenderedViewsCollection.new
|
126
134
|
end
|
127
135
|
|
136
|
+
def _routes
|
137
|
+
@controller._routes if @controller.respond_to?(:_routes)
|
138
|
+
end
|
139
|
+
|
128
140
|
# Need to experiment if this priority is the best one: rendered => output_buffer
|
129
141
|
class RenderedViewsCollection
|
130
142
|
def initialize
|
@@ -146,41 +158,32 @@ module ActionView
|
|
146
158
|
|
147
159
|
def view_rendered?(view, expected_locals)
|
148
160
|
locals_for(view).any? do |actual_locals|
|
149
|
-
expected_locals.all? {|key, value| value == actual_locals[key] }
|
161
|
+
expected_locals.all? { |key, value| value == actual_locals[key] }
|
150
162
|
end
|
151
163
|
end
|
152
164
|
end
|
153
165
|
|
154
166
|
included do
|
155
167
|
setup :setup_with_controller
|
156
|
-
|
157
|
-
|
158
|
-
private
|
168
|
+
ActiveSupport.run_load_hooks(:action_view_test_case, self)
|
159
169
|
|
160
|
-
|
161
|
-
def document_root_element
|
162
|
-
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root
|
163
|
-
end
|
164
|
-
|
165
|
-
def say_no_to_protect_against_forgery!
|
166
|
-
_helpers.module_eval do
|
167
|
-
remove_possible_method :protect_against_forgery?
|
170
|
+
helper do
|
168
171
|
def protect_against_forgery?
|
169
172
|
false
|
170
173
|
end
|
171
|
-
end
|
172
|
-
end
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
_helpers.module_eval do
|
177
|
-
unless private_method_defined?(:_test_case)
|
178
|
-
define_method(:_test_case) { test_case_instance }
|
179
|
-
private :_test_case
|
175
|
+
def _test_case
|
176
|
+
controller._test_case
|
180
177
|
end
|
181
178
|
end
|
182
179
|
end
|
183
180
|
|
181
|
+
private
|
182
|
+
# Need to experiment if this priority is the best one: rendered => output_buffer
|
183
|
+
def document_root_element
|
184
|
+
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root
|
185
|
+
end
|
186
|
+
|
184
187
|
module Locals
|
185
188
|
attr_accessor :rendered_views
|
186
189
|
|
@@ -204,10 +207,10 @@ module ActionView
|
|
204
207
|
def view
|
205
208
|
@view ||= begin
|
206
209
|
view = @controller.view_context
|
207
|
-
view.singleton_class.
|
210
|
+
view.singleton_class.include(_helpers)
|
208
211
|
view.extend(Locals)
|
209
|
-
view.rendered_views =
|
210
|
-
view.output_buffer =
|
212
|
+
view.rendered_views = rendered_views
|
213
|
+
view.output_buffer = output_buffer
|
211
214
|
view
|
212
215
|
end
|
213
216
|
end
|
@@ -240,9 +243,9 @@ module ActionView
|
|
240
243
|
:@test_passed,
|
241
244
|
:@view,
|
242
245
|
:@view_context_class,
|
246
|
+
:@view_flow,
|
243
247
|
:@_subscribers,
|
244
|
-
:@html_document
|
245
|
-
:@html_scanner_document
|
248
|
+
:@html_document
|
246
249
|
]
|
247
250
|
|
248
251
|
def _user_defined_ivars
|
@@ -259,19 +262,33 @@ module ActionView
|
|
259
262
|
end]
|
260
263
|
end
|
261
264
|
|
262
|
-
def _routes
|
263
|
-
@controller._routes if @controller.respond_to?(:_routes)
|
264
|
-
end
|
265
|
-
|
266
265
|
def method_missing(selector, *args)
|
267
|
-
|
268
|
-
|
269
|
-
|
266
|
+
begin
|
267
|
+
routes = @controller.respond_to?(:_routes) && @controller._routes
|
268
|
+
rescue
|
269
|
+
# Don't call routes, if there is an error on _routes call
|
270
|
+
end
|
271
|
+
|
272
|
+
if routes &&
|
273
|
+
(routes.named_routes.route_defined?(selector) ||
|
274
|
+
routes.mounted_helpers.method_defined?(selector))
|
270
275
|
@controller.__send__(selector, *args)
|
271
276
|
else
|
272
277
|
super
|
273
278
|
end
|
274
279
|
end
|
280
|
+
|
281
|
+
def respond_to_missing?(name, include_private = false)
|
282
|
+
begin
|
283
|
+
routes = defined?(@controller) && @controller.respond_to?(:_routes) && @controller._routes
|
284
|
+
rescue
|
285
|
+
# Don't call routes, if there is an error on _routes call
|
286
|
+
end
|
287
|
+
|
288
|
+
routes &&
|
289
|
+
(routes.named_routes.route_defined?(name) ||
|
290
|
+
routes.mounted_helpers.method_defined?(name))
|
291
|
+
end
|
275
292
|
end
|
276
293
|
|
277
294
|
include Behavior
|
@@ -1,54 +1,44 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "action_view/template/resolver"
|
4
|
+
|
5
|
+
module ActionView # :nodoc:
|
4
6
|
# Use FixtureResolver in your tests to simulate the presence of files on the
|
5
7
|
# file system. This is used internally by Rails' own test suite, and is
|
6
8
|
# useful for testing extensions that have no way of knowing what the file
|
7
9
|
# system will look like at runtime.
|
8
|
-
class FixtureResolver <
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(hash = {}, pattern=nil)
|
12
|
-
super(pattern)
|
10
|
+
class FixtureResolver < FileSystemResolver
|
11
|
+
def initialize(hash = {})
|
12
|
+
super("")
|
13
13
|
@hash = hash
|
14
|
+
@path = ""
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
@hash
|
17
|
+
def data
|
18
|
+
@hash
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
+
def to_s
|
22
|
+
@hash.keys.join(", ")
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
private
|
26
|
+
def template_glob(glob)
|
27
|
+
@hash.keys.filter_map do |path|
|
28
|
+
"/#{path}" if File.fnmatch(glob, path)
|
29
|
+
end
|
26
30
|
end
|
27
|
-
query = /^(#{Regexp.escape(path)})#{query}$/
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
source, updated_at = array
|
32
|
-
next unless _path =~ query
|
33
|
-
handler, format, variant = extract_handler_and_format_and_variant(_path, formats)
|
34
|
-
templates << Template.new(source, _path, handler,
|
35
|
-
:virtual_path => path.virtual,
|
36
|
-
:format => format,
|
37
|
-
:variant => variant,
|
38
|
-
:updated_at => updated_at
|
39
|
-
)
|
32
|
+
def source_for_template(template)
|
33
|
+
@hash[template.from(1)]
|
40
34
|
end
|
41
|
-
|
42
|
-
templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
|
43
|
-
end
|
44
35
|
end
|
45
36
|
|
46
|
-
class NullResolver <
|
47
|
-
def
|
48
|
-
|
49
|
-
|
37
|
+
class NullResolver < Resolver
|
38
|
+
def find_templates(name, prefix, partial, details, locals = [])
|
39
|
+
path = TemplatePath.build(name, prefix, partial)
|
40
|
+
handler = ActionView::Template::Handlers::Raw
|
41
|
+
[ActionView::Template.new("Template generated by Null Resolver", path.virtual, handler, virtual_path: path.virtual, format: nil, variant: nil, locals: locals)]
|
50
42
|
end
|
51
43
|
end
|
52
|
-
|
53
44
|
end
|
54
|
-
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "concurrent/map"
|
4
|
+
|
5
|
+
module ActionView
|
6
|
+
class UnboundTemplate
|
7
|
+
attr_reader :virtual_path, :details
|
8
|
+
delegate :locale, :format, :variant, :handler, to: :@details
|
9
|
+
|
10
|
+
def initialize(source, identifier, details:, virtual_path:)
|
11
|
+
@source = source
|
12
|
+
@identifier = identifier
|
13
|
+
@details = details
|
14
|
+
@virtual_path = virtual_path
|
15
|
+
|
16
|
+
@templates = Concurrent::Map.new(initial_capacity: 2)
|
17
|
+
@write_lock = Mutex.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def bind_locals(locals)
|
21
|
+
if template = @templates[locals]
|
22
|
+
template
|
23
|
+
else
|
24
|
+
@write_lock.synchronize do
|
25
|
+
normalized_locals = normalize_locals(locals)
|
26
|
+
|
27
|
+
# We need ||=, both to dedup on the normalized locals and to check
|
28
|
+
# while holding the lock.
|
29
|
+
@templates[normalized_locals] ||= build_template(normalized_locals)
|
30
|
+
|
31
|
+
# This may have already been assigned, but we've already de-dup'd so
|
32
|
+
# reassignment is fine.
|
33
|
+
@templates[locals.dup] = @templates[normalized_locals]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def build_template(locals)
|
40
|
+
Template.new(
|
41
|
+
@source,
|
42
|
+
@identifier,
|
43
|
+
details.handler_class,
|
44
|
+
|
45
|
+
format: details.format_or_default,
|
46
|
+
variant: variant&.to_s,
|
47
|
+
virtual_path: @virtual_path,
|
48
|
+
|
49
|
+
locals: locals.map(&:to_s)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def normalize_locals(locals)
|
54
|
+
locals.map(&:to_sym).sort!.freeze
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/action_view/version.rb
CHANGED
@@ -1,78 +1,33 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionView
|
4
4
|
module ViewPaths
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
|
9
|
-
self._view_paths = ActionView::PathSet.new
|
10
|
-
self._view_paths.freeze
|
8
|
+
ViewPaths.set_view_paths(self, ActionView::PathSet.new.freeze)
|
11
9
|
end
|
12
10
|
|
13
|
-
delegate :template_exists?, :view_paths, :formats, :formats=,
|
14
|
-
:locale, :locale=, :
|
11
|
+
delegate :template_exists?, :any_templates?, :view_paths, :formats, :formats=,
|
12
|
+
:locale, :locale=, to: :lookup_context
|
15
13
|
|
16
14
|
module ClassMethods
|
17
|
-
def
|
18
|
-
|
19
|
-
deprecated_prefixes = handle_deprecated_parent_prefixes
|
20
|
-
if deprecated_prefixes
|
21
|
-
deprecated_prefixes
|
22
|
-
else
|
23
|
-
return local_prefixes if superclass.abstract?
|
24
|
-
|
25
|
-
local_prefixes + superclass._prefixes
|
26
|
-
end
|
27
|
-
end
|
15
|
+
def _view_paths
|
16
|
+
ViewPaths.get_view_paths(self)
|
28
17
|
end
|
29
18
|
|
30
|
-
|
31
|
-
|
32
|
-
# Override this method in your controller if you want to change paths prefixes for finding views.
|
33
|
-
# Prefixes defined here will still be added to parents' <tt>._prefixes</tt>.
|
34
|
-
def local_prefixes
|
35
|
-
[controller_path]
|
19
|
+
def _view_paths=(paths)
|
20
|
+
ViewPaths.set_view_paths(self, paths)
|
36
21
|
end
|
37
22
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
42
|
-
Overriding `ActionController::Base::parent_prefixes` is deprecated,
|
43
|
-
override `.local_prefixes` instead.
|
44
|
-
MSG
|
23
|
+
def _prefixes # :nodoc:
|
24
|
+
@_prefixes ||= begin
|
25
|
+
return local_prefixes if superclass.abstract?
|
45
26
|
|
46
|
-
|
27
|
+
local_prefixes + superclass._prefixes
|
28
|
+
end
|
47
29
|
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# The prefixes used in render "foo" shortcuts.
|
51
|
-
def _prefixes # :nodoc:
|
52
|
-
self.class._prefixes
|
53
|
-
end
|
54
|
-
|
55
|
-
# LookupContext is the object responsible to hold all information required to lookup
|
56
|
-
# templates, i.e. view paths and details. Check ActionView::LookupContext for more
|
57
|
-
# information.
|
58
|
-
def lookup_context
|
59
|
-
@_lookup_context ||=
|
60
|
-
ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
|
61
|
-
end
|
62
|
-
|
63
|
-
def details_for_lookup
|
64
|
-
{ }
|
65
|
-
end
|
66
|
-
|
67
|
-
def append_view_path(path)
|
68
|
-
lookup_context.view_paths.push(*path)
|
69
|
-
end
|
70
|
-
|
71
|
-
def prepend_view_path(path)
|
72
|
-
lookup_context.view_paths.unshift(*path)
|
73
|
-
end
|
74
30
|
|
75
|
-
module ClassMethods
|
76
31
|
# Append a path to the list of view paths for this controller.
|
77
32
|
#
|
78
33
|
# ==== Parameters
|
@@ -106,6 +61,66 @@ module ActionView
|
|
106
61
|
def view_paths=(paths)
|
107
62
|
self._view_paths = ActionView::PathSet.new(Array(paths))
|
108
63
|
end
|
64
|
+
|
65
|
+
private
|
66
|
+
# Override this method in your controller if you want to change paths prefixes for finding views.
|
67
|
+
# Prefixes defined here will still be added to parents' <tt>._prefixes</tt>.
|
68
|
+
def local_prefixes
|
69
|
+
[controller_path]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# :stopdoc:
|
74
|
+
@all_view_paths = {}
|
75
|
+
|
76
|
+
def self.get_view_paths(klass)
|
77
|
+
@all_view_paths[klass] || get_view_paths(klass.superclass)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.set_view_paths(klass, paths)
|
81
|
+
@all_view_paths[klass] = paths
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.all_view_paths
|
85
|
+
@all_view_paths.values.uniq
|
86
|
+
end
|
87
|
+
# :startdoc:
|
88
|
+
|
89
|
+
# The prefixes used in render "foo" shortcuts.
|
90
|
+
def _prefixes # :nodoc:
|
91
|
+
self.class._prefixes
|
92
|
+
end
|
93
|
+
|
94
|
+
# <tt>LookupContext</tt> is the object responsible for holding all
|
95
|
+
# information required for looking up templates, i.e. view paths and
|
96
|
+
# details. Check <tt>ActionView::LookupContext</tt> for more information.
|
97
|
+
def lookup_context
|
98
|
+
@_lookup_context ||=
|
99
|
+
ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
|
100
|
+
end
|
101
|
+
|
102
|
+
def details_for_lookup
|
103
|
+
{}
|
104
|
+
end
|
105
|
+
|
106
|
+
# Append a path to the list of view paths for the current <tt>LookupContext</tt>.
|
107
|
+
#
|
108
|
+
# ==== Parameters
|
109
|
+
# * <tt>path</tt> - If a String is provided, it gets converted into
|
110
|
+
# the default view path. You may also provide a custom view path
|
111
|
+
# (see ActionView::PathSet for more information)
|
112
|
+
def append_view_path(path)
|
113
|
+
lookup_context.view_paths.push(*path)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Prepend a path to the list of view paths for the current <tt>LookupContext</tt>.
|
117
|
+
#
|
118
|
+
# ==== Parameters
|
119
|
+
# * <tt>path</tt> - If a String is provided, it gets converted into
|
120
|
+
# the default view path. You may also provide a custom view path
|
121
|
+
# (see ActionView::PathSet for more information)
|
122
|
+
def prepend_view_path(path)
|
123
|
+
lookup_context.view_paths.unshift(*path)
|
109
124
|
end
|
110
125
|
end
|
111
126
|
end
|
data/lib/action_view.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2022 David Heinemeier Hansson
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
7
|
# a copy of this software and associated documentation files (the
|
@@ -21,9 +23,9 @@
|
|
21
23
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
24
|
#++
|
23
25
|
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
26
|
+
require "active_support"
|
27
|
+
require "active_support/rails"
|
28
|
+
require "action_view/version"
|
27
29
|
|
28
30
|
module ActionView
|
29
31
|
extend ActiveSupport::Autoload
|
@@ -33,7 +35,6 @@ module ActionView
|
|
33
35
|
eager_autoload do
|
34
36
|
autoload :Base
|
35
37
|
autoload :Context
|
36
|
-
autoload :CompiledTemplates, "action_view/context"
|
37
38
|
autoload :Digestor
|
38
39
|
autoload :Helpers
|
39
40
|
autoload :LookupContext
|
@@ -43,21 +44,24 @@ module ActionView
|
|
43
44
|
autoload :Rendering
|
44
45
|
autoload :RoutingUrlFor
|
45
46
|
autoload :Template
|
47
|
+
autoload :TemplateDetails
|
48
|
+
autoload :TemplatePath
|
49
|
+
autoload :UnboundTemplate
|
46
50
|
autoload :ViewPaths
|
47
51
|
|
48
52
|
autoload_under "renderer" do
|
49
53
|
autoload :Renderer
|
50
54
|
autoload :AbstractRenderer
|
51
55
|
autoload :PartialRenderer
|
56
|
+
autoload :CollectionRenderer
|
57
|
+
autoload :ObjectRenderer
|
52
58
|
autoload :TemplateRenderer
|
53
59
|
autoload :StreamingTemplateRenderer
|
54
60
|
end
|
55
61
|
|
56
62
|
autoload_at "action_view/template/resolver" do
|
57
63
|
autoload :Resolver
|
58
|
-
autoload :
|
59
|
-
autoload :OptimizedFileSystemResolver
|
60
|
-
autoload :FallbackFileSystemResolver
|
64
|
+
autoload :FileSystemResolver
|
61
65
|
end
|
62
66
|
|
63
67
|
autoload_at "action_view/buffers" do
|
@@ -74,12 +78,13 @@ module ActionView
|
|
74
78
|
autoload :MissingTemplate
|
75
79
|
autoload :ActionViewError
|
76
80
|
autoload :EncodingError
|
77
|
-
autoload :MissingRequestError
|
78
81
|
autoload :TemplateError
|
82
|
+
autoload :SyntaxErrorInTemplate
|
79
83
|
autoload :WrongEncodingError
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
87
|
+
autoload :CacheExpiry
|
83
88
|
autoload :TestCase
|
84
89
|
|
85
90
|
def self.eager_load!
|
@@ -89,8 +94,8 @@ module ActionView
|
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
92
|
-
require
|
97
|
+
require "active_support/core_ext/string/output_safety"
|
93
98
|
|
94
99
|
ActiveSupport.on_load(:i18n) do
|
95
|
-
I18n.load_path <<
|
100
|
+
I18n.load_path << File.expand_path("action_view/locale/en.yml", __dir__)
|
96
101
|
end
|