Skip to content

Commit

Permalink
forgot to add file
Browse files Browse the repository at this point in the history
  • Loading branch information
coreymartella committed Jul 8, 2009
1 parent a65c799 commit 0878837
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/rails-footnotes/notes/partials_note.rb
@@ -0,0 +1,50 @@
module Footnotes
module Notes
class PartialsNote < LogNote
def initialize(controller)
super
@controller = controller
end
def row
:edit
end
def title
"Partials (#{partials.size})"
end
def content
links = partials.map do |file|
href = Footnotes::Filter.prefix(file,1,1)
"<tr><td><a href=\"#{href}\">#{file.gsub(File.join(Rails.root,"app/views/"),"")}</td><td>#{@partial_times[file].sum}ms</a></td><td>#{@partial_counts[file]}</td></tr>"
end
"<table><thead><tr><th>Partial</th><th>Time</th><th>Count</th></tr></thead><tbody>#{links.join}</tbody></table>"
end

protected
#Generate a list of partials that were rendered, also build up render times and counts.
#This is memoized so we can use its information in the title easily.
def partials
@partials ||= begin
partials = []
@partial_counts = {}
@partial_times = {}
log_lines = log_tail
log_lines.split("\n").each do |line|
if line =~ /Rendered (\S*) \(([\d\.]+)ms\)/
partial = $1
files = Dir.glob("#{Rails.root}/app/views/#{partial}*")
for file in files
#TODO figure out what format got rendered if theres multiple
@partial_times[file] ||= []
@partial_times[file] << $2.to_f
@partial_counts[file] ||= 0
@partial_counts[file] += 1
partials << file unless partials.include?(file)
end
end
end
partials.reverse
end
end
end
end
end

0 comments on commit 0878837

Please sign in to comment.