public
Description: Every Rails page has footnotes that link give request information and link back to your source via TextMate [extracted from Rails TextMate bundle project]
Clone URL: git://github.com/drnic/rails-footnotes.git
Added ComponentsNote (it shows renderized components links)
josevalim (author)
Wed Jun 11 14:51:36 -0700 2008
commit  ab4edda689c8b75ad3ce1f8b1f6f58211c168a11
tree    2fa3908826e3f04c1528418f70ccf693bc21f6d8
parent  24042f4a2cb9b3d6e55a4ff2a0bf8e9d65cfedfd
...
3
4
5
6
 
7
8
 
9
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
29
30
31
32
33
 
 
34
35
36
37
38
 
39
40
41
...
47
48
49
50
51
 
 
52
53
54
...
74
75
76
 
 
 
 
77
78
79
...
144
145
146
147
 
148
149
150
...
3
4
5
 
6
7
 
8
9
10
11
 
 
 
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
44
45
46
 
 
47
48
49
50
51
52
 
53
54
55
56
...
62
63
64
 
 
65
66
67
68
69
...
89
90
91
92
93
94
95
96
97
98
...
163
164
165
 
166
167
168
169
0
@@ -3,16 +3,31 @@ module Footnotes
0
     @@no_style = false
0
     @@multiple_notes = false
0
     # Edit notes
0
- @@notes = [ :controller, :view, :layout, :stylesheets, :javascripts ]
0
+ @@notes = [ :components, :controller, :view, :layout, :stylesheets, :javascripts ]
0
     # Show notes
0
- @@notes += [:session, :cookies, :params, :filters, :routes, :queries, :log, :general]
0
+ @@notes += [ :session, :cookies, :params, :filters, :routes, :queries, :log, :general ]
0
 
0
     cattr_accessor :no_style, :notes, :prefix, :multiple_notes
0
 
0
- def self.filter(controller)
0
- filter = Footnotes::Filter.new(controller)
0
- filter.add_footnotes!
0
- filter.reset!
0
+ class << self
0
+ def before(controller)
0
+ Footnotes::Filter.start!
0
+ end
0
+
0
+ def after(controller)
0
+ filter = Footnotes::Filter.new(controller)
0
+ filter.add_footnotes!
0
+ filter.close!
0
+ end
0
+
0
+ def start!
0
+ @@notes.flatten.each do |note|
0
+ klass = eval("Footnotes::Notes::#{note.to_s.camelize}Note") if note.is_a?(Symbol) || note.is_a?(String)
0
+ klass.start! if klass.respond_to?(:start!)
0
+ end
0
+ rescue Exception => e
0
+ log_error("Footnotes Exception", e)
0
+ end
0
     end
0
 
0
     def initialize(controller)
0
@@ -29,13 +44,13 @@ module Footnotes
0
       log_error("Footnotes Exception", e)
0
     end
0
 
0
- def reset!
0
- @notes.map(&:reset!)
0
+ def close!
0
+ @notes.map{|note| note.class.close!}
0
     end
0
 
0
     protected
0
     def valid?
0
- performed_render? && first_render? && valid_format? && valid_content_type? && @body.is_a?(String) && !xhr?
0
+ performed_render? && first_render? && valid_format? && valid_content_type? && @body.is_a?(String) && !component_request? && !xhr?
0
     end
0
 
0
     def add_footnotes_without_validation!
0
@@ -47,8 +62,8 @@ module Footnotes
0
     def initialize_notes!
0
       @@notes.flatten.each do |note|
0
         begin
0
- instance_note = eval("Footnotes::Notes::#{note.to_s.camelize}Note").new(@controller)
0
- @notes << instance_note if instance_note.valid?
0
+ note = eval("Footnotes::Notes::#{note.to_s.camelize}Note").new(@controller) if note.is_a?(Symbol) || note.is_a?(String)
0
+ @notes << note if note.respond_to?(:valid?) && note.valid?
0
         rescue Exception => e
0
           # Discard note if it has a problem
0
           log_error("Footnotes #{note.to_s.camelize}Note Exception", e)
0
@@ -74,6 +89,10 @@ module Footnotes
0
       (c.nil? || c =~ /html/)
0
     end
0
 
0
+ def component_request?
0
+ @controller.instance_variable_get('@parent_controller')
0
+ end
0
+
0
     def xhr?
0
       @controller.request.xhr?
0
     end
0
@@ -144,7 +163,7 @@ module Footnotes
0
       html = ''
0
       order.uniq!
0
       order.each do |row|
0
- html << "#{row.to_s.capitalize}: #{links[row].join(" | \n")}<br />"
0
+ html << "#{row.is_a?(String) ? row : row.to_s.camelize}: #{links[row].join(" | \n")}<br />"
0
       end
0
       html
0
     end
...
9
10
11
 
12
13
14
...
9
10
11
12
13
14
15
0
@@ -9,5 +9,6 @@ end
0
 # application. Then you can cherrypick in which actions it will appear.
0
 #
0
 class ActionController::Base
0
+ prepend_before_filter Footnotes::Filter
0
   after_filter Footnotes::Filter
0
 end
0
\ No newline at end of file
...
16
17
18
 
 
 
 
 
 
 
 
 
 
 
 
19
20
 
21
22
23
...
76
77
78
79
80
81
82
83
84
85
86
...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
32
33
34
35
...
88
89
90
 
 
 
 
 
91
92
93
0
@@ -16,8 +16,20 @@ module Footnotes
0
         def included?
0
           Footnotes::Filter.notes.include?(self.to_sym)
0
         end
0
+
0
+ # Action to be called to start the Note.
0
+ # This is applied as a before_filter.
0
+ #
0
+ def start!
0
+ end
0
+
0
+ # Action to be called after the Note was used.
0
+ # This is applied as an after_filter.
0
+ #
0
+ def close!
0
+ end
0
       end
0
-
0
+
0
       # Initialize notes.
0
       # Always receives a controller.
0
       #
0
@@ -76,11 +88,6 @@ module Footnotes
0
       def javascript
0
       end
0
 
0
- # Action to be called after the Note was used.
0
- #
0
- def reset!
0
- end
0
-
0
       # Specifies when should create a note for it.
0
       # By default, if title exists, it's valid.
0
       #
...
6
7
8
 
 
 
 
9
10
11
...
19
20
21
22
 
23
24
25
...
28
29
30
31
 
32
33
34
35
36
37
38
39
40
41
...
6
7
8
9
10
11
12
13
14
15
...
23
24
25
 
26
27
28
29
...
32
33
34
 
35
36
37
38
 
 
 
 
39
40
41
0
@@ -6,6 +6,10 @@ module Footnotes
0
       @@sql = []
0
       cattr_accessor :sql
0
 
0
+ def self.start!
0
+ @@sql = []
0
+ end
0
+
0
       def self.to_sym
0
         :queries
0
       end
0
@@ -19,7 +23,7 @@ module Footnotes
0
       end
0
 
0
       def stylesheet
0
- '#queries_debug_info thead, #queries_debug_info tbody {text-align: center; color:#FF0000;}'
0
+ '.queries_debug_table thead, .queries_debug_table tbody {text-align: center; color:#FF0000;}'
0
       end
0
 
0
       def content
0
@@ -28,14 +32,10 @@ module Footnotes
0
           html << "<b>#{item[0].to_s.upcase}</b>\n"
0
           html << "#{item[1] || 'SQL'} (#{sprintf('%f',item[2])}s)\n"
0
           html << "#{item[3].gsub(/(\s)+/,' ').gsub('`','')}\n"
0
- html << (item[4] ? mount_table(item[4]) : "\n")
0
+ html << (item[4] ? mount_table(item[4], :class => 'queries_debug_table') : "\n")
0
         end
0
         "<pre>#{html}</pre>"
0
       end
0
-
0
- def reset!
0
- @@sql = []
0
- end
0
     end
0
   end
0
 
...
98
99
100
101
102
 
 
103
104
105
...
98
99
100
 
 
101
102
103
104
105
0
@@ -98,8 +98,8 @@ class FootnotesTest < Test::Unit::TestCase
0
 
0
   def test_notes_are_reset
0
     footnotes_perform!
0
- @footnotes.instance_variable_get('@notes').first.expects(:reset!)
0
- @footnotes.send(:reset!)
0
+ @footnotes.instance_variable_get('@notes').first.class.expects(:close!)
0
+ @footnotes.send(:close!)
0
   end
0
 
0
   def test_links_helper
...
6
7
8
 
 
 
 
 
9
10
11
...
75
76
77
78
 
79
80
81
 
82
83
84
85
86
87
 
88
89
90
 
91
92
93
...
96
97
98
99
 
100
101
102
...
6
7
8
9
10
11
12
13
14
15
16
...
80
81
82
 
83
84
85
 
86
87
88
89
90
91
 
92
93
94
 
95
96
97
98
...
101
102
103
 
104
105
106
107
0
@@ -6,6 +6,11 @@ class AbstractNoteTest < Test::Unit::TestCase
0
     Footnotes::Filter.notes = [:abstract]
0
   end
0
 
0
+ def test_respond_to_start_and_close
0
+ assert_respond_to Footnotes::Notes::AbstractNote, :start!
0
+ assert_respond_to Footnotes::Notes::AbstractNote, :close!
0
+ end
0
+
0
   def test_respond_to_sym
0
     assert_equal :abstract, Footnotes::Notes::AbstractNote.to_sym
0
     assert_equal :abstract, @note.to_sym
0
@@ -75,19 +80,19 @@ class AbstractNoteTest < Test::Unit::TestCase
0
   
0
   def test_footnotes_mount_table
0
     assert_equal '', @note.send(:mount_table,[])
0
- assert_equal '', @note.send(:mount_table,[['h1','h2','h3']])
0
+ assert_equal '', @note.send(:mount_table,[['h1','h2','h3']], :class => 'table')
0
 
0
     tab = <<-TABLE
0
- <table>
0
+ <table class="table">
0
             <thead><tr><th>H1</th></tr></thead>
0
             <tbody><tr><td>r1c1</td></tr></tbody>
0
           </table>
0
           TABLE
0
 
0
- assert_equal tab, @note.send(:mount_table,[['h1'],['r1c1']])
0
+ assert_equal tab, @note.send(:mount_table,[['h1'],['r1c1']], :class => 'table')
0
 
0
     tab = <<-TABLE
0
- <table>
0
+ <table >
0
             <thead><tr><th>H1</th><th>H2</th><th>H3</th></tr></thead>
0
             <tbody><tr><td>r1c1</td><td>r1c2</td><td>r1c3</td></tr></tbody>
0
           </table>
0
@@ -96,7 +101,7 @@ class AbstractNoteTest < Test::Unit::TestCase
0
     assert_equal tab, @note.send(:mount_table,[['h1','h2','h3'],['r1c1','r1c2','r1c3']])
0
 
0
     tab = <<-TABLE
0
- <table>
0
+ <table >
0
             <thead><tr><th>H1</th><th>H2</th><th>H3</th></tr></thead>
0
             <tbody><tr><td>r1c1</td><td>r1c2</td><td>r1c3</td></tr><tr><td>r2c1</td><td>r2c2</td><td>r2c3</td></tr></tbody>
0
           </table>

Comments

    No one has commented yet.