Skip to content

Commit

Permalink
merged in partials footnote from coreymartealla
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Dec 31, 2009
2 parents 945c36e + 0878837 commit bec1844
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rails-footnotes/footnotes.rb
Expand Up @@ -8,7 +8,7 @@ class Filter
@@prefix = 'txmt://open?url=file://%s&line=%d&column=%d'

# Edit notes
@@notes = [ :controller, :view, :layout, :stylesheets, :javascripts ]
@@notes = [ :controller, :view, :layout, :partials, :stylesheets, :javascripts ]
# Show notes
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general ]

Expand Down Expand Up @@ -165,6 +165,7 @@ def insert_styles
<!-- Footnotes Style -->
<style type="text/css">
#footnotes_debug {margin: 2em 0 1em 0; text-align: center; color: #444; line-height: 16px;}
#footnotes_debug th, #footnotes_debug td {color: #444; line-height: 18px;}
#footnotes_debug a {text-decoration: none; color: #444; line-height: 18px;}
#footnotes_debug table {text-align: center;}
#footnotes_debug table td {padding: 0 5px;}
Expand Down
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 bec1844

Please sign in to comment.