rails-footnotes 3.6.5 → 3.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/README +4 -0
- data/Rakefile +12 -1
- data/lib/rails-footnotes.rb +1 -1
- data/lib/rails-footnotes/footnotes.rb +9 -2
- data/lib/rails-footnotes/notes/abstract_note.rb +3 -2
- data/lib/rails-footnotes/notes/assigns_note.rb +3 -3
- data/lib/rails-footnotes/notes/controller_note.rb +1 -1
- data/lib/rails-footnotes/notes/cookies_note.rb +1 -1
- data/lib/rails-footnotes/notes/env_note.rb +10 -3
- data/lib/rails-footnotes/notes/filters_note.rb +1 -1
- data/lib/rails-footnotes/notes/params_note.rb +1 -1
- data/lib/rails-footnotes/notes/partials_note.rb +50 -0
- data/lib/rails-footnotes/notes/queries_note.rb +31 -12
- data/lib/rails-footnotes/notes/routes_note.rb +1 -1
- data/lib/rails-footnotes/notes/rpm_note.rb +8 -2
- data/lib/rails-footnotes/notes/session_note.rb +12 -2
- data/test/footnotes_test.rb +4 -5
- metadata +3 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== Footnotes v3.6.6
|
2
|
+
* fix for ruby 1.9 compat (thanks to ivanoats)
|
3
|
+
* fix for log note (thanks to tobias)
|
4
|
+
* pre rails 2.3 support fixes (thanks to tobias)
|
5
|
+
* better disabling of query notes (thanks to tobias)
|
6
|
+
* fixed variable assignment escaping (thanks to gdelvino)
|
7
|
+
* fixed cookie value escaping (thanks to indirect)
|
8
|
+
* Turn off footnotes with a parameter footnotes=false (thanks to indirect)
|
9
|
+
|
1
10
|
== Footnotes v3.6
|
2
11
|
* Cookies, sessions and params notes now use table;
|
3
12
|
* Old components note removed;
|
data/README
CHANGED
@@ -62,6 +62,10 @@ Finally, you can control which notes you want to show. The default are:
|
|
62
62
|
|
63
63
|
Footnotes::Filter.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general]
|
64
64
|
|
65
|
+
The queries note by default will not load if it detects New Relic loaded in the app. If you want to load it
|
66
|
+
in this case, add the following to an initializer:
|
67
|
+
|
68
|
+
Footnotes::Notes::QueriesNote.include_when_new_relic_installed = true if defined?(Footnotes)
|
65
69
|
|
66
70
|
Creating your own notes
|
67
71
|
-----------------------
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
require 'jeweler'
|
7
7
|
Jeweler::Tasks.new do |s|
|
8
8
|
s.name = "rails-footnotes"
|
9
|
-
s.version = "3.6.
|
9
|
+
s.version = "3.6.6"
|
10
10
|
s.rubyforge_project = "rails-footnotes"
|
11
11
|
s.summary = "Every Rails page has footnotes that gives information about your application and links back to your editor."
|
12
12
|
s.email = "jose@plataformatec.com.br"
|
@@ -36,3 +36,14 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
36
36
|
rdoc.rdoc_files.include('MIT-LICENSE')
|
37
37
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
38
|
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
require 'metric_fu'
|
42
|
+
MetricFu::Configuration.run do |config|
|
43
|
+
#skipping: churn, :stats
|
44
|
+
config.metrics = [:saikuro, :flog, :flay, :reek, :roodi, :rcov]
|
45
|
+
# config.graphs = [:flog, :flay, :reek, :roodi, :rcov]
|
46
|
+
config.rcov[:rcov_opts] << "-Itest"
|
47
|
+
end
|
48
|
+
rescue LoadError
|
49
|
+
end
|
data/lib/rails-footnotes.rb
CHANGED
@@ -6,7 +6,7 @@ if RAILS_ENV == 'development'
|
|
6
6
|
# Load all notes
|
7
7
|
#
|
8
8
|
Dir[File.join(dir, 'rails-footnotes', 'notes', '*.rb')].each do |note|
|
9
|
-
require note
|
9
|
+
require note
|
10
10
|
end
|
11
11
|
|
12
12
|
# The footnotes are applied by default to all actions. You can change this
|
@@ -8,7 +8,7 @@ module Footnotes
|
|
8
8
|
@@prefix = 'txmt://open?url=file://%s&line=%d&column=%d'
|
9
9
|
|
10
10
|
# Edit notes
|
11
|
-
@@notes = [ :controller, :view, :layout, :stylesheets, :javascripts ]
|
11
|
+
@@notes = [ :controller, :view, :layout, :partials, :stylesheets, :javascripts ]
|
12
12
|
# Show notes
|
13
13
|
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general ]
|
14
14
|
|
@@ -119,7 +119,9 @@ module Footnotes
|
|
119
119
|
|
120
120
|
protected
|
121
121
|
def valid?
|
122
|
-
performed_render? && valid_format? && valid_content_type? &&
|
122
|
+
performed_render? && valid_format? && valid_content_type? &&
|
123
|
+
@body.is_a?(String) && !component_request? && !xhr? &&
|
124
|
+
!footnotes_disabled?
|
123
125
|
end
|
124
126
|
|
125
127
|
def add_footnotes_without_validation!
|
@@ -156,6 +158,10 @@ module Footnotes
|
|
156
158
|
@controller.request.xhr?
|
157
159
|
end
|
158
160
|
|
161
|
+
def footnotes_disabled?
|
162
|
+
@controller.params[:footnotes] == "false"
|
163
|
+
end
|
164
|
+
|
159
165
|
#
|
160
166
|
# Insertion methods
|
161
167
|
#
|
@@ -165,6 +171,7 @@ module Footnotes
|
|
165
171
|
<!-- Footnotes Style -->
|
166
172
|
<style type="text/css">
|
167
173
|
#footnotes_debug {margin: 2em 0 1em 0; text-align: center; color: #444; line-height: 16px;}
|
174
|
+
#footnotes_debug th, #footnotes_debug td {color: #444; line-height: 18px;}
|
168
175
|
#footnotes_debug a {text-decoration: none; color: #444; line-height: 18px;}
|
169
176
|
#footnotes_debug table {text-align: center;}
|
170
177
|
#footnotes_debug table td {padding: 0 5px;}
|
@@ -145,6 +145,7 @@ module Footnotes
|
|
145
145
|
return '' if array.empty?
|
146
146
|
|
147
147
|
header = header.collect{|i| escape(i.to_s.humanize) }
|
148
|
+
array = array.collect { |a| a.collect { |b| c = b.to_s; escape(c) unless c == ""}}
|
148
149
|
rows = array.collect{|i| "<tr><td>#{i.join('</td><td>')}</td></tr>" }
|
149
150
|
|
150
151
|
<<-TABLE
|
@@ -158,12 +159,12 @@ module Footnotes
|
|
158
159
|
# Mount table for hash, using name and value and adding a name_value class
|
159
160
|
# to the generated table.
|
160
161
|
#
|
161
|
-
def mount_table_for_hash(hash)
|
162
|
+
def mount_table_for_hash(hash, options={})
|
162
163
|
rows = []
|
163
164
|
hash.each do |key, value|
|
164
165
|
rows << [ key.to_sym.inspect, escape(value.inspect) ]
|
165
166
|
end
|
166
|
-
mount_table(rows.unshift(['Name', 'Value']), :class => 'name_value')
|
167
|
+
mount_table(rows.unshift(['Name', 'Value']), {:class => 'name_value'}.merge(options))
|
167
168
|
end
|
168
169
|
|
169
170
|
def hash_to_xml_attributes(hash)
|
@@ -23,7 +23,7 @@ module Footnotes
|
|
23
23
|
assigns.each do |key|
|
24
24
|
rows << [ key, assigned_value(key) ]
|
25
25
|
end
|
26
|
-
mount_table(rows.unshift(['Name', 'Value']), :class => 'name_values')
|
26
|
+
mount_table(rows.unshift(['Name', 'Value']), :class => 'name_values', :summary => "Debug information for #{title}")
|
27
27
|
end
|
28
28
|
|
29
29
|
protected
|
@@ -32,12 +32,12 @@ module Footnotes
|
|
32
32
|
return @assigns if @assigns
|
33
33
|
|
34
34
|
@assigns = @controller.instance_variables
|
35
|
-
@assigns -= @controller.protected_instance_variables
|
35
|
+
@assigns -= @controller.protected_instance_variables if @controller.respond_to? :protected_instance_variables
|
36
36
|
@assigns -= ignored_assigns
|
37
37
|
end
|
38
38
|
|
39
39
|
def assigned_value(key)
|
40
|
-
|
40
|
+
@controller.instance_variable_get(key).inspect
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -51,7 +51,7 @@ module Footnotes
|
|
51
51
|
def lines_from_index(string, index)
|
52
52
|
return nil if string.blank? || index.blank?
|
53
53
|
|
54
|
-
lines = string.to_a
|
54
|
+
lines = string.respond_to?(:to_a) ? string.to_a : string.lines.to_a
|
55
55
|
running_length = 0
|
56
56
|
lines.each_with_index do |line, i|
|
57
57
|
running_length += line.length
|
@@ -8,11 +8,18 @@ module Footnotes
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def content
|
11
|
-
|
12
|
-
|
11
|
+
env_data = @env.to_a.sort.unshift([:key, :value]).map do |k,v|
|
12
|
+
case k
|
13
|
+
when 'HTTP_COOKIE'
|
14
|
+
# Replace HTTP_COOKIE for a link
|
15
|
+
[k, '<a href="#" style="color:#009" onclick="Footnotes.hideAllAndToggle(\'cookies_debug_info\');return false;">See cookies on its tab</a>']
|
16
|
+
else
|
17
|
+
[k, escape(v.to_s)]
|
18
|
+
end
|
19
|
+
end
|
13
20
|
|
14
21
|
# Create the env table
|
15
|
-
mount_table(
|
22
|
+
mount_table(env_data)
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Footnotes
|
2
|
+
module Notes
|
3
|
+
class PartialsNote < LogNote
|
4
|
+
def initialize(controller)
|
5
|
+
super
|
6
|
+
@controller = controller
|
7
|
+
end
|
8
|
+
def row
|
9
|
+
:edit
|
10
|
+
end
|
11
|
+
def title
|
12
|
+
"Partials (#{partials.size})"
|
13
|
+
end
|
14
|
+
def content
|
15
|
+
links = partials.map do |file|
|
16
|
+
href = Footnotes::Filter.prefix(file,1,1)
|
17
|
+
"<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>"
|
18
|
+
end
|
19
|
+
"<table><thead><tr><th>Partial</th><th>Time</th><th>Count</th></tr></thead><tbody>#{links.join}</tbody></table>"
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
#Generate a list of partials that were rendered, also build up render times and counts.
|
24
|
+
#This is memoized so we can use its information in the title easily.
|
25
|
+
def partials
|
26
|
+
@partials ||= begin
|
27
|
+
partials = []
|
28
|
+
@partial_counts = {}
|
29
|
+
@partial_times = {}
|
30
|
+
log_lines = log
|
31
|
+
log_lines.split("\n").each do |line|
|
32
|
+
if line =~ /Rendered (\S*) \(([\d\.]+)\S*?\)/
|
33
|
+
partial = $1
|
34
|
+
files = Dir.glob("#{Rails.root}/app/views/#{partial}*")
|
35
|
+
for file in files
|
36
|
+
#TODO figure out what format got rendered if theres multiple
|
37
|
+
@partial_times[file] ||= []
|
38
|
+
@partial_times[file] << $2.to_f
|
39
|
+
@partial_counts[file] ||= 0
|
40
|
+
@partial_counts[file] += 1
|
41
|
+
partials << file unless partials.include?(file)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
partials.reverse
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -6,8 +6,17 @@ module Footnotes
|
|
6
6
|
@@alert_db_time = 0.16
|
7
7
|
@@alert_sql_number = 8
|
8
8
|
@@sql = []
|
9
|
-
|
10
|
-
|
9
|
+
@@include_when_new_relic_installed = false
|
10
|
+
@@loaded = false
|
11
|
+
|
12
|
+
cattr_accessor :sql, :alert_db_time, :alert_sql_number, :alert_explain, :loaded, :instance_writter => false
|
13
|
+
cattr_reader :include_when_new_relic_installed
|
14
|
+
|
15
|
+
def self.include_when_new_relic_installed=(include_me)
|
16
|
+
@@include_when_new_relic_installed = include_me
|
17
|
+
load if include_me
|
18
|
+
end
|
19
|
+
|
11
20
|
def self.start!(controller)
|
12
21
|
@@sql = []
|
13
22
|
end
|
@@ -55,7 +64,24 @@ module Footnotes
|
|
55
64
|
|
56
65
|
return html
|
57
66
|
end
|
58
|
-
|
67
|
+
|
68
|
+
def self.load
|
69
|
+
#only include when NewRelic is installed if configured to do so
|
70
|
+
if !loaded and
|
71
|
+
included? and
|
72
|
+
defined?(ActiveRecord) and
|
73
|
+
(!defined?(NewRelic) or
|
74
|
+
include_when_new_relic_installed)
|
75
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Footnotes::Extensions::AbstractAdapter
|
76
|
+
ActiveRecord::ConnectionAdapters.local_constants.each do |adapter|
|
77
|
+
next unless adapter =~ /.*[^Abstract]Adapter$/
|
78
|
+
next if adapter =~ /SQLiteAdapter$/
|
79
|
+
eval("ActiveRecord::ConnectionAdapters::#{adapter}").send :include, Footnotes::Extensions::QueryAnalyzer
|
80
|
+
self.loaded = true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
59
85
|
protected
|
60
86
|
def parse_explain(results)
|
61
87
|
table = []
|
@@ -82,7 +108,7 @@ module Footnotes
|
|
82
108
|
end
|
83
109
|
|
84
110
|
def print_explain(i, explain)
|
85
|
-
mount_table(parse_explain(explain), :id => "qtable_#{i}", :style => 'margin:10px;display:none;')
|
111
|
+
mount_table(parse_explain(explain), :id => "qtable_#{i}", :style => 'margin:10px;display:none;', :summary => "Debug information for #{title}")
|
86
112
|
end
|
87
113
|
|
88
114
|
def generate_red_color(value, alert)
|
@@ -162,11 +188,4 @@ module Footnotes
|
|
162
188
|
end
|
163
189
|
end
|
164
190
|
|
165
|
-
|
166
|
-
ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Footnotes::Extensions::AbstractAdapter
|
167
|
-
ActiveRecord::ConnectionAdapters.local_constants.each do |adapter|
|
168
|
-
next unless adapter =~ /.*[^Abstract]Adapter$/
|
169
|
-
next if adapter =~ /SQLiteAdapter$/
|
170
|
-
eval("ActiveRecord::ConnectionAdapters::#{adapter}").send :include, Footnotes::Extensions::QueryAnalyzer
|
171
|
-
end
|
172
|
-
end
|
191
|
+
Footnotes::Notes::QueriesNote.load
|
@@ -13,7 +13,7 @@ module Footnotes
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def content
|
16
|
-
mount_table(@parsed_routes.unshift([:path, :name, :options, :requirements]))
|
16
|
+
mount_table(@parsed_routes.unshift([:path, :name, :options, :requirements]), :summary => "Debug information for #{title}")
|
17
17
|
end
|
18
18
|
|
19
19
|
protected
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/abstract_note"
|
2
2
|
|
3
|
+
if defined?(NewRelic)
|
3
4
|
module Footnotes
|
4
5
|
module Notes
|
5
6
|
class RpmNote < AbstractNote
|
@@ -13,12 +14,17 @@ module Footnotes
|
|
13
14
|
|
14
15
|
def link
|
15
16
|
#{:controller => 'newrelic', :action => 'show_sample_detail', :id => @rpm_id}
|
16
|
-
"/newrelic/show_sample_detail/#{@rpm_id}"
|
17
|
+
"/newrelic/show_sample_detail/#{@rpm_id}" if @rpm_id
|
17
18
|
end
|
18
19
|
|
19
20
|
def valid?
|
20
|
-
|
21
|
+
if defined?(NewRelic::Control)
|
22
|
+
!NewRelic::Control.instance['skip_developer_route']
|
23
|
+
else
|
24
|
+
!NewRelic::Config.instance['skip_developer_route']
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
30
|
+
end
|
@@ -4,7 +4,17 @@ module Footnotes
|
|
4
4
|
module Notes
|
5
5
|
class SessionNote < AbstractNote
|
6
6
|
def initialize(controller)
|
7
|
-
|
7
|
+
session = controller.session
|
8
|
+
if session
|
9
|
+
if session.respond_to? :to_hash
|
10
|
+
# rails >= 2.3
|
11
|
+
session = session.to_hash
|
12
|
+
else
|
13
|
+
#rails < 2.3
|
14
|
+
session = session.data
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@session = (session || {}).symbolize_keys
|
8
18
|
end
|
9
19
|
|
10
20
|
def title
|
@@ -12,7 +22,7 @@ module Footnotes
|
|
12
22
|
end
|
13
23
|
|
14
24
|
def content
|
15
|
-
mount_table_for_hash(@session)
|
25
|
+
mount_table_for_hash(@session, :summary => "Debug information for #{title}")
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
data/test/footnotes_test.rb
CHANGED
@@ -159,12 +159,12 @@ class FootnotesTest < Test::Unit::TestCase
|
|
159
159
|
|
160
160
|
def test_insert_text
|
161
161
|
@footnotes.send(:insert_text, :after, /<head>/, "Graffiti")
|
162
|
-
after = " <head>Graffiti
|
163
|
-
assert_equal after, @controller.response.body.
|
162
|
+
after = " <head>Graffiti"
|
163
|
+
assert_equal after, @controller.response.body.split("\n")[2]
|
164
164
|
|
165
165
|
@footnotes.send(:insert_text, :before, /<\/body>/, "Notes")
|
166
|
-
after = " Notes</body
|
167
|
-
assert_equal after, @controller.response.body.
|
166
|
+
after = " Notes</body>"
|
167
|
+
assert_equal after, @controller.response.body.split("\n")[12]
|
168
168
|
end
|
169
169
|
|
170
170
|
protected
|
@@ -172,7 +172,6 @@ class FootnotesTest < Test::Unit::TestCase
|
|
172
172
|
# Then we call add_footnotes!
|
173
173
|
#
|
174
174
|
def footnotes_perform!
|
175
|
-
@controller.template.expects(:instance_variable_get).returns(true)
|
176
175
|
@controller.template.expects(:template_format).returns('html')
|
177
176
|
@controller.performed_render = true
|
178
177
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-footnotes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.6
|
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:
|
12
|
+
date: 2010-01-31 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/rails-footnotes/notes/layout_note.rb
|
42
42
|
- lib/rails-footnotes/notes/log_note.rb
|
43
43
|
- lib/rails-footnotes/notes/params_note.rb
|
44
|
+
- lib/rails-footnotes/notes/partials_note.rb
|
44
45
|
- lib/rails-footnotes/notes/queries_note.rb
|
45
46
|
- lib/rails-footnotes/notes/routes_note.rb
|
46
47
|
- lib/rails-footnotes/notes/rpm_note.rb
|