rails-footnotes 3.7.9 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -3
- data/.travis.yml +10 -6
- data/CHANGELOG +13 -0
- data/README.rdoc +33 -46
- data/Rakefile +2 -2
- data/gemfiles/Gemfile.rails-3.2.x +5 -0
- data/gemfiles/Gemfile.rails-4.0.x +6 -0
- data/gemfiles/Gemfile.rails-4.1.x +5 -0
- data/gemfiles/Gemfile.rails-edge +5 -0
- data/lib/generators/rails_footnotes/install_generator.rb +1 -4
- data/lib/generators/templates/rails_footnotes.rb +19 -3
- data/lib/rails-footnotes.rb +41 -13
- data/lib/rails-footnotes/extension.rb +22 -3
- data/lib/rails-footnotes/filter.rb +9 -18
- data/lib/rails-footnotes/notes/log_note.rb +18 -25
- data/lib/rails-footnotes/notes/log_note/note_logger.rb +59 -0
- data/lib/rails-footnotes/notes/partials_note.rb +20 -38
- data/lib/rails-footnotes/notes/queries_note.rb +1 -1
- data/lib/rails-footnotes/notes/routes_note.rb +13 -14
- data/lib/rails-footnotes/version.rb +1 -1
- data/rails-footnotes.gemspec +5 -6
- data/spec/abstract_note_spec.rb +5 -0
- data/spec/controllers/footnotes_controller_spec.rb +113 -0
- data/spec/controllers/log_note_controller_spec.rb +45 -0
- data/spec/controllers/partials_note_controller_spec.rb +29 -0
- data/spec/fixtures/html_download.html +5 -0
- data/spec/footnotes_spec.rb +5 -8
- data/spec/notes/assigns_note_spec.rb +1 -1
- data/spec/notes/controller_note_spec.rb +1 -1
- data/spec/notes/files_note_spec.rb +1 -1
- data/spec/notes/javascripts_note_spec.rb +1 -1
- data/spec/notes/stylesheets_note_spec.rb +1 -1
- data/spec/spec_helper.rb +23 -12
- data/spec/views/partials/_foo.html.erb +1 -0
- data/spec/views/partials/index.html.erb +1 -0
- metadata +31 -22
- data/.watchr.example +0 -13
- data/lib/generators/templates/rails_footnotes +0 -3
- data/lib/rails-footnotes/after_filter.rb +0 -10
- data/lib/rails-footnotes/backtracer.rb +0 -32
- data/lib/rails-footnotes/before_filter.rb +0 -9
- data/lib/rails-footnotes/footnotes.rb +0 -7
- data/lib/rails-footnotes/notes/general_note.rb +0 -17
- data/spec/notes/partials_notes_spec.rb +0 -9
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
script: "bundle exec rake spec"
|
2
2
|
rvm:
|
3
|
-
- 1.8.7
|
4
|
-
- 1.9.2
|
5
3
|
- 1.9.3
|
6
|
-
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.1
|
6
|
+
gemfile:
|
7
|
+
- gemfiles/Gemfile.rails-3.2.x
|
8
|
+
- gemfiles/Gemfile.rails-4.0.x
|
9
|
+
- gemfiles/Gemfile.rails-4.1.x
|
10
|
+
- gemfiles/Gemfile.rails-edge
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- gemfile: gemfiles/Gemfile.rails-edge
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== Footnotes v4.0.0
|
2
|
+
* Drop support for ruby 1.8
|
3
|
+
* Drop support for rails < 3.2
|
4
|
+
* Add support for rails 4.x
|
5
|
+
* Rewrite of the log note to make it work on all supported rails versions
|
6
|
+
* Rewrite of the partials note to make it work on all supported rails versions
|
7
|
+
* Rewrite of the loading mechanism, allowing to load conditionally footnotes on a per-request basis if wanted
|
8
|
+
* Deprecate Footnotes.run!
|
9
|
+
* Remove backtrace cleaner monkey patchs
|
10
|
+
* Remove support of .rails_footnotes file
|
11
|
+
* New initializer format with ability to configure footnotes more easily
|
12
|
+
* Remove 'general' note
|
13
|
+
|
1
14
|
== Footnotes v3.7.0
|
2
15
|
* Migrate to Bundler
|
3
16
|
* Support only Rails3
|
data/README.rdoc
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
= Rails Footnotes
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
{<img src="https://travis-ci.org/josevalim/rails-footnotes.png" />}[https://travis-ci.org/josevalim/rails-footnotes]
|
4
|
+
|
5
|
+
Rails footnotes displays footnotes in your application for easy debugging, such as sessions,
|
5
6
|
request parameters, cookies, filter chain, routes, queries, etc.
|
6
7
|
|
7
8
|
Even more, it contains links to open files directly in your editor including
|
@@ -9,46 +10,22 @@ your backtrace lines.
|
|
9
10
|
|
10
11
|
== Installation
|
11
12
|
|
12
|
-
NOTE: Since this branch aims Rails 3 support, if you want to use
|
13
|
+
NOTE: Since this branch aims Rails 3.2+ support, if you want to use footnotes with Rails 2.3 you should use this branch:
|
14
|
+
|
15
|
+
https://github.com/josevalim/rails-footnotes/tree/rails2
|
13
16
|
|
14
|
-
|
17
|
+
Installing Rails Footnotes is very easy.
|
15
18
|
|
16
|
-
|
19
|
+
=== Rails 3.2.x/4.x
|
17
20
|
|
18
|
-
|
21
|
+
gem 'rails-footnotes', '>= 4.0.0', '<5'
|
19
22
|
|
20
|
-
gem 'rails-footnotes', '>= 3.7.5.rc4', :group => :development
|
21
23
|
|
22
24
|
After you install RailsFootnotes and add it to your Gemfile, you need to run the generator:
|
23
25
|
|
24
26
|
rails generate rails_footnotes:install
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
In RAILS_ROOT/config/environments/development.rb (yes, you want it only in development):
|
29
|
-
|
30
|
-
gem "rails-footnotes", '< 3.7.0', :group => :development
|
31
|
-
|
32
|
-
== Configuration
|
33
|
-
|
34
|
-
For version greater than 3.7.0
|
35
|
-
|
36
|
-
If you want to add alternate logic to enable or disable footnotes,
|
37
|
-
add something like this to config/initializers/footnotes.rb:
|
38
|
-
|
39
|
-
if defined?(Footnotes) && Rails.env.development?
|
40
|
-
Footnotes.run! # first of all
|
41
|
-
|
42
|
-
# ... other init code
|
43
|
-
end
|
44
|
-
|
45
|
-
=== Post initialization
|
46
|
-
|
47
|
-
If you want to add alternate logic to config footnotes without commit it to SCM, add your code to .footnotes:
|
48
|
-
|
49
|
-
Footnotes::Filter.notes = []
|
50
|
-
|
51
|
-
this code temporarily disables notes for all controllers
|
28
|
+
This will create an initializer with default config and some examples.
|
52
29
|
|
53
30
|
=== Hooks
|
54
31
|
|
@@ -59,26 +36,28 @@ this code temporarily disables notes for all controllers
|
|
59
36
|
controller.action_name == 'edit' }
|
60
37
|
end
|
61
38
|
|
39
|
+
=== Editors links
|
40
|
+
|
62
41
|
If you are not using Textmate as text editor, MacVim and Sublime Text 2 are also compatible.
|
63
42
|
|
64
43
|
*MacVim*
|
65
44
|
|
66
|
-
In
|
45
|
+
In the rails-footnotes initializer do :
|
67
46
|
|
68
|
-
|
47
|
+
f.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'
|
69
48
|
|
70
49
|
Where you are going to choose a prefix compatible with your text editor. The %s is
|
71
50
|
replaced by the name of the file, the first %d is replaced by the line number and
|
72
51
|
the second %d is replaced by the column.
|
73
52
|
|
74
|
-
Take note that the order in which the file name (%s), line number (%d) and column number (%d) appears is important.
|
53
|
+
Take note that the order in which the file name (%s), line number (%d) and column number (%d) appears is important.
|
75
54
|
We assume that they appear in that order. "foo://line=%d&file=%s" (%d precedes %s) would throw out an error.
|
76
55
|
|
77
56
|
*Sublime* *Text* *2*
|
78
57
|
|
79
|
-
1. Keep the Textmate prefix,
|
58
|
+
1. Keep the Textmate prefix, <tt>f.prefix = 'txmt://open?url=file://%s&line=%d&column=%d'</tt>
|
80
59
|
|
81
|
-
2. Install {subl-
|
60
|
+
2. Install {subl-handler}[https://github.com/asuth/subl-handler]
|
82
61
|
|
83
62
|
3. Open subl-handler. Go to preferences (SublHandler > Preferences), and point "Path to subl" to your installed instance. (EG, /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl). Note: do not escape the whitespaces, subl-handler accounts for those.
|
84
63
|
|
@@ -93,23 +72,23 @@ By default, footnotes are appended at the end of the page with default styleshee
|
|
93
72
|
to change their position, you can define a div with id "footnotes_holder" or define your own stylesheet
|
94
73
|
by turning footnotes stylesheet off:
|
95
74
|
|
96
|
-
|
75
|
+
f.no_style = true
|
97
76
|
|
98
77
|
Another option is to allow multiple notes to be opened at the same time:
|
99
78
|
|
100
|
-
|
79
|
+
f.multiple_notes = true
|
101
80
|
|
102
81
|
Finally, you can control which notes you want to show. The default are:
|
103
82
|
|
104
|
-
|
83
|
+
f.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general]
|
105
84
|
|
106
85
|
== Creating your own notes
|
107
86
|
|
108
|
-
|
87
|
+
Creating your notes to integrate with Footnotes is easy.
|
109
88
|
|
110
89
|
1. Create a Footnotes::Notes::YourExampleNote class
|
111
90
|
2. Implement the necessary methods (check abstract_note.rb file in lib/notes)
|
112
|
-
3. Append your example note in Footnotes::Filter.notes array (usually at the end of your environment file or in
|
91
|
+
3. Append your example note in Footnotes::Filter.notes array (usually at the end of your environment file or in the initializer):
|
113
92
|
|
114
93
|
For example, to create a note that shows info about the user logged in your application you just have to do:
|
115
94
|
|
@@ -144,9 +123,9 @@ For example, to create a note that shows info about the user logged in your appl
|
|
144
123
|
end
|
145
124
|
end
|
146
125
|
|
147
|
-
Then put in your environment:
|
126
|
+
Then put in your environment, add in your initializer:
|
148
127
|
|
149
|
-
|
128
|
+
f.notes += [:current_user]
|
150
129
|
|
151
130
|
== Display of the notes
|
152
131
|
|
@@ -161,12 +140,18 @@ at an appropriate place, your notes will now appear inside div#footnotes_holder
|
|
161
140
|
* Keenan Brock - http://github.com/kbrock
|
162
141
|
* Ivan Storck - http://github.com/ivanoats
|
163
142
|
* Kris Chamber - http://github.com/kristopher
|
143
|
+
* Roman Babenko - http://github.com/romanvbabenko
|
144
|
+
* Adrien Siami - http://github.com/intrepidd
|
164
145
|
|
165
146
|
== Bugs and Feedback
|
166
147
|
|
167
|
-
If you discover any bugs, please
|
148
|
+
If you discover any bugs, please open an issue.
|
168
149
|
If you just want to give some positive feedback or drop a line, that's fine too!
|
169
150
|
|
151
|
+
=== Version 4.x
|
152
|
+
|
153
|
+
Starting from version 4.0, Adren Siami is the maintainer of this plugin.
|
154
|
+
|
170
155
|
=== Version 3.x
|
171
156
|
|
172
157
|
This plugin was maintained until version 3.6 by José Valim
|
@@ -174,6 +159,8 @@ This plugin was maintained until version 3.6 by José Valim
|
|
174
159
|
Copyright (c) 2009 José Valim (jose@plataformatec.com.br)
|
175
160
|
http://blog.plataformatec.com.br
|
176
161
|
|
162
|
+
Until version 4.0, Roman Babenko maintained this plugin.
|
163
|
+
|
177
164
|
=== Version 2.0
|
178
165
|
|
179
166
|
This plugin was created and maintained until version 2.0 by Duane Johnson:
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
require "rspec/core/rake_task"
|
4
|
-
require '
|
4
|
+
require 'rdoc/task'
|
5
5
|
|
6
6
|
desc 'Default: run tests'
|
7
7
|
task :default => :spec
|
@@ -13,7 +13,7 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'Generate documentation for Footnotes.'
|
16
|
-
|
16
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
18
|
rdoc.title = 'Footnotes'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
@@ -3,15 +3,12 @@ module RailsFootnotes
|
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
source_root File.expand_path("../../templates", __FILE__)
|
5
5
|
|
6
|
-
desc "
|
6
|
+
desc "Copy rails-footnotes initializer to your application."
|
7
7
|
|
8
8
|
def copy_initializer
|
9
9
|
template "rails_footnotes.rb", "config/initializers/rails_footnotes.rb"
|
10
10
|
end
|
11
11
|
|
12
|
-
def copy_dotfile
|
13
|
-
template "rails_footnotes", ".rails_footnotes"
|
14
|
-
end
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
@@ -1,5 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Footnotes.setup do |f|
|
2
|
+
# Wether or not to enable footnotes
|
3
|
+
f.enabled = Rails.env.development?
|
4
|
+
# You can also use a lambda / proc to conditionally toggle footnotes
|
5
|
+
# Example :
|
6
|
+
# f.enabled = -> { User.current.admin? }
|
7
|
+
# Beware of thread-safety though, Footnotes.enabled is NOT thread safe
|
8
|
+
# and should not be modified anywhere else.
|
3
9
|
|
4
|
-
#
|
10
|
+
# Only toggle some notes :
|
11
|
+
# f.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general]
|
12
|
+
|
13
|
+
# Change the prefix :
|
14
|
+
# f.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'
|
15
|
+
|
16
|
+
# Disable style :
|
17
|
+
# f.no_style = true
|
18
|
+
|
19
|
+
# Allow to open multiple notes :
|
20
|
+
# f.multiple_notes = true
|
5
21
|
end
|
data/lib/rails-footnotes.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'rails-footnotes/abstract_note'
|
4
|
+
require 'rails-footnotes/each_with_rescue'
|
5
|
+
require 'rails-footnotes/filter'
|
6
|
+
require 'rails-footnotes/notes/all'
|
7
|
+
require 'rails-footnotes/extension'
|
8
|
+
require 'active_support/deprecation'
|
9
|
+
|
1
10
|
module Footnotes
|
2
11
|
mattr_accessor :before_hooks
|
3
12
|
@@before_hooks = []
|
@@ -5,6 +14,28 @@ module Footnotes
|
|
5
14
|
mattr_accessor :after_hooks
|
6
15
|
@@after_hooks = []
|
7
16
|
|
17
|
+
mattr_accessor :enabled
|
18
|
+
@@enabled = false
|
19
|
+
|
20
|
+
class << self
|
21
|
+
delegate :notes, :to => Filter
|
22
|
+
delegate :notes=, :to => Filter
|
23
|
+
|
24
|
+
delegate :prefix, :to => Filter
|
25
|
+
delegate :prefix=, :to => Filter
|
26
|
+
|
27
|
+
delegate :no_style, :to => Filter
|
28
|
+
delegate :no_style=, :to => Filter
|
29
|
+
|
30
|
+
delegate :multiple_notes, :to => Filter
|
31
|
+
delegate :multiple_notes=, :to => Filter
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.run!
|
35
|
+
ActiveSupport::Deprecation.warn "run! is deprecated and will be removed from future releases, use Footnotes.setup or Footnotes.enabled instead.", caller
|
36
|
+
Footnotes.enabled = true
|
37
|
+
end
|
38
|
+
|
8
39
|
def self.before(&block)
|
9
40
|
@@before_hooks << block
|
10
41
|
end
|
@@ -13,22 +44,19 @@ module Footnotes
|
|
13
44
|
@@after_hooks << block
|
14
45
|
end
|
15
46
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require 'rails-footnotes/notes/all'
|
23
|
-
|
24
|
-
ActionController::Base.send(:include, RailsFootnotesExtension)
|
25
|
-
|
26
|
-
load Rails.root.join('.rails_footnotes') if Rails.root.join('.rails_footnotes').exist?
|
27
|
-
#TODO DEPRECATED
|
28
|
-
load Rails.root.join('.footnotes') if Rails.root.join('.footnotes').exist?
|
47
|
+
def self.enabled?
|
48
|
+
if @@enabled.is_a? Proc
|
49
|
+
@@enabled.call
|
50
|
+
else
|
51
|
+
!!@@enabled
|
52
|
+
end
|
29
53
|
end
|
30
54
|
|
31
55
|
def self.setup
|
32
56
|
yield self
|
33
57
|
end
|
34
58
|
end
|
59
|
+
|
60
|
+
ActionController::Base.send(:include, Footnotes::RailsFootnotesExtension)
|
61
|
+
|
62
|
+
load Rails.root.join('.rails_footnotes') if Rails.root && Rails.root.join('.rails_footnotes').exist?
|
@@ -1,8 +1,27 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
1
3
|
module Footnotes
|
2
4
|
module RailsFootnotesExtension
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
prepend_before_filter :rails_footnotes_before_filter
|
10
|
+
after_filter :rails_footnotes_after_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
def rails_footnotes_before_filter
|
14
|
+
if Footnotes.enabled?
|
15
|
+
Footnotes::Filter.start!(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def rails_footnotes_after_filter
|
20
|
+
if Footnotes.enabled?
|
21
|
+
filter = Footnotes::Filter.new(self)
|
22
|
+
filter.add_footnotes!
|
23
|
+
filter.close!(self)
|
24
|
+
end
|
6
25
|
end
|
7
26
|
end
|
8
27
|
end
|
@@ -10,7 +10,7 @@ module Footnotes
|
|
10
10
|
# Edit notes
|
11
11
|
@@notes = [ :controller, :view, :layout, :partials, :stylesheets, :javascripts ]
|
12
12
|
# Show notes
|
13
|
-
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log
|
13
|
+
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log]
|
14
14
|
|
15
15
|
# :no_style => If you don't want the style to be appended to your pages
|
16
16
|
# :notes => Class variable that holds the notes to be processed
|
@@ -78,7 +78,7 @@ module Footnotes
|
|
78
78
|
protected
|
79
79
|
def valid?
|
80
80
|
@body.is_a?(String) && performed_render? && valid_format? && valid_content_type? &&
|
81
|
-
!component_request? && !xhr? && !footnotes_disabled?
|
81
|
+
!component_request? && !xhr? && !footnotes_disabled? && !attached_file?
|
82
82
|
end
|
83
83
|
|
84
84
|
def add_footnotes_without_validation!
|
@@ -90,7 +90,7 @@ module Footnotes
|
|
90
90
|
def initialize_notes!
|
91
91
|
each_with_rescue(@@klasses) do |klass|
|
92
92
|
note = klass.new(@controller)
|
93
|
-
@notes << note if note.
|
93
|
+
@notes << note if note.valid?
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -102,24 +102,11 @@ module Footnotes
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def performed_render?
|
105
|
-
@controller.
|
106
|
-
(@controller.respond_to?(:performed?) && @controller.performed?) # rails3, will break on redirect??
|
105
|
+
@controller.respond_to?(:performed?) && @controller.performed?
|
107
106
|
end
|
108
107
|
|
109
108
|
def valid_format?
|
110
|
-
|
111
|
-
[:html,:rhtml,:xhtml,:rxhtml].include?(@template.send(template_format_method.to_sym).to_sym)
|
112
|
-
else # Rails 3
|
113
|
-
@controller.response.content_type == 'text/html'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def template_format_method
|
118
|
-
if @template.respond_to?(:template_format)
|
119
|
-
return 'template_format'
|
120
|
-
else
|
121
|
-
return 'format'
|
122
|
-
end
|
109
|
+
['text/html', nil].include? @controller.response.content_type
|
123
110
|
end
|
124
111
|
|
125
112
|
def valid_content_type?
|
@@ -139,6 +126,10 @@ module Footnotes
|
|
139
126
|
@controller.params[:footnotes] == "false"
|
140
127
|
end
|
141
128
|
|
129
|
+
def attached_file?
|
130
|
+
!!(@controller.headers['Content-Disposition'] =~ /attachment/)
|
131
|
+
end
|
132
|
+
|
142
133
|
#
|
143
134
|
# Insertion methods
|
144
135
|
#
|