rails3-footnotes 4.0.0.pre.3 → 4.0.0.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/rails-footnotes.rb +4 -0
- data/lib/rails-footnotes/footnotes.rb +2 -2
- data/lib/rails-footnotes/notes/layout_note.rb +6 -8
- data/lib/rails-footnotes/notes/partials_note.rb +4 -21
- data/lib/rails-footnotes/notes/queries_note.rb +2 -2
- data/lib/rails-footnotes/notes/render_note.rb +40 -0
- data/lib/rails-footnotes/version.rb +1 -1
- data/lib/rails-footnotes/view_subscriber.rb +48 -0
- metadata +5 -4
- data/lib/rails-footnotes/notes/view_note.rb +0 -75
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== Footnotes v4.0.0.pre.4 (April 2, 2011)
|
2
|
+
* fix event[:duration] to event.duration in query note
|
3
|
+
* fix layout note to work again
|
4
|
+
* rename views note to render note since it lists renders
|
5
|
+
|
1
6
|
== Footnotes v4.0.0.pre.3 (March 30, 2011)
|
2
7
|
* Merge in contributions from irjudson and jackkinsella
|
3
8
|
* fixes for partials note
|
data/lib/rails-footnotes.rb
CHANGED
@@ -5,11 +5,15 @@ module Footnotes
|
|
5
5
|
if ::Rails.env.development?
|
6
6
|
require 'rails-footnotes/footnotes'
|
7
7
|
require 'rails-footnotes/backtracer'
|
8
|
+
require 'rails-footnotes/view_subscriber'
|
8
9
|
|
9
10
|
# Require each individual note
|
10
11
|
notes_glob = File.expand_path("../rails-footnotes/notes/*.rb", __FILE__)
|
11
12
|
Dir[notes_glob].each{|note| require note }
|
12
13
|
|
14
|
+
# Subscribe to view events so we can use them later
|
15
|
+
ActiveSupport::LogSubscriber.attach_to(:action_view, Footnotes.view_subscriber)
|
16
|
+
|
13
17
|
# The footnotes are applied by default to all actions. To remove the
|
14
18
|
# footnotes from an action, use skip_filter in your controller.
|
15
19
|
ActionController::Base.prepend_before_filter Footnotes::BeforeFilter
|
@@ -25,9 +25,9 @@ module Footnotes
|
|
25
25
|
@@prefix = 'txmt://open?url=file://%s&line=%d&column=%d'.html_safe
|
26
26
|
|
27
27
|
# Edit notes
|
28
|
-
@@notes = [ :controller, :
|
28
|
+
@@notes = [ :controller, :layout, :partials, :stylesheets, :javascripts ]
|
29
29
|
# Show notes
|
30
|
-
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log ]
|
30
|
+
@@notes += [ :render, :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log ]
|
31
31
|
|
32
32
|
# Change queries for rpm note when available
|
33
33
|
# if defined?(NewRelic)
|
@@ -3,9 +3,6 @@ require "#{File.dirname(__FILE__)}/abstract_note"
|
|
3
3
|
module Footnotes
|
4
4
|
module Notes
|
5
5
|
class LayoutNote < AbstractNote
|
6
|
-
def initialize(controller)
|
7
|
-
@controller = controller
|
8
|
-
end
|
9
6
|
|
10
7
|
def row
|
11
8
|
:edit
|
@@ -16,13 +13,14 @@ module Footnotes
|
|
16
13
|
end
|
17
14
|
|
18
15
|
def valid?
|
19
|
-
prefix? &&
|
16
|
+
prefix? && filename
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def filename
|
21
|
+
Dir[Footnotes.view_subscriber.layout.to_s+".html*"].first
|
20
22
|
end
|
21
23
|
|
22
|
-
protected
|
23
|
-
def filename
|
24
|
-
File.join(File.expand_path(Rails.root), 'app', 'layouts', "#{@controller.active_layout.to_s.underscore}").sub('/layouts/layouts/', '/views/layouts/')
|
25
|
-
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -3,19 +3,12 @@ require "#{File.dirname(__FILE__)}/log_note"
|
|
3
3
|
module Footnotes
|
4
4
|
module Notes
|
5
5
|
class PartialsNote < LogNote
|
6
|
-
@@partial_subscriber = nil
|
7
|
-
cattr_accessor :partial_subscriber
|
8
6
|
|
9
7
|
def initialize(controller)
|
10
8
|
super
|
11
9
|
@controller = controller
|
12
10
|
end
|
13
11
|
|
14
|
-
def self.start!(controller)
|
15
|
-
@@partial_subscriber = Footnotes::Notes::PartialSubscriber.new
|
16
|
-
ActiveSupport::LogSubscriber.attach_to(:action_view, @@partial_subscriber)
|
17
|
-
end
|
18
|
-
|
19
12
|
def row
|
20
13
|
:edit
|
21
14
|
end
|
@@ -27,8 +20,8 @@ module Footnotes
|
|
27
20
|
def content
|
28
21
|
rows = partials.map do |filename|
|
29
22
|
href = Footnotes::Filter.prefix(filename,1,1)
|
30
|
-
|
31
|
-
[%{<a href="#{href}">#{
|
23
|
+
name = filename.gsub(Rails.root.join("app/views/"),"")
|
24
|
+
[%{<a href="#{href}">#{name}</a>},"#{@partial_times[filename].sum}ms", @partial_counts[filename]]
|
32
25
|
end
|
33
26
|
mount_table(rows.unshift(%w(Partial Time Count)), :summary => "Partials for #{title}")
|
34
27
|
end
|
@@ -37,7 +30,7 @@ module Footnotes
|
|
37
30
|
self.loaded = true unless loaded
|
38
31
|
end
|
39
32
|
|
40
|
-
|
33
|
+
protected
|
41
34
|
#Generate a list of partials that were rendered, also build up render times and counts.
|
42
35
|
#This is memoized so we can use its information in the title easily.
|
43
36
|
def partials
|
@@ -45,7 +38,7 @@ module Footnotes
|
|
45
38
|
partials = []
|
46
39
|
@partial_counts = {}
|
47
40
|
@partial_times = {}
|
48
|
-
|
41
|
+
Footnotes.view_subscriber.partials.each do |event|
|
49
42
|
partial = event.payload[:identifier]
|
50
43
|
@partial_times[partial] ||= []
|
51
44
|
@partial_times[partial] << event.duration
|
@@ -56,17 +49,7 @@ module Footnotes
|
|
56
49
|
partials.reverse
|
57
50
|
end
|
58
51
|
end
|
59
|
-
end
|
60
|
-
class PartialSubscriber < ActiveSupport::LogSubscriber
|
61
|
-
attr_accessor :events
|
62
|
-
def initialize
|
63
|
-
@events = Array.new
|
64
|
-
super
|
65
|
-
end
|
66
52
|
|
67
|
-
def render_partial(event)
|
68
|
-
@events << event.dup
|
69
|
-
end
|
70
53
|
end
|
71
54
|
end
|
72
55
|
end
|
@@ -31,7 +31,7 @@ module Footnotes
|
|
31
31
|
|
32
32
|
def title
|
33
33
|
queries = @@query_subscriber.events.length
|
34
|
-
total_time = @@query_subscriber.events.
|
34
|
+
total_time = @@query_subscriber.events.map{|e| e.duration }.sum / 1000.0
|
35
35
|
query_color = generate_red_color(@@query_subscriber.events.length, alert_sql_number)
|
36
36
|
db_color = generate_red_color(total_time, alert_db_time)
|
37
37
|
|
@@ -55,7 +55,7 @@ module Footnotes
|
|
55
55
|
|
56
56
|
@@query_subscriber.events.each_with_index do |item, i|
|
57
57
|
html << <<-HTML
|
58
|
-
#{print_name_and_time(item.payload[:name], item.
|
58
|
+
#{print_name_and_time(item.payload[:name], item.duration / 1000.0)}
|
59
59
|
<span id="explain_#{i}">#{print_query(item.payload[:sql])}</span><br />
|
60
60
|
HTML
|
61
61
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/abstract_note"
|
2
|
+
require "#{File.dirname(__FILE__)}/../view_subscriber"
|
3
|
+
|
4
|
+
module Footnotes
|
5
|
+
module Notes
|
6
|
+
class RenderNote < AbstractNote
|
7
|
+
|
8
|
+
def initialize(controller)
|
9
|
+
super
|
10
|
+
@controller = controller
|
11
|
+
@page = Footnotes.view_subscriber.page
|
12
|
+
end
|
13
|
+
|
14
|
+
def title
|
15
|
+
"<span style=\"background-color:#{color(@page.duration)}\">Rendered (#{"%.3f" % @page.duration}ms)</span>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def content
|
19
|
+
html = ''
|
20
|
+
|
21
|
+
if @page
|
22
|
+
view = Footnotes.view_subscriber.view_name
|
23
|
+
layout = Footnotes.view_subscriber.layout_name
|
24
|
+
partial_time = Footnotes.view_subscriber.partial_time
|
25
|
+
|
26
|
+
rows = [["View", "Layout", "View Render", "Partial Render", "Total Render"],
|
27
|
+
[escape(view), escape(layout), "#{'%.3f' % (@page.duration - partial_time)}ms",
|
28
|
+
"<a href=\"#\" onclick=\"Footnotes.hideAllAndToggle('partials_debug_info');return false;\">#{'%.3f' % partial_time}ms</a>",
|
29
|
+
"#{'%.3f' % @page.duration}ms"]]
|
30
|
+
mount_table(rows)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def color(value)
|
35
|
+
value > 500.0 ? "#f00" : "#aaa"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Class that can subscribe to and log any view events
|
2
|
+
module Footnotes
|
3
|
+
class ViewSubscriber < ActiveSupport::LogSubscriber
|
4
|
+
attr_accessor :events
|
5
|
+
def initialize
|
6
|
+
@events = Array.new
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_template(event)
|
11
|
+
@events << event.dup
|
12
|
+
end
|
13
|
+
alias :render_partial :render_template
|
14
|
+
alias :render_collection :render_template
|
15
|
+
|
16
|
+
def partials
|
17
|
+
events.select{ |e| e.name =~ /render_partial/ }
|
18
|
+
end
|
19
|
+
|
20
|
+
def partial_time
|
21
|
+
partials.map{|p| p.duration }.sum
|
22
|
+
end
|
23
|
+
|
24
|
+
def page
|
25
|
+
events.find{ |e| e.name =~ /render_template/ }
|
26
|
+
end
|
27
|
+
|
28
|
+
def view
|
29
|
+
page && page.payload[:identifier]
|
30
|
+
end
|
31
|
+
|
32
|
+
def view_name
|
33
|
+
view && view.gsub(Rails.root.join("app/views/"),'')
|
34
|
+
end
|
35
|
+
|
36
|
+
def layout
|
37
|
+
page && Rails.root.join("app/views", page.payload[:layout])
|
38
|
+
end
|
39
|
+
|
40
|
+
def layout_name
|
41
|
+
page && page.payload[:layout]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.view_subscriber
|
46
|
+
@view_subscriber ||= ViewSubscriber.new
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-footnotes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1923831841
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 4
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- pre
|
11
|
-
-
|
12
|
-
version: 4.0.0.pre.
|
11
|
+
- 4
|
12
|
+
version: 4.0.0.pre.4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- "Andr\xC3\xA9 Arko"
|
@@ -78,12 +78,13 @@ files:
|
|
78
78
|
- lib/rails-footnotes/notes/params_note.rb
|
79
79
|
- lib/rails-footnotes/notes/partials_note.rb
|
80
80
|
- lib/rails-footnotes/notes/queries_note.rb
|
81
|
+
- lib/rails-footnotes/notes/render_note.rb
|
81
82
|
- lib/rails-footnotes/notes/routes_note.rb
|
82
83
|
- lib/rails-footnotes/notes/rpm_note.rb
|
83
84
|
- lib/rails-footnotes/notes/session_note.rb
|
84
85
|
- lib/rails-footnotes/notes/stylesheets_note.rb
|
85
|
-
- lib/rails-footnotes/notes/view_note.rb
|
86
86
|
- lib/rails-footnotes/version.rb
|
87
|
+
- lib/rails-footnotes/view_subscriber.rb
|
87
88
|
- lib/rails-footnotes.rb
|
88
89
|
- lib/rails3-footnotes.rb
|
89
90
|
- test/footnotes_test.rb
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/abstract_note"
|
2
|
-
|
3
|
-
module Footnotes
|
4
|
-
module Notes
|
5
|
-
class ViewNote < AbstractNote
|
6
|
-
@@alert_time = 500.0
|
7
|
-
@@loaded = false
|
8
|
-
@@view_subscriber = nil
|
9
|
-
|
10
|
-
def initialize(controller)
|
11
|
-
super
|
12
|
-
@controller = controller
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.start!(controller)
|
16
|
-
@@view_subscriber = Footnotes::Notes::ViewSubscriber.new
|
17
|
-
ActiveSupport::LogSubscriber.attach_to(:action_view, @@view_subscriber)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.to_sym
|
21
|
-
:views
|
22
|
-
end
|
23
|
-
|
24
|
-
def title
|
25
|
-
total_time = @@view_subscriber.events.select{ |e| e.name =~ /render_template/ }[0].duration
|
26
|
-
"<span style=\"background-color:#{generate_red_color(total_time)}\">View Render (#{"%.3f" % total_time}ms)</span>"
|
27
|
-
end
|
28
|
-
|
29
|
-
def content
|
30
|
-
html = ''
|
31
|
-
page = @@view_subscriber.events.select{ |e| e.name =~ /render_template/ }[0]
|
32
|
-
partials = @@view_subscriber.events.select{ |e| e.name =~ /render_partial/ }
|
33
|
-
partial_time = partials.inject(0) {|sum, item| sum += item.duration}
|
34
|
-
|
35
|
-
view = page.payload[:identifier].gsub(File.join(Rails.root,"app/views/"),"")
|
36
|
-
layout = page.payload[:layout].gsub(File.join(Rails.root,"app/views/"),"")
|
37
|
-
|
38
|
-
rows = [["View", "Layout", "View Render (ms)", "Partial(s) Render (ms)", "Total Render (ms)"],
|
39
|
-
[escape(view), escape(layout), "#{'%.3f' % (page.duration - partial_time)}",
|
40
|
-
"<a href=\"#\" onclick=\"Footnotes.hideAllAndToggle('partials_debug_info');return false;\">#{'%.3f' % partial_time}</a>",
|
41
|
-
"#{'%.3f' % page.duration}"]]
|
42
|
-
|
43
|
-
puts rows.inspect
|
44
|
-
|
45
|
-
mount_table(rows)
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.load
|
49
|
-
self.loaded = true unless loaded
|
50
|
-
end
|
51
|
-
|
52
|
-
def generate_red_color(value)
|
53
|
-
if value > @@alert_time
|
54
|
-
"#f00"
|
55
|
-
else
|
56
|
-
"#aaa"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class ViewSubscriber < ActiveSupport::LogSubscriber
|
62
|
-
attr_accessor :events
|
63
|
-
def initialize
|
64
|
-
@events = Array.new
|
65
|
-
super
|
66
|
-
end
|
67
|
-
|
68
|
-
def render_template(event)
|
69
|
-
@events << event.dup
|
70
|
-
end
|
71
|
-
alias :render_partial :render_template
|
72
|
-
alias :render_collection :render_template
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|