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
data/lib/action_view/helpers.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require "active_support/benchmarkable"
|
4
|
+
require "action_view/helpers/capture_helper"
|
5
|
+
require "action_view/helpers/output_safety_helper"
|
6
|
+
require "action_view/helpers/tag_helper"
|
7
|
+
require "action_view/helpers/url_helper"
|
8
|
+
require "action_view/helpers/sanitize_helper"
|
9
|
+
require "action_view/helpers/text_helper"
|
10
|
+
require "action_view/helpers/active_model_helper"
|
11
|
+
require "action_view/helpers/asset_tag_helper"
|
12
|
+
require "action_view/helpers/asset_url_helper"
|
13
|
+
require "action_view/helpers/atom_feed_helper"
|
14
|
+
require "action_view/helpers/cache_helper"
|
15
|
+
require "action_view/helpers/controller_helper"
|
16
|
+
require "action_view/helpers/csp_helper"
|
17
|
+
require "action_view/helpers/csrf_helper"
|
18
|
+
require "action_view/helpers/date_helper"
|
19
|
+
require "action_view/helpers/debug_helper"
|
20
|
+
require "action_view/helpers/form_tag_helper"
|
21
|
+
require "action_view/helpers/form_helper"
|
22
|
+
require "action_view/helpers/form_options_helper"
|
23
|
+
require "action_view/helpers/javascript_helper"
|
24
|
+
require "action_view/helpers/number_helper"
|
25
|
+
require "action_view/helpers/rendering_helper"
|
26
|
+
require "action_view/helpers/translation_helper"
|
27
|
+
|
28
|
+
module ActionView # :nodoc:
|
29
|
+
module Helpers # :nodoc:
|
5
30
|
extend ActiveSupport::Autoload
|
6
31
|
|
7
|
-
autoload :ActiveModelHelper
|
8
|
-
autoload :AssetTagHelper
|
9
|
-
autoload :AssetUrlHelper
|
10
|
-
autoload :AtomFeedHelper
|
11
|
-
autoload :CacheHelper
|
12
|
-
autoload :CaptureHelper
|
13
|
-
autoload :ControllerHelper
|
14
|
-
autoload :CsrfHelper
|
15
|
-
autoload :DateHelper
|
16
|
-
autoload :DebugHelper
|
17
|
-
autoload :FormHelper
|
18
|
-
autoload :FormOptionsHelper
|
19
|
-
autoload :FormTagHelper
|
20
|
-
autoload :JavaScriptHelper, "action_view/helpers/javascript_helper"
|
21
|
-
autoload :NumberHelper
|
22
|
-
autoload :OutputSafetyHelper
|
23
|
-
autoload :RecordTagHelper
|
24
|
-
autoload :RenderingHelper
|
25
|
-
autoload :SanitizeHelper
|
26
|
-
autoload :TagHelper
|
27
|
-
autoload :TextHelper
|
28
|
-
autoload :TranslationHelper
|
29
|
-
autoload :UrlHelper
|
30
32
|
autoload :Tags
|
31
33
|
|
32
34
|
def self.eager_load!
|
@@ -44,6 +46,7 @@ module ActionView #:nodoc:
|
|
44
46
|
include CacheHelper
|
45
47
|
include CaptureHelper
|
46
48
|
include ControllerHelper
|
49
|
+
include CspHelper
|
47
50
|
include CsrfHelper
|
48
51
|
include DateHelper
|
49
52
|
include DebugHelper
|
@@ -53,7 +56,6 @@ module ActionView #:nodoc:
|
|
53
56
|
include JavaScriptHelper
|
54
57
|
include NumberHelper
|
55
58
|
include OutputSafetyHelper
|
56
|
-
include RecordTagHelper
|
57
59
|
include RenderingHelper
|
58
60
|
include SanitizeHelper
|
59
61
|
include TagHelper
|
data/lib/action_view/layouts.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "action_view/rendering"
|
2
|
-
require "active_support/core_ext/module/
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
3
5
|
|
4
6
|
module ActionView
|
5
7
|
# Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
|
@@ -91,16 +93,16 @@ module ActionView
|
|
91
93
|
# layout false
|
92
94
|
#
|
93
95
|
# In these examples, we have three implicit lookup scenarios:
|
94
|
-
# * The BankController uses the "bank" layout.
|
95
|
-
# * The ExchangeController uses the "exchange" layout.
|
96
|
-
# * The CurrencyController inherits the layout from BankController.
|
96
|
+
# * The +BankController+ uses the "bank" layout.
|
97
|
+
# * The +ExchangeController+ uses the "exchange" layout.
|
98
|
+
# * The +CurrencyController+ inherits the layout from BankController.
|
97
99
|
#
|
98
100
|
# However, when a layout is explicitly set, the explicitly set layout wins:
|
99
|
-
# * The InformationController uses the "information" layout, explicitly set.
|
100
|
-
# * The TellerController also uses the "information" layout, because the parent explicitly set it.
|
101
|
-
# * The EmployeeController uses the "employee" layout, because it set the layout to nil
|
102
|
-
# * The VaultController chooses a layout dynamically by calling the <tt>access_level_layout</tt> method.
|
103
|
-
# * The TillController does not use a layout at all.
|
101
|
+
# * The +InformationController+ uses the "information" layout, explicitly set.
|
102
|
+
# * The +TellerController+ also uses the "information" layout, because the parent explicitly set it.
|
103
|
+
# * The +EmployeeController+ uses the "employee" layout, because it set the layout to +nil+, resetting the parent configuration.
|
104
|
+
# * The +VaultController+ chooses a layout dynamically by calling the <tt>access_level_layout</tt> method.
|
105
|
+
# * The +TillController+ does not use a layout at all.
|
104
106
|
#
|
105
107
|
# == Types of layouts
|
106
108
|
#
|
@@ -148,8 +150,8 @@ module ActionView
|
|
148
150
|
# The template will be looked always in <tt>app/views/layouts/</tt> folder. But you can point
|
149
151
|
# <tt>layouts</tt> folder direct also. <tt>layout "layouts/demo"</tt> is the same as <tt>layout "demo"</tt>.
|
150
152
|
#
|
151
|
-
# Setting the layout to nil forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists.
|
152
|
-
# Setting it to nil is useful to re-enable template lookup overriding a previous configuration set in the parent:
|
153
|
+
# Setting the layout to +nil+ forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists.
|
154
|
+
# Setting it to +nil+ is useful to re-enable template lookup overriding a previous configuration set in the parent:
|
153
155
|
#
|
154
156
|
# class ApplicationController < ActionController::Base
|
155
157
|
# layout "application"
|
@@ -204,9 +206,9 @@ module ActionView
|
|
204
206
|
include ActionView::Rendering
|
205
207
|
|
206
208
|
included do
|
207
|
-
class_attribute :_layout, :
|
208
|
-
|
209
|
-
|
209
|
+
class_attribute :_layout, instance_accessor: false
|
210
|
+
class_attribute :_layout_conditions, instance_accessor: false, default: {}
|
211
|
+
|
210
212
|
_write_layout_method
|
211
213
|
end
|
212
214
|
|
@@ -222,37 +224,39 @@ module ActionView
|
|
222
224
|
# that if no layout conditions are used, this method is not used
|
223
225
|
module LayoutConditions # :nodoc:
|
224
226
|
private
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
227
|
+
# Determines whether the current action has a layout definition by
|
228
|
+
# checking the action name against the :only and :except conditions
|
229
|
+
# set by the <tt>layout</tt> method.
|
230
|
+
#
|
231
|
+
# ==== Returns
|
232
|
+
# * <tt>Boolean</tt> - True if the action has a layout definition, false otherwise.
|
233
|
+
def _conditional_layout?
|
234
|
+
return unless super
|
235
|
+
|
236
|
+
conditions = _layout_conditions
|
237
|
+
|
238
|
+
if only = conditions[:only]
|
239
|
+
only.include?(action_name)
|
240
|
+
elsif except = conditions[:except]
|
241
|
+
!except.include?(action_name)
|
242
|
+
else
|
243
|
+
true
|
244
|
+
end
|
243
245
|
end
|
244
|
-
end
|
245
246
|
end
|
246
247
|
|
247
248
|
# Specify the layout to use for this class.
|
248
249
|
#
|
249
250
|
# If the specified layout is a:
|
250
251
|
# String:: the String is the template name
|
251
|
-
# Symbol:: call the method specified by the symbol
|
252
|
+
# Symbol:: call the method specified by the symbol
|
253
|
+
# Proc:: call the passed Proc
|
252
254
|
# false:: There is no layout
|
253
255
|
# true:: raise an ArgumentError
|
254
256
|
# nil:: Force default layout behavior with inheritance
|
255
257
|
#
|
258
|
+
# Return value of +Proc+ and +Symbol+ arguments should be +String+, +false+, +true+ or +nil+
|
259
|
+
# with the same meaning as described above.
|
256
260
|
# ==== Parameters
|
257
261
|
# * <tt>layout</tt> - The layout to use.
|
258
262
|
#
|
@@ -262,7 +266,7 @@ module ActionView
|
|
262
266
|
def layout(layout, conditions = {})
|
263
267
|
include LayoutConditions unless conditions.empty?
|
264
268
|
|
265
|
-
conditions.each {|k, v| conditions[k] = Array(v).map
|
269
|
+
conditions.each { |k, v| conditions[k] = Array(v).map(&:to_s) }
|
266
270
|
self._layout_conditions = conditions
|
267
271
|
|
268
272
|
self._layout = layout
|
@@ -274,10 +278,10 @@ module ActionView
|
|
274
278
|
# If a layout is not explicitly mentioned then look for a layout with the controller's name.
|
275
279
|
# if nothing is found then try same procedure to find super class's layout.
|
276
280
|
def _write_layout_method # :nodoc:
|
277
|
-
|
281
|
+
silence_redefinition_of_method(:_layout)
|
278
282
|
|
279
|
-
prefixes
|
280
|
-
default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}).first || super"
|
283
|
+
prefixes = /\blayouts/.match?(_implied_layout_name) ? [] : ["layouts"]
|
284
|
+
default_behavior = "lookup_context.find_all('#{_implied_layout_name}', #{prefixes.inspect}, false, [], { formats: formats }).first || super"
|
281
285
|
name_clause = if name
|
282
286
|
default_behavior
|
283
287
|
else
|
@@ -286,7 +290,8 @@ module ActionView
|
|
286
290
|
RUBY
|
287
291
|
end
|
288
292
|
|
289
|
-
layout_definition =
|
293
|
+
layout_definition = \
|
294
|
+
case _layout
|
290
295
|
when String
|
291
296
|
_layout.inspect
|
292
297
|
when Symbol
|
@@ -301,7 +306,7 @@ module ActionView
|
|
301
306
|
RUBY
|
302
307
|
when Proc
|
303
308
|
define_method :_layout_from_proc, &_layout
|
304
|
-
|
309
|
+
private :_layout_from_proc
|
305
310
|
<<-RUBY
|
306
311
|
result = _layout_from_proc(#{_layout.arity == 0 ? '' : 'self'})
|
307
312
|
return #{default_behavior} if result.nil?
|
@@ -313,10 +318,11 @@ module ActionView
|
|
313
318
|
raise ArgumentError, "Layouts must be specified as a String, Symbol, Proc, false, or nil"
|
314
319
|
when nil
|
315
320
|
name_clause
|
316
|
-
|
321
|
+
end
|
317
322
|
|
318
|
-
|
319
|
-
|
323
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
324
|
+
# frozen_string_literal: true
|
325
|
+
def _layout(lookup_context, formats)
|
320
326
|
if _conditional_layout?
|
321
327
|
#{layout_definition}
|
322
328
|
else
|
@@ -328,15 +334,14 @@ module ActionView
|
|
328
334
|
end
|
329
335
|
|
330
336
|
private
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
end
|
337
|
+
# If no layout is supplied, look for a template named the return
|
338
|
+
# value of this method.
|
339
|
+
#
|
340
|
+
# ==== Returns
|
341
|
+
# * <tt>String</tt> - A template name
|
342
|
+
def _implied_layout_name
|
343
|
+
controller_path
|
344
|
+
end
|
340
345
|
end
|
341
346
|
|
342
347
|
def _normalize_options(options) # :nodoc:
|
@@ -366,13 +371,12 @@ module ActionView
|
|
366
371
|
end
|
367
372
|
|
368
373
|
private
|
369
|
-
|
370
374
|
def _conditional_layout?
|
371
375
|
true
|
372
376
|
end
|
373
377
|
|
374
378
|
# This will be overwritten by _write_layout_method
|
375
|
-
def _layout; end
|
379
|
+
def _layout(*); end
|
376
380
|
|
377
381
|
# Determine the layout for a given name, taking into account the name type.
|
378
382
|
#
|
@@ -382,8 +386,8 @@ module ActionView
|
|
382
386
|
case name
|
383
387
|
when String then _normalize_layout(name)
|
384
388
|
when Proc then name
|
385
|
-
when true then Proc.new { _default_layout(true) }
|
386
|
-
when :default then Proc.new { _default_layout(false) }
|
389
|
+
when true then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, true) }
|
390
|
+
when :default then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, false) }
|
387
391
|
when false, nil then nil
|
388
392
|
else
|
389
393
|
raise ArgumentError,
|
@@ -392,21 +396,22 @@ module ActionView
|
|
392
396
|
end
|
393
397
|
|
394
398
|
def _normalize_layout(value)
|
395
|
-
value.is_a?(String) && value
|
399
|
+
value.is_a?(String) && !value.match?(/\blayouts/) ? "layouts/#{value}" : value
|
396
400
|
end
|
397
401
|
|
398
402
|
# Returns the default layout for this controller.
|
399
403
|
# Optionally raises an exception if the layout could not be found.
|
400
404
|
#
|
401
405
|
# ==== Parameters
|
402
|
-
# * <tt>
|
403
|
-
#
|
406
|
+
# * <tt>formats</tt> - The formats accepted to this layout
|
407
|
+
# * <tt>require_layout</tt> - If set to +true+ and layout is not found,
|
408
|
+
# an +ArgumentError+ exception is raised (defaults to +false+)
|
404
409
|
#
|
405
410
|
# ==== Returns
|
406
|
-
# * <tt>template</tt> - The template object for the default layout (or nil)
|
407
|
-
def _default_layout(require_layout = false)
|
411
|
+
# * <tt>template</tt> - The template object for the default layout (or +nil+)
|
412
|
+
def _default_layout(lookup_context, formats, require_layout = false)
|
408
413
|
begin
|
409
|
-
value = _layout if action_has_layout?
|
414
|
+
value = _layout(lookup_context, formats) if action_has_layout?
|
410
415
|
rescue NameError => e
|
411
416
|
raise e, "Could not render layout: #{e.message}"
|
412
417
|
end
|
@@ -420,7 +425,7 @@ module ActionView
|
|
420
425
|
end
|
421
426
|
|
422
427
|
def _include_layout?(options)
|
423
|
-
(options.keys & [:body, :
|
428
|
+
(options.keys & [:body, :plain, :html, :inline, :partial]).empty? || options.key?(:layout)
|
424
429
|
end
|
425
430
|
end
|
426
431
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/log_subscriber"
|
2
4
|
|
3
5
|
module ActionView
|
4
6
|
# = Action View Log Subscriber
|
@@ -14,30 +16,95 @@ module ActionView
|
|
14
16
|
|
15
17
|
def render_template(event)
|
16
18
|
info do
|
17
|
-
message = " Rendered #{from_rails_root(event.payload[:identifier])}"
|
19
|
+
message = +" Rendered #{from_rails_root(event.payload[:identifier])}"
|
20
|
+
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
21
|
+
message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_partial(event)
|
26
|
+
debug do
|
27
|
+
message = +" Rendered #{from_rails_root(event.payload[:identifier])}"
|
18
28
|
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
19
|
-
message << " (#{event.duration.round(1)}ms)"
|
29
|
+
message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
|
30
|
+
message << " #{cache_message(event.payload)}" unless event.payload[:cache_hit].nil?
|
31
|
+
message
|
20
32
|
end
|
21
33
|
end
|
22
|
-
|
23
|
-
|
34
|
+
|
35
|
+
def render_layout(event)
|
36
|
+
info do
|
37
|
+
message = +" Rendered layout #{from_rails_root(event.payload[:identifier])}"
|
38
|
+
message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_collection(event)
|
43
|
+
identifier = event.payload[:identifier] || "templates"
|
44
|
+
|
45
|
+
debug do
|
46
|
+
message = +" Rendered collection of #{from_rails_root(identifier)}"
|
47
|
+
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
48
|
+
message << " #{render_count(event.payload)} (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
|
49
|
+
message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def start(name, id, payload)
|
54
|
+
log_rendering_start(payload, name)
|
55
|
+
|
56
|
+
super
|
57
|
+
end
|
24
58
|
|
25
59
|
def logger
|
26
60
|
ActionView::Base.logger
|
27
61
|
end
|
28
62
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def from_rails_root(string)
|
63
|
+
private
|
64
|
+
EMPTY = ""
|
65
|
+
def from_rails_root(string) # :doc:
|
33
66
|
string = string.sub(rails_root, EMPTY)
|
34
67
|
string.sub!(VIEWS_PATTERN, EMPTY)
|
35
68
|
string
|
36
69
|
end
|
37
70
|
|
38
|
-
def rails_root
|
71
|
+
def rails_root # :doc:
|
39
72
|
@root ||= "#{Rails.root}/"
|
40
73
|
end
|
74
|
+
|
75
|
+
def render_count(payload) # :doc:
|
76
|
+
if payload[:cache_hits]
|
77
|
+
"[#{payload[:cache_hits]} / #{payload[:count]} cache hits]"
|
78
|
+
else
|
79
|
+
"[#{payload[:count]} times]"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def cache_message(payload) # :doc:
|
84
|
+
case payload[:cache_hit]
|
85
|
+
when :hit
|
86
|
+
"[cache hit]"
|
87
|
+
when :miss
|
88
|
+
"[cache miss]"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def log_rendering_start(payload, name)
|
93
|
+
debug do
|
94
|
+
qualifier =
|
95
|
+
if name == "render_template.action_view"
|
96
|
+
""
|
97
|
+
elsif name == "render_layout.action_view"
|
98
|
+
"layout "
|
99
|
+
end
|
100
|
+
|
101
|
+
return unless qualifier
|
102
|
+
|
103
|
+
message = +" Rendering #{qualifier}#{from_rails_root(payload[:identifier])}"
|
104
|
+
message << " within #{from_rails_root(payload[:layout])}" if payload[:layout]
|
105
|
+
message
|
106
|
+
end
|
107
|
+
end
|
41
108
|
end
|
42
109
|
end
|
43
110
|
|