@@ -50,28 +50,58 @@ def render_collection(event)
50
50
end
51
51
end
52
52
53
- def start ( name , id , payload )
54
- log_rendering_start ( payload , name )
53
+ module Utils # :nodoc:
54
+ def logger
55
+ ActionView ::Base . logger
56
+ end
55
57
56
- super
57
- end
58
+ private
59
+ def from_rails_root ( string )
60
+ string = string . sub ( rails_root , "" )
61
+ string . sub! ( VIEWS_PATTERN , "" )
62
+ string
63
+ end
58
64
59
- def logger
60
- ActionView ::Base . logger
65
+ def rails_root # :doc:
66
+ @root ||= "#{ Rails . root } /"
67
+ end
61
68
end
62
69
63
- private
64
- EMPTY = ""
65
- def from_rails_root ( string ) # :doc:
66
- string = string . sub ( rails_root , EMPTY )
67
- string . sub! ( VIEWS_PATTERN , EMPTY )
68
- string
70
+ include Utils
71
+
72
+ class Start # :nodoc:
73
+ include Utils
74
+
75
+ def start ( name , id , payload )
76
+ return unless logger
77
+ logger . debug do
78
+ qualifier =
79
+ if name == "render_template.action_view"
80
+ ""
81
+ elsif name == "render_layout.action_view"
82
+ "layout "
83
+ end
84
+
85
+ return unless qualifier
86
+
87
+ message = +" Rendering #{ qualifier } #{ from_rails_root ( payload [ :identifier ] ) } "
88
+ message << " within #{ from_rails_root ( payload [ :layout ] ) } " if payload [ :layout ]
89
+ message
90
+ end
91
+ end
92
+
93
+ def finish ( name , id , payload )
94
+ end
69
95
end
70
96
71
- def rails_root # :doc:
72
- @root ||= "#{ Rails . root } /"
97
+ def self . attach_to ( *)
98
+ ActiveSupport ::Notifications . subscribe ( "render_template.action_view" , ActionView ::LogSubscriber ::Start . new )
99
+ ActiveSupport ::Notifications . subscribe ( "render_layout.action_view" , ActionView ::LogSubscriber ::Start . new )
100
+
101
+ super
73
102
end
74
103
104
+ private
75
105
def render_count ( payload ) # :doc:
76
106
if payload [ :cache_hits ]
77
107
"[#{ payload [ :cache_hits ] } / #{ payload [ :count ] } cache hits]"
@@ -88,23 +118,6 @@ def cache_message(payload) # :doc:
88
118
"[cache miss]"
89
119
end
90
120
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
108
121
end
109
122
end
110
123
0 commit comments