diff --git a/lib/rails-footnotes/notes/partials_note.rb b/lib/rails-footnotes/notes/partials_note.rb new file mode 100644 index 0000000..e2834fe --- /dev/null +++ b/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) + "#{file.gsub(File.join(Rails.root,"app/views/"),"")}#{@partial_times[file].sum}ms#{@partial_counts[file]}" + end + "#{links.join}
PartialTimeCount
" + 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 \ No newline at end of file