# Class that can subscribe to and log any view events module Footnotes def self.view_subscriber @view_subscriber ||= ViewSubscriber.new end class ViewSubscriber < ActiveSupport::LogSubscriber attr_reader :events def initialize reset! super end def reset! @events = [] end def render_template(event) events << event.dup end alias :render_partial :render_template alias :render_collection :render_template def partials events.select{ |e| e.name =~ /render_partial/ } end def partial_time partials.map{|p| p.duration }.sum end def page events.find{ |e| e.name =~ /render_template/ } end def view page && page.payload[:identifier] end def view_name view && view.gsub(Rails.root.join("app/views/").to_s, '') end def layout page && page.payload[:layout] end end end