actionview 4.2.11.3 → 5.2.7.1
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 +115 -245
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -6
- data/lib/action_view/base.rb +38 -28
- data/lib/action_view/buffers.rb +3 -1
- data/lib/action_view/context.rb +3 -3
- data/lib/action_view/dependency_tracker.rb +54 -20
- data/lib/action_view/digestor.rb +94 -83
- data/lib/action_view/flows.rb +11 -11
- data/lib/action_view/gem_version.rb +5 -3
- data/lib/action_view/helpers/active_model_helper.rb +17 -11
- data/lib/action_view/helpers/asset_tag_helper.rb +244 -62
- data/lib/action_view/helpers/asset_url_helper.rb +170 -67
- data/lib/action_view/helpers/atom_feed_helper.rb +19 -17
- data/lib/action_view/helpers/cache_helper.rb +105 -42
- data/lib/action_view/helpers/capture_helper.rb +16 -13
- data/lib/action_view/helpers/controller_helper.rb +15 -4
- data/lib/action_view/helpers/csp_helper.rb +24 -0
- data/lib/action_view/helpers/csrf_helper.rb +7 -5
- data/lib/action_view/helpers/date_helper.rb +170 -112
- data/lib/action_view/helpers/debug_helper.rb +7 -6
- data/lib/action_view/helpers/form_helper.rb +521 -127
- data/lib/action_view/helpers/form_options_helper.rb +109 -63
- data/lib/action_view/helpers/form_tag_helper.rb +110 -67
- data/lib/action_view/helpers/javascript_helper.rb +27 -12
- data/lib/action_view/helpers/number_helper.rb +77 -58
- data/lib/action_view/helpers/output_safety_helper.rb +36 -4
- data/lib/action_view/helpers/record_tag_helper.rb +14 -99
- data/lib/action_view/helpers/rendering_helper.rb +6 -5
- data/lib/action_view/helpers/sanitize_helper.rb +20 -15
- data/lib/action_view/helpers/tag_helper.rb +229 -73
- data/lib/action_view/helpers/tags/base.rb +134 -97
- data/lib/action_view/helpers/tags/check_box.rb +20 -18
- data/lib/action_view/helpers/tags/checkable.rb +4 -2
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -33
- data/lib/action_view/helpers/tags/collection_helpers.rb +70 -36
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -11
- data/lib/action_view/helpers/tags/collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/color_field.rb +3 -1
- data/lib/action_view/helpers/tags/date_field.rb +2 -0
- data/lib/action_view/helpers/tags/date_select.rb +38 -36
- data/lib/action_view/helpers/tags/datetime_field.rb +4 -2
- data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -0
- 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 -1
- data/lib/action_view/helpers/tags/month_field.rb +2 -0
- 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 -5
- 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 -9
- 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 -7
- data/lib/action_view/helpers/tags/time_field.rb +2 -0
- 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 +17 -13
- data/lib/action_view/helpers/tags/url_field.rb +2 -0
- data/lib/action_view/helpers/tags/week_field.rb +2 -0
- data/lib/action_view/helpers/tags.rb +3 -1
- data/lib/action_view/helpers/text_helper.rb +55 -36
- data/lib/action_view/helpers/translation_helper.rb +74 -32
- data/lib/action_view/helpers/url_helper.rb +159 -104
- data/lib/action_view/helpers.rb +5 -1
- data/lib/action_view/layouts.rb +65 -58
- data/lib/action_view/log_subscriber.rb +60 -8
- data/lib/action_view/lookup_context.rb +80 -65
- data/lib/action_view/model_naming.rb +3 -1
- data/lib/action_view/path_set.rb +30 -19
- data/lib/action_view/railtie.rb +39 -6
- data/lib/action_view/record_identifier.rb +53 -25
- data/lib/action_view/renderer/abstract_renderer.rb +21 -15
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +57 -0
- data/lib/action_view/renderer/partial_renderer.rb +218 -214
- data/lib/action_view/renderer/renderer.rb +8 -6
- data/lib/action_view/renderer/streaming_template_renderer.rb +50 -48
- data/lib/action_view/renderer/template_renderer.rb +67 -66
- data/lib/action_view/rendering.rb +19 -14
- data/lib/action_view/routing_url_for.rb +27 -17
- data/lib/action_view/tasks/cache_digests.rake +25 -0
- data/lib/action_view/template/error.rb +16 -16
- data/lib/action_view/template/handlers/builder.rb +10 -11
- data/lib/action_view/template/handlers/erb/erubi.rb +83 -0
- data/lib/action_view/template/handlers/erb.rb +9 -80
- data/lib/action_view/template/handlers/html.rb +11 -0
- data/lib/action_view/template/handlers/raw.rb +3 -3
- data/lib/action_view/template/handlers.rb +11 -7
- data/lib/action_view/template/html.rb +5 -5
- data/lib/action_view/template/resolver.rb +140 -115
- data/lib/action_view/template/text.rb +8 -9
- data/lib/action_view/template/types.rb +18 -18
- data/lib/action_view/template.rb +54 -33
- data/lib/action_view/test_case.rb +50 -29
- data/lib/action_view/testing/resolvers.rb +31 -31
- data/lib/action_view/version.rb +3 -1
- data/lib/action_view/view_paths.rb +28 -34
- data/lib/action_view.rb +8 -7
- data/lib/assets/compiled/rails-ujs.js +720 -0
- metadata +28 -27
- data/lib/action_view/tasks/dependencies.rake +0 -23
data/lib/action_view/template.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/try"
|
4
|
+
require "active_support/core_ext/kernel/singleton_class"
|
5
|
+
require "thread"
|
4
6
|
|
5
7
|
module ActionView
|
6
8
|
# = Action View Template
|
@@ -65,8 +67,7 @@ module ActionView
|
|
65
67
|
# If you want to provide an alternate mechanism for
|
66
68
|
# specifying encodings (like ERB does via <%# encoding: ... %>),
|
67
69
|
# you may indicate that you will handle encodings yourself
|
68
|
-
# by implementing <tt>
|
69
|
-
# on your handler.
|
70
|
+
# by implementing <tt>handles_encoding?</tt> on your handler.
|
70
71
|
#
|
71
72
|
# If you do, Rails will not try to encode the String
|
72
73
|
# into the default_internal, passing you the unaltered
|
@@ -87,6 +88,19 @@ module ActionView
|
|
87
88
|
# expected_encoding
|
88
89
|
# )
|
89
90
|
|
91
|
+
##
|
92
|
+
# :method: local_assigns
|
93
|
+
#
|
94
|
+
# Returns a hash with the defined local variables.
|
95
|
+
#
|
96
|
+
# Given this sub template rendering:
|
97
|
+
#
|
98
|
+
# <%= render "shared/header", { headline: "Welcome", person: person } %>
|
99
|
+
#
|
100
|
+
# You can use +local_assigns+ in the sub templates to access the local variables:
|
101
|
+
#
|
102
|
+
# local_assigns[:headline] # => "Welcome"
|
103
|
+
|
90
104
|
eager_autoload do
|
91
105
|
autoload :Error
|
92
106
|
autoload :Handlers
|
@@ -103,7 +117,7 @@ module ActionView
|
|
103
117
|
|
104
118
|
# This finalizer is needed (and exactly with a proc inside another proc)
|
105
119
|
# otherwise templates leak in development.
|
106
|
-
Finalizer = proc do |method_name, mod|
|
120
|
+
Finalizer = proc do |method_name, mod| # :nodoc:
|
107
121
|
proc do
|
108
122
|
mod.module_eval do
|
109
123
|
remove_possible_method method_name
|
@@ -127,8 +141,8 @@ module ActionView
|
|
127
141
|
@compile_mutex = Mutex.new
|
128
142
|
end
|
129
143
|
|
130
|
-
# Returns
|
131
|
-
# a streaming buffer *may* be passed when it
|
144
|
+
# Returns whether the underlying handler supports streaming. If so,
|
145
|
+
# a streaming buffer *may* be passed when it starts rendering.
|
132
146
|
def supports_streaming?
|
133
147
|
handler.respond_to?(:supports_streaming?) && handler.supports_streaming?
|
134
148
|
end
|
@@ -139,8 +153,8 @@ module ActionView
|
|
139
153
|
# This method is instrumented as "!render_template.action_view". Notice that
|
140
154
|
# we use a bang in this instrumentation because you don't want to
|
141
155
|
# consume this in production. This is only slow if it's being listened to.
|
142
|
-
def render(view, locals, buffer=nil, &block)
|
143
|
-
|
156
|
+
def render(view, locals, buffer = nil, &block)
|
157
|
+
instrument_render_template do
|
144
158
|
compile!(view)
|
145
159
|
view.send(method_name, locals, buffer, &block)
|
146
160
|
end
|
@@ -167,12 +181,12 @@ module ActionView
|
|
167
181
|
name = pieces.pop
|
168
182
|
partial = !!name.sub!(/^_/, "")
|
169
183
|
lookup.disable_cache do
|
170
|
-
lookup.find_template(name, [ pieces.join(
|
184
|
+
lookup.find_template(name, [ pieces.join("/") ], partial, @locals)
|
171
185
|
end
|
172
186
|
end
|
173
187
|
|
174
188
|
def inspect
|
175
|
-
@inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/",
|
189
|
+
@inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", "".freeze) : identifier
|
176
190
|
end
|
177
191
|
|
178
192
|
# This method is responsible for properly setting the encoding of the
|
@@ -191,7 +205,7 @@ module ActionView
|
|
191
205
|
# Look for # encoding: *. If we find one, we'll encode the
|
192
206
|
# String in that encoding, otherwise, we'll use the
|
193
207
|
# default external encoding.
|
194
|
-
if source.sub!(/\A#{ENCODING_FLAG}/,
|
208
|
+
if source.sub!(/\A#{ENCODING_FLAG}/, "")
|
195
209
|
encoding = magic_encoding = $1
|
196
210
|
else
|
197
211
|
encoding = Encoding.default_external
|
@@ -219,11 +233,11 @@ module ActionView
|
|
219
233
|
end
|
220
234
|
end
|
221
235
|
|
222
|
-
|
236
|
+
private
|
223
237
|
|
224
238
|
# Compile a template. This method ensures a template is compiled
|
225
239
|
# just once and removes the source after it is compiled.
|
226
|
-
def compile!(view)
|
240
|
+
def compile!(view)
|
227
241
|
return if @compiled
|
228
242
|
|
229
243
|
# Templates can be used concurrently in threaded environments
|
@@ -264,14 +278,13 @@ module ActionView
|
|
264
278
|
# encode the source into <tt>Encoding.default_internal</tt>.
|
265
279
|
# In general, this means that templates will be UTF-8 inside of Rails,
|
266
280
|
# regardless of the original source encoding.
|
267
|
-
def compile(mod)
|
281
|
+
def compile(mod)
|
268
282
|
encode!
|
269
|
-
method_name = self.method_name
|
270
283
|
code = @handler.call(self)
|
271
284
|
|
272
285
|
# Make sure that the resulting String to be eval'd is in the
|
273
286
|
# encoding of the code
|
274
|
-
source = <<-end_src
|
287
|
+
source = <<-end_src.dup
|
275
288
|
def #{method_name}(local_assigns, output_buffer)
|
276
289
|
_old_virtual_path, @virtual_path = @virtual_path, #{@virtual_path.inspect};_old_output_buffer = @output_buffer;#{locals_code};#{code}
|
277
290
|
ensure
|
@@ -297,7 +310,7 @@ module ActionView
|
|
297
310
|
ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
|
298
311
|
end
|
299
312
|
|
300
|
-
def handle_render_error(view, e)
|
313
|
+
def handle_render_error(view, e)
|
301
314
|
if e.is_a?(Template::Error)
|
302
315
|
e.sub_template_of(self)
|
303
316
|
raise e
|
@@ -307,34 +320,42 @@ module ActionView
|
|
307
320
|
template = refresh(view)
|
308
321
|
template.encode!
|
309
322
|
end
|
310
|
-
raise Template::Error.new(template
|
323
|
+
raise Template::Error.new(template)
|
311
324
|
end
|
312
325
|
end
|
313
326
|
|
314
|
-
def locals_code
|
327
|
+
def locals_code
|
315
328
|
# Only locals with valid variable names get set directly. Others will
|
316
329
|
# still be available in local_assigns.
|
317
|
-
locals = @locals
|
318
|
-
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
319
|
-
|
320
|
-
|
330
|
+
locals = @locals - Module::RUBY_RESERVED_KEYWORDS
|
331
|
+
locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
332
|
+
|
333
|
+
# Assign for the same variable is to suppress unused variable warning
|
334
|
+
locals.each_with_object("".dup) { |key, code| code << "#{key} = local_assigns[:#{key}]; #{key} = #{key};" }
|
321
335
|
end
|
322
336
|
|
323
|
-
def method_name
|
337
|
+
def method_name
|
324
338
|
@method_name ||= begin
|
325
|
-
m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}"
|
326
|
-
m.tr!(
|
339
|
+
m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}".dup
|
340
|
+
m.tr!("-".freeze, "_".freeze)
|
327
341
|
m
|
328
342
|
end
|
329
343
|
end
|
330
344
|
|
331
|
-
def identifier_method_name
|
332
|
-
inspect.tr(
|
345
|
+
def identifier_method_name
|
346
|
+
inspect.tr("^a-z_".freeze, "_".freeze)
|
347
|
+
end
|
348
|
+
|
349
|
+
def instrument(action, &block) # :doc:
|
350
|
+
ActiveSupport::Notifications.instrument("#{action}.action_view", instrument_payload, &block)
|
351
|
+
end
|
352
|
+
|
353
|
+
def instrument_render_template(&block)
|
354
|
+
ActiveSupport::Notifications.instrument("!render_template.action_view".freeze, instrument_payload, &block)
|
333
355
|
end
|
334
356
|
|
335
|
-
def
|
336
|
-
|
337
|
-
ActiveSupport::Notifications.instrument("#{action}.action_view", payload, &block)
|
357
|
+
def instrument_payload
|
358
|
+
{ virtual_path: @virtual_path, identifier: @identifier }
|
338
359
|
end
|
339
360
|
end
|
340
361
|
end
|
@@ -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
|
@@ -18,17 +20,17 @@ module ActionView
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def controller_path=(path)
|
21
|
-
self.class.controller_path=(path)
|
23
|
+
self.class.controller_path = (path)
|
22
24
|
end
|
23
25
|
|
24
26
|
def initialize
|
25
27
|
super
|
26
28
|
self.class.controller_path = ""
|
27
|
-
@request = ActionController::TestRequest.
|
28
|
-
@response =
|
29
|
+
@request = ActionController::TestRequest.create(self.class)
|
30
|
+
@response = ActionDispatch::TestResponse.new
|
29
31
|
|
30
|
-
@request.env.delete(
|
31
|
-
@params =
|
32
|
+
@request.env.delete("PATH_INFO")
|
33
|
+
@params = ActionController::Parameters.new
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -49,7 +51,7 @@ module ActionView
|
|
49
51
|
|
50
52
|
include ActiveSupport::Testing::ConstantLookup
|
51
53
|
|
52
|
-
delegate :lookup_context, :
|
54
|
+
delegate :lookup_context, to: :controller
|
53
55
|
attr_accessor :controller, :output_buffer, :rendered
|
54
56
|
|
55
57
|
module ClassMethods
|
@@ -71,7 +73,7 @@ module ActionView
|
|
71
73
|
def helper_method(*methods)
|
72
74
|
# Almost a duplicate from ActionController::Helpers
|
73
75
|
methods.flatten.each do |method|
|
74
|
-
_helpers.module_eval <<-end_eval
|
76
|
+
_helpers.module_eval <<-end_eval, __FILE__, __LINE__ + 1
|
75
77
|
def #{method}(*args, &block) # def current_user(*args, &block)
|
76
78
|
_test_case.send(%(#{method}), *args, &block) # _test_case.send(%(current_user), *args, &block)
|
77
79
|
end # end
|
@@ -96,16 +98,16 @@ module ActionView
|
|
96
98
|
helper(helper_class) if helper_class
|
97
99
|
include _helpers
|
98
100
|
end
|
99
|
-
|
100
101
|
end
|
101
102
|
|
102
103
|
def setup_with_controller
|
103
104
|
@controller = ActionView::TestCase::TestController.new
|
104
105
|
@request = @controller.request
|
106
|
+
@view_flow = ActionView::OutputFlow.new
|
105
107
|
# empty string ensures buffer has UTF-8 encoding as
|
106
108
|
# new without arguments returns ASCII-8BIT encoded buffer like String#new
|
107
|
-
@output_buffer = ActiveSupport::SafeBuffer.new
|
108
|
-
@rendered =
|
109
|
+
@output_buffer = ActiveSupport::SafeBuffer.new ""
|
110
|
+
@rendered = "".dup
|
109
111
|
|
110
112
|
make_test_case_available_to_view!
|
111
113
|
say_no_to_protect_against_forgery!
|
@@ -125,6 +127,10 @@ module ActionView
|
|
125
127
|
@_rendered_views ||= RenderedViewsCollection.new
|
126
128
|
end
|
127
129
|
|
130
|
+
def _routes
|
131
|
+
@controller._routes if @controller.respond_to?(:_routes)
|
132
|
+
end
|
133
|
+
|
128
134
|
# Need to experiment if this priority is the best one: rendered => output_buffer
|
129
135
|
class RenderedViewsCollection
|
130
136
|
def initialize
|
@@ -146,13 +152,14 @@ module ActionView
|
|
146
152
|
|
147
153
|
def view_rendered?(view, expected_locals)
|
148
154
|
locals_for(view).any? do |actual_locals|
|
149
|
-
expected_locals.all? {|key, value| value == actual_locals[key] }
|
155
|
+
expected_locals.all? { |key, value| value == actual_locals[key] }
|
150
156
|
end
|
151
157
|
end
|
152
158
|
end
|
153
159
|
|
154
160
|
included do
|
155
161
|
setup :setup_with_controller
|
162
|
+
ActiveSupport.run_load_hooks(:action_view_test_case, self)
|
156
163
|
end
|
157
164
|
|
158
165
|
private
|
@@ -164,7 +171,7 @@ module ActionView
|
|
164
171
|
|
165
172
|
def say_no_to_protect_against_forgery!
|
166
173
|
_helpers.module_eval do
|
167
|
-
|
174
|
+
silence_redefinition_of_method :protect_against_forgery?
|
168
175
|
def protect_against_forgery?
|
169
176
|
false
|
170
177
|
end
|
@@ -204,10 +211,10 @@ module ActionView
|
|
204
211
|
def view
|
205
212
|
@view ||= begin
|
206
213
|
view = @controller.view_context
|
207
|
-
view.singleton_class.
|
214
|
+
view.singleton_class.include(_helpers)
|
208
215
|
view.extend(Locals)
|
209
|
-
view.rendered_views =
|
210
|
-
view.output_buffer =
|
216
|
+
view.rendered_views = rendered_views
|
217
|
+
view.output_buffer = output_buffer
|
211
218
|
view
|
212
219
|
end
|
213
220
|
end
|
@@ -240,9 +247,9 @@ module ActionView
|
|
240
247
|
:@test_passed,
|
241
248
|
:@view,
|
242
249
|
:@view_context_class,
|
250
|
+
:@view_flow,
|
243
251
|
:@_subscribers,
|
244
|
-
:@html_document
|
245
|
-
:@html_scanner_document
|
252
|
+
:@html_document
|
246
253
|
]
|
247
254
|
|
248
255
|
def _user_defined_ivars
|
@@ -259,19 +266,33 @@ module ActionView
|
|
259
266
|
end]
|
260
267
|
end
|
261
268
|
|
262
|
-
def _routes
|
263
|
-
@controller._routes if @controller.respond_to?(:_routes)
|
264
|
-
end
|
265
|
-
|
266
269
|
def method_missing(selector, *args)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
+
begin
|
271
|
+
routes = @controller.respond_to?(:_routes) && @controller._routes
|
272
|
+
rescue
|
273
|
+
# Don't call routes, if there is an error on _routes call
|
274
|
+
end
|
275
|
+
|
276
|
+
if routes &&
|
277
|
+
(routes.named_routes.route_defined?(selector) ||
|
278
|
+
routes.mounted_helpers.method_defined?(selector))
|
270
279
|
@controller.__send__(selector, *args)
|
271
280
|
else
|
272
281
|
super
|
273
282
|
end
|
274
283
|
end
|
284
|
+
|
285
|
+
def respond_to_missing?(name, include_private = false)
|
286
|
+
begin
|
287
|
+
routes = @controller.respond_to?(:_routes) && @controller._routes
|
288
|
+
rescue
|
289
|
+
# Don't call routes, if there is an error on _routes call
|
290
|
+
end
|
291
|
+
|
292
|
+
routes &&
|
293
|
+
(routes.named_routes.route_defined?(name) ||
|
294
|
+
routes.mounted_helpers.method_defined?(name))
|
295
|
+
end
|
275
296
|
end
|
276
297
|
|
277
298
|
include Behavior
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/template/resolver"
|
2
4
|
|
3
5
|
module ActionView #:nodoc:
|
4
6
|
# Use FixtureResolver in your tests to simulate the presence of files on the
|
@@ -8,47 +10,45 @@ module ActionView #:nodoc:
|
|
8
10
|
class FixtureResolver < PathResolver
|
9
11
|
attr_reader :hash
|
10
12
|
|
11
|
-
def initialize(hash = {}, pattern=nil)
|
13
|
+
def initialize(hash = {}, pattern = nil)
|
12
14
|
super(pattern)
|
13
15
|
@hash = hash
|
14
16
|
end
|
15
17
|
|
16
18
|
def to_s
|
17
|
-
@hash.keys.join(
|
19
|
+
@hash.keys.join(", ")
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
private
|
23
|
+
|
24
|
+
def query(path, exts, _, _)
|
25
|
+
query = "".dup
|
26
|
+
EXTENSIONS.each_key do |ext|
|
27
|
+
query << "(" << exts[ext].map { |e| e && Regexp.escape(".#{e}") }.join("|") << "|)"
|
28
|
+
end
|
29
|
+
query = /^(#{Regexp.escape(path)})#{query}$/
|
30
|
+
|
31
|
+
templates = []
|
32
|
+
@hash.each do |_path, array|
|
33
|
+
source, updated_at = array
|
34
|
+
next unless query.match?(_path)
|
35
|
+
handler, format, variant = extract_handler_and_format_and_variant(_path)
|
36
|
+
templates << Template.new(source, _path, handler,
|
37
|
+
virtual_path: path.virtual,
|
38
|
+
format: format,
|
39
|
+
variant: variant,
|
40
|
+
updated_at: updated_at
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
templates.sort_by { |t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
|
26
45
|
end
|
27
|
-
query = /^(#{Regexp.escape(path)})#{query}$/
|
28
|
-
|
29
|
-
templates = []
|
30
|
-
@hash.each do |_path, array|
|
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
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
|
43
|
-
end
|
44
46
|
end
|
45
47
|
|
46
48
|
class NullResolver < PathResolver
|
47
|
-
def query(path, exts,
|
48
|
-
handler, format, variant = extract_handler_and_format_and_variant(path
|
49
|
-
[ActionView::Template.new("Template generated by Null Resolver", path, handler, :
|
49
|
+
def query(path, exts, _, _)
|
50
|
+
handler, format, variant = extract_handler_and_format_and_variant(path)
|
51
|
+
[ActionView::Template.new("Template generated by Null Resolver", path.virtual, handler, virtual_path: path.virtual, format: format, variant: variant)]
|
50
52
|
end
|
51
53
|
end
|
52
|
-
|
53
54
|
end
|
54
|
-
|
data/lib/action_view/version.rb
CHANGED
@@ -1,50 +1,32 @@
|
|
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
|
-
class_attribute :_view_paths
|
9
|
-
self._view_paths = ActionView::PathSet.new
|
10
|
-
self._view_paths.freeze
|
8
|
+
class_attribute :_view_paths, default: 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
15
|
def _prefixes # :nodoc:
|
18
16
|
@_prefixes ||= begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
return local_prefixes if superclass.abstract?
|
24
|
-
|
25
|
-
local_prefixes + superclass._prefixes
|
26
|
-
end
|
17
|
+
return local_prefixes if superclass.abstract?
|
18
|
+
|
19
|
+
local_prefixes + superclass._prefixes
|
27
20
|
end
|
28
21
|
end
|
29
22
|
|
30
23
|
private
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def handle_deprecated_parent_prefixes # TODO: remove in 4.3/5.0.
|
39
|
-
return unless respond_to?(:parent_prefixes)
|
40
|
-
|
41
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
42
|
-
Overriding `ActionController::Base::parent_prefixes` is deprecated,
|
43
|
-
override `.local_prefixes` instead.
|
44
|
-
MSG
|
45
|
-
|
46
|
-
local_prefixes + parent_prefixes
|
47
|
-
end
|
25
|
+
# Override this method in your controller if you want to change paths prefixes for finding views.
|
26
|
+
# Prefixes defined here will still be added to parents' <tt>._prefixes</tt>.
|
27
|
+
def local_prefixes
|
28
|
+
[controller_path]
|
29
|
+
end
|
48
30
|
end
|
49
31
|
|
50
32
|
# The prefixes used in render "foo" shortcuts.
|
@@ -52,22 +34,34 @@ module ActionView
|
|
52
34
|
self.class._prefixes
|
53
35
|
end
|
54
36
|
|
55
|
-
# LookupContext is the object responsible
|
56
|
-
# templates, i.e. view paths and
|
57
|
-
# information.
|
37
|
+
# <tt>LookupContext</tt> is the object responsible for holding all
|
38
|
+
# information required for looking up templates, i.e. view paths and
|
39
|
+
# details. Check <tt>ActionView::LookupContext</tt> for more information.
|
58
40
|
def lookup_context
|
59
41
|
@_lookup_context ||=
|
60
42
|
ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
|
61
43
|
end
|
62
44
|
|
63
45
|
def details_for_lookup
|
64
|
-
{
|
46
|
+
{}
|
65
47
|
end
|
66
48
|
|
49
|
+
# Append a path to the list of view paths for the current <tt>LookupContext</tt>.
|
50
|
+
#
|
51
|
+
# ==== Parameters
|
52
|
+
# * <tt>path</tt> - If a String is provided, it gets converted into
|
53
|
+
# the default view path. You may also provide a custom view path
|
54
|
+
# (see ActionView::PathSet for more information)
|
67
55
|
def append_view_path(path)
|
68
56
|
lookup_context.view_paths.push(*path)
|
69
57
|
end
|
70
58
|
|
59
|
+
# Prepend a path to the list of view paths for the current <tt>LookupContext</tt>.
|
60
|
+
#
|
61
|
+
# ==== Parameters
|
62
|
+
# * <tt>path</tt> - If a String is provided, it gets converted into
|
63
|
+
# the default view path. You may also provide a custom view path
|
64
|
+
# (see ActionView::PathSet for more information)
|
71
65
|
def prepend_view_path(path)
|
72
66
|
lookup_context.view_paths.unshift(*path)
|
73
67
|
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-2018 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
|
@@ -74,7 +76,6 @@ module ActionView
|
|
74
76
|
autoload :MissingTemplate
|
75
77
|
autoload :ActionViewError
|
76
78
|
autoload :EncodingError
|
77
|
-
autoload :MissingRequestError
|
78
79
|
autoload :TemplateError
|
79
80
|
autoload :WrongEncodingError
|
80
81
|
end
|
@@ -89,8 +90,8 @@ module ActionView
|
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
|
-
require
|
93
|
+
require "active_support/core_ext/string/output_safety"
|
93
94
|
|
94
95
|
ActiveSupport.on_load(:i18n) do
|
95
|
-
I18n.load_path <<
|
96
|
+
I18n.load_path << File.expand_path("action_view/locale/en.yml", __dir__)
|
96
97
|
end
|