josevalim-rails-footnotes 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +10 -2
- data/README +6 -5
- data/lib/rails-footnotes/footnotes.rb +8 -7
- data/lib/rails-footnotes/notes/abstract_note.rb +12 -1
- data/lib/rails-footnotes/notes/assigns_note.rb +44 -0
- data/lib/rails-footnotes/notes/cookies_note.rb +2 -2
- data/lib/rails-footnotes/notes/layout_note.rb +1 -1
- data/lib/rails-footnotes/notes/params_note.rb +2 -2
- data/lib/rails-footnotes/notes/queries_note.rb +39 -13
- data/lib/rails-footnotes/notes/routes_note.rb +2 -2
- data/lib/rails-footnotes/notes/session_note.rb +5 -1
- metadata +3 -3
- data/lib/rails-footnotes/notes/components_note.rb +0 -79
data/CHANGELOG
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
== Footnotes v3.6
|
|
2
|
+
* Cookies, sessions and params notes now use table;
|
|
3
|
+
* Old components note removed;
|
|
4
|
+
* Added assigns notes (thanks to scorpio);
|
|
5
|
+
* Improve query note, count query time and display it with several configurable
|
|
6
|
+
options (:alert_db_time and :alert_sql_number) (thanks to scorpio);
|
|
7
|
+
* Fixed bugs of layout link and route note related (thanks to scorpio).
|
|
8
|
+
|
|
1
9
|
== Footnotes v3.5
|
|
2
|
-
* Added NewRelic RPM footnote (
|
|
3
|
-
* Several bug fixes (
|
|
10
|
+
* Added NewRelic RPM footnote (thanks to kbrock);
|
|
11
|
+
* Several bug fixes (thanks to kbrock, ivanoats and kristopher).
|
|
4
12
|
|
|
5
13
|
== Footnotes v3.4
|
|
6
14
|
* Rails 2.3 compatible.
|
data/README
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Rails Footnotes
|
|
2
2
|
License: MIT
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.6
|
|
4
4
|
|
|
5
5
|
You can also read this README in pretty html at the GitHub project Wiki page
|
|
6
6
|
|
|
@@ -131,9 +131,10 @@ Then put in your environment:
|
|
|
131
131
|
Colaborators
|
|
132
132
|
------------
|
|
133
133
|
|
|
134
|
-
* http://github.com/
|
|
135
|
-
* http://github.com/
|
|
136
|
-
* http://github.com/
|
|
134
|
+
* Leon Li - http://github.com/scorpio
|
|
135
|
+
* Keenan Brock - http://github.com/kbrock
|
|
136
|
+
* Ivan Storck - http://github.com/ivanoats
|
|
137
|
+
* Kris Chamber - http://github.com/kristopher
|
|
137
138
|
|
|
138
139
|
|
|
139
140
|
Bugs and Feedback
|
|
@@ -149,7 +150,7 @@ http://josevalim.blogspot.com/
|
|
|
149
150
|
Version 2.0
|
|
150
151
|
-----------
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
This plugin was created and maintained until version 2.0 by Duane Johnson:
|
|
153
154
|
|
|
154
155
|
Copyright (c) 2006 InquiryLabs, Inc.
|
|
155
156
|
http://blog.inquirylabs.com/
|
|
@@ -10,11 +10,12 @@ module Footnotes
|
|
|
10
10
|
# Edit notes
|
|
11
11
|
@@notes = [ :controller, :view, :layout, :stylesheets, :javascripts ]
|
|
12
12
|
# Show notes
|
|
13
|
-
@@notes += [ :session, :cookies, :params, :filters, :routes, :env, :log, :general ]
|
|
13
|
+
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general ]
|
|
14
|
+
|
|
15
|
+
# Change queries for rpm note when available
|
|
14
16
|
if defined?(NewRelic)
|
|
17
|
+
@@notes.delete(:queries)
|
|
15
18
|
@@notes << :rpm
|
|
16
|
-
else
|
|
17
|
-
@@notes << :queries
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# :no_style => If you don't want the style to be appended to your pages
|
|
@@ -168,6 +169,7 @@ module Footnotes
|
|
|
168
169
|
#footnotes_debug table {text-align: center;}
|
|
169
170
|
#footnotes_debug table td {padding: 0 5px;}
|
|
170
171
|
#footnotes_debug tbody {text-align: left;}
|
|
172
|
+
#footnotes_debug .name_values td {vertical-align: top;}
|
|
171
173
|
#footnotes_debug legend {background-color: #FFF;}
|
|
172
174
|
#footnotes_debug fieldset {text-align: left; border: 1px dashed #aaa; padding: 0.5em 1em 1em 1em; margin: 1em 2em; color: #444; background-color: #FFF;}
|
|
173
175
|
/* Aditional Stylesheets */
|
|
@@ -232,11 +234,10 @@ module Footnotes
|
|
|
232
234
|
<!-- End Footnotes -->
|
|
233
235
|
HTML
|
|
234
236
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
insert_text :after,
|
|
237
|
+
placeholder = /<div[^>]+id=['"]footnotes_holder['"][^>]*>/i
|
|
238
|
+
if @body =~ placeholder
|
|
239
|
+
insert_text :after, placeholder, footnotes_html
|
|
238
240
|
else
|
|
239
|
-
# Otherwise, try to insert as the last part of the html body
|
|
240
241
|
insert_text :before, /<\/body>/i, footnotes_html
|
|
241
242
|
end
|
|
242
243
|
end
|
|
@@ -155,9 +155,20 @@ module Footnotes
|
|
|
155
155
|
TABLE
|
|
156
156
|
end
|
|
157
157
|
|
|
158
|
+
# Mount table for hash, using name and value and adding a name_value class
|
|
159
|
+
# to the generated table.
|
|
160
|
+
#
|
|
161
|
+
def mount_table_for_hash(hash)
|
|
162
|
+
rows = []
|
|
163
|
+
hash.each do |key, value|
|
|
164
|
+
rows << [ key.to_sym.inspect, escape(value.inspect) ]
|
|
165
|
+
end
|
|
166
|
+
mount_table(rows.unshift(['Name', 'Value']), :class => 'name_value')
|
|
167
|
+
end
|
|
168
|
+
|
|
158
169
|
def hash_to_xml_attributes(hash)
|
|
159
170
|
return hash.collect{ |key, value| "#{key.to_s}=\"#{value.gsub('"','\"')}\"" }.join(' ')
|
|
160
171
|
end
|
|
161
172
|
end
|
|
162
173
|
end
|
|
163
|
-
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "#{File.dirname(__FILE__)}/abstract_note"
|
|
2
|
+
|
|
3
|
+
module Footnotes
|
|
4
|
+
module Notes
|
|
5
|
+
class AssignsNote < AbstractNote
|
|
6
|
+
@@ignored_assigns = %w( @template @_request @db_rt_before_render @db_rt_after_render @view_runtime )
|
|
7
|
+
cattr_accessor :ignored_assigns, :instance_writter => false
|
|
8
|
+
|
|
9
|
+
def initialize(controller)
|
|
10
|
+
@controller = controller
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def title
|
|
14
|
+
"Assigns (#{assigns.size})"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def valid?
|
|
18
|
+
assigns
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def content
|
|
22
|
+
rows = []
|
|
23
|
+
assigns.each do |key|
|
|
24
|
+
rows << [ key, assigned_value(key) ]
|
|
25
|
+
end
|
|
26
|
+
mount_table(rows.unshift(['Name', 'Value']), :class => 'name_values')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
protected
|
|
30
|
+
|
|
31
|
+
def assigns
|
|
32
|
+
return @assigns if @assigns
|
|
33
|
+
|
|
34
|
+
@assigns = @controller.instance_variables
|
|
35
|
+
@assigns -= @controller.protected_instance_variables
|
|
36
|
+
@assigns -= ignored_assigns
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def assigned_value(key)
|
|
40
|
+
escape(@controller.instance_variable_get(key).inspect)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -21,7 +21,7 @@ module Footnotes
|
|
|
21
21
|
|
|
22
22
|
protected
|
|
23
23
|
def filename
|
|
24
|
-
File.join(File.expand_path(RAILS_ROOT), 'app', 'layouts', "#{@controller.active_layout.to_s.underscore}
|
|
24
|
+
File.join(File.expand_path(RAILS_ROOT), 'app', 'layouts', "#{@controller.active_layout.to_s.underscore}").sub('/layouts/layouts/', '/views/layouts/')
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -3,8 +3,10 @@ require "#{File.dirname(__FILE__)}/abstract_note"
|
|
|
3
3
|
module Footnotes
|
|
4
4
|
module Notes
|
|
5
5
|
class QueriesNote < AbstractNote
|
|
6
|
+
@@alert_db_time = 0.16
|
|
7
|
+
@@alert_sql_number = 8
|
|
6
8
|
@@sql = []
|
|
7
|
-
cattr_accessor :sql
|
|
9
|
+
cattr_accessor :sql, :alert_db_time, :alert_sql_number, :alert_explain, :instance_writter => false
|
|
8
10
|
|
|
9
11
|
def self.start!(controller)
|
|
10
12
|
@@sql = []
|
|
@@ -15,16 +17,23 @@ module Footnotes
|
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def title
|
|
18
|
-
|
|
20
|
+
db_time = @@sql.inject(0){|sum, item| sum += item.time }
|
|
21
|
+
query_color = generate_red_color(@@sql.length, alert_sql_number)
|
|
22
|
+
db_color = generate_red_color(db_time, alert_db_time)
|
|
23
|
+
|
|
24
|
+
<<-TITLE
|
|
25
|
+
<span style="background-color:#{query_color}">Queries (#{@@sql.length})</span>
|
|
26
|
+
<span style="background-color:#{db_color}">DB (#{"%.6f" % db_time}s)</span>
|
|
27
|
+
TITLE
|
|
19
28
|
end
|
|
20
29
|
|
|
21
30
|
def stylesheet
|
|
22
|
-
<<-STYLESHEET
|
|
31
|
+
<<-STYLESHEET
|
|
23
32
|
#queries_debug_info table td, #queries_debug_info table th{border:1px solid #A00; padding:0 3px; text-align:center;}
|
|
24
33
|
#queries_debug_info table thead, #queries_debug_info table tbody {color:#A00;}
|
|
25
34
|
#queries_debug_info p {background-color:#F3F3FF; border:1px solid #CCC; margin:12px; padding:4px 6px;}
|
|
26
35
|
#queries_debug_info a:hover {text-decoration:underline;}
|
|
27
|
-
STYLESHEET
|
|
36
|
+
STYLESHEET
|
|
28
37
|
end
|
|
29
38
|
|
|
30
39
|
def content
|
|
@@ -32,16 +41,16 @@ STYLESHEET
|
|
|
32
41
|
|
|
33
42
|
@@sql.each_with_index do |item, i|
|
|
34
43
|
sql_links = []
|
|
35
|
-
sql_links << "<a href=\"
|
|
36
|
-
sql_links << "<a href=\"
|
|
44
|
+
sql_links << "<a href=\"javascript:Footnotes.toggle('qtable_#{i}')\" style=\"color:#A00;\">explain</a>" if item.explain
|
|
45
|
+
sql_links << "<a href=\"javascript:Footnotes.toggle('qtrace_#{i}')\" style=\"color:#00A;\">trace</a>" if item.trace
|
|
37
46
|
|
|
38
|
-
html << <<-HTML
|
|
47
|
+
html << <<-HTML
|
|
39
48
|
<b id="qtitle_#{i}">#{escape(item.type.to_s.upcase)}</b> (#{sql_links.join(' | ')})<br />
|
|
40
49
|
#{print_name_and_time(item.name, item.time)}<br />
|
|
41
|
-
#{print_query(item.query)}
|
|
50
|
+
<span id="explain_#{i}">#{print_query(item.query)}</span><br />
|
|
42
51
|
#{print_explain(i, item.explain) if item.explain}
|
|
43
52
|
<p id="qtrace_#{i}" style="display:none;">#{parse_trace(item.trace) if item.trace}</p><br />
|
|
44
|
-
HTML
|
|
53
|
+
HTML
|
|
45
54
|
end
|
|
46
55
|
|
|
47
56
|
return html
|
|
@@ -51,7 +60,9 @@ HTML
|
|
|
51
60
|
def parse_explain(results)
|
|
52
61
|
table = []
|
|
53
62
|
table << results.fetch_fields.map(&:name)
|
|
54
|
-
results.each
|
|
63
|
+
results.each do |row|
|
|
64
|
+
table << row
|
|
65
|
+
end
|
|
55
66
|
table
|
|
56
67
|
end
|
|
57
68
|
|
|
@@ -63,7 +74,7 @@ HTML
|
|
|
63
74
|
end
|
|
64
75
|
|
|
65
76
|
def print_name_and_time(name, time)
|
|
66
|
-
"
|
|
77
|
+
"<span style='background-color:#{generate_red_color(time, alert_ratio)}'>#{escape(name || 'SQL')} (#{sprintf('%f', time)}s)</span>"
|
|
67
78
|
end
|
|
68
79
|
|
|
69
80
|
def print_query(query)
|
|
@@ -73,6 +84,20 @@ HTML
|
|
|
73
84
|
def print_explain(i, explain)
|
|
74
85
|
mount_table(parse_explain(explain), :id => "qtable_#{i}", :style => 'margin:10px;display:none;')
|
|
75
86
|
end
|
|
87
|
+
|
|
88
|
+
def generate_red_color(value, alert)
|
|
89
|
+
c = ((value.to_f/alert).to_i - 1) * 16
|
|
90
|
+
c = 0 if c < 0
|
|
91
|
+
c = 15 if c > 15
|
|
92
|
+
|
|
93
|
+
c = (15-c).to_s(16)
|
|
94
|
+
"#ff#{c*4}"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def alert_ratio
|
|
98
|
+
alert_db_time / alert_sql_number
|
|
99
|
+
end
|
|
100
|
+
|
|
76
101
|
end
|
|
77
102
|
end
|
|
78
103
|
|
|
@@ -87,7 +112,8 @@ HTML
|
|
|
87
112
|
@query = query
|
|
88
113
|
@explain = explain
|
|
89
114
|
|
|
90
|
-
# Strip, select those ones from app and reject first two, because they
|
|
115
|
+
# Strip, select those ones from app and reject first two, because they
|
|
116
|
+
# are from the plugin
|
|
91
117
|
@trace = Kernel.caller.collect(&:strip).select{|i| i.gsub!(/^#{RAILS_ROOT}\//im, '') }[2..-1]
|
|
92
118
|
end
|
|
93
119
|
end
|
|
@@ -125,7 +151,7 @@ HTML
|
|
|
125
151
|
if @logger
|
|
126
152
|
@logger.silence do
|
|
127
153
|
result = yield
|
|
128
|
-
end
|
|
154
|
+
end
|
|
129
155
|
else
|
|
130
156
|
result = yield
|
|
131
157
|
end
|
|
@@ -20,7 +20,7 @@ module Footnotes
|
|
|
20
20
|
def parse_routes
|
|
21
21
|
routes_with_name = ActionController::Routing::Routes.named_routes.to_a.flatten
|
|
22
22
|
|
|
23
|
-
return ActionController::Routing::Routes.filtered_routes(:controller => @controller.
|
|
23
|
+
return ActionController::Routing::Routes.filtered_routes(:controller => @controller.controller_path).collect do |route|
|
|
24
24
|
# Catch routes name if exists
|
|
25
25
|
i = routes_with_name.index(route)
|
|
26
26
|
name = i ? routes_with_name[i-1].to_s : ''
|
|
@@ -56,4 +56,4 @@ end
|
|
|
56
56
|
|
|
57
57
|
if Footnotes::Notes::RoutesNote.included?
|
|
58
58
|
ActionController::Routing::RouteSet.send :include, Footnotes::Extensions::Routes
|
|
59
|
-
end
|
|
59
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: josevalim-rails-footnotes
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-05-
|
|
12
|
+
date: 2009-05-12 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -30,7 +30,7 @@ files:
|
|
|
30
30
|
- lib/rails-footnotes/backtracer.rb
|
|
31
31
|
- lib/rails-footnotes/footnotes.rb
|
|
32
32
|
- lib/rails-footnotes/notes/abstract_note.rb
|
|
33
|
-
- lib/rails-footnotes/notes/
|
|
33
|
+
- lib/rails-footnotes/notes/assigns_note.rb
|
|
34
34
|
- lib/rails-footnotes/notes/controller_note.rb
|
|
35
35
|
- lib/rails-footnotes/notes/cookies_note.rb
|
|
36
36
|
- lib/rails-footnotes/notes/env_note.rb
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
require "#{File.dirname(__FILE__)}/abstract_note"
|
|
2
|
-
require "#{File.dirname(__FILE__)}/controller_note"
|
|
3
|
-
require "#{File.dirname(__FILE__)}/view_note"
|
|
4
|
-
require "#{File.dirname(__FILE__)}/params_note"
|
|
5
|
-
|
|
6
|
-
module Footnotes
|
|
7
|
-
module Notes
|
|
8
|
-
module ComponentsNote
|
|
9
|
-
def self.included(base)
|
|
10
|
-
base.extend ClassMethods
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
module ClassMethods
|
|
14
|
-
def to_sym
|
|
15
|
-
@note_sym ||= "#{self.title.underscore}_component_#{(rand*1000).to_i}".to_sym
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def title
|
|
19
|
-
@note_title ||= self.name.match(/^Footnotes::Notes::(\w+)ComponentNote$/)[1]
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def initialize(controller)
|
|
24
|
-
super
|
|
25
|
-
@controller = controller
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def row
|
|
29
|
-
"#{@controller.controller_name.camelize}##{@controller.action_name.camelize} Component"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def legend
|
|
33
|
-
"#{super} for #{row}"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
class ControllerComponentNote < ControllerNote; include ComponentsNote; end
|
|
38
|
-
class ViewComponentNote < ViewNote; include ComponentsNote; end
|
|
39
|
-
class ParamsComponentNote < ParamsNote; include ComponentsNote; end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
module Components
|
|
43
|
-
|
|
44
|
-
def self.included(base)
|
|
45
|
-
base.class_eval do
|
|
46
|
-
alias_method_chain :add_footnotes!, :component
|
|
47
|
-
Footnotes::Filter.notes.delete(:components)
|
|
48
|
-
@@component_notes = [ :controller, :view, :params ]
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def add_footnotes_with_component!
|
|
53
|
-
if component_request?
|
|
54
|
-
initialize_component_notes!
|
|
55
|
-
Footnotes::Filter.notes.unshift(*@notes)
|
|
56
|
-
else
|
|
57
|
-
add_footnotes_without_component!
|
|
58
|
-
Footnotes::Filter.notes.delete_if {|note| note.class.to_s =~ /(ComponentNote)$/}
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
protected
|
|
63
|
-
def initialize_component_notes!
|
|
64
|
-
@@component_notes.flatten.each do |note|
|
|
65
|
-
begin
|
|
66
|
-
note = eval("Footnotes::Notes::#{note.to_s.camelize}ComponentNote").new(@controller) if note.is_a?(Symbol) || note.is_a?(String)
|
|
67
|
-
@notes << note if note.respond_to?(:valid?) && note.valid?
|
|
68
|
-
rescue Exception => e
|
|
69
|
-
# Discard note if it has a problem
|
|
70
|
-
self.class.log_error("Footnotes #{note.to_s.camelize}ComponentNote Exception", e)
|
|
71
|
-
next
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
Footnotes::Filter.__send__ :include, Footnotes::Components if Footnotes::Filter.notes.include?(:components)
|