rails-footnotes 5.0.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/ci.yml +2 -8
- data/.github/workflows/merge-dependabot.yml +33 -0
- data/.gitignore +3 -8
- data/.ruby-version +1 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +193 -124
- data/{README.rdoc → README.md} +65 -59
- data/lib/generators/templates/rails_footnotes.rb +3 -0
- data/lib/rails-footnotes/filter.rb +42 -29
- data/lib/rails-footnotes/notes/assigns_note.rb +23 -20
- data/lib/rails-footnotes/notes/controller_note.rb +2 -2
- data/lib/rails-footnotes/notes/log_note/note_logger.rb +0 -38
- data/lib/rails-footnotes/notes/log_note.rb +8 -5
- data/lib/rails-footnotes/notes/partials_note.rb +2 -2
- data/lib/rails-footnotes/notes/queries_note.rb +4 -6
- data/lib/rails-footnotes/notes/view_note.rb +5 -5
- data/lib/rails-footnotes/version.rb +1 -1
- data/lib/rails-footnotes.rb +18 -16
- data/rails-footnotes.gemspec +3 -5
- data/renovate.json +5 -0
- data/spec/footnotes_spec.rb +173 -140
- data/spec/notes/assigns_note_spec.rb +27 -9
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +22 -0
- metadata +13 -8
- data/lib/rails6-footnotes.rb +0 -1
data/{README.rdoc → README.md}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# Rails 7 Footnotes
|
2
2
|
|
3
3
|
Rails footnotes displays footnotes in your application for easy debugging, such as sessions,
|
4
4
|
request parameters, cookies, filter chain, routes, queries, etc.
|
@@ -6,34 +6,37 @@ request parameters, cookies, filter chain, routes, queries, etc.
|
|
6
6
|
Even more, it contains links to open files directly in your editor including
|
7
7
|
your backtrace lines.
|
8
8
|
|
9
|
-
|
9
|
+
### Installation
|
10
10
|
|
11
|
-
Add to your `Gemfile
|
11
|
+
1. Add to your `Gemfile` with `bundle add rails-footnotes`
|
12
|
+
2. Run `bundle install`
|
13
|
+
3. Generate the initializer with `bin/rails generate rails_footnotes:install`
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
Run `bundle install`, then the generator:
|
15
|
+
This will create an initializer with default config and some examples.
|
16
16
|
|
17
|
-
|
17
|
+
### Hooks
|
18
18
|
|
19
|
-
|
19
|
+
You can run blocks before and after footnotes are evaluated.
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
Footnotes.setup do |config|
|
23
|
+
config.before do |controller, filter|
|
24
|
+
filter.notes = (controller.class.name =~ /Message/ && controller.action_name == 'index' ? [:assigns] : [])
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
config.before do |controller, filter|
|
28
|
+
filter.notes |= [:params] if controller.class.name =~ /Profile/ && controller.action_name == 'edit'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
29
32
|
|
30
|
-
|
33
|
+
### Editor links
|
31
34
|
|
32
|
-
|
35
|
+
By default, files are linked to open in TextMate, but you can use any editor with a URL scheme. Here are some examples for other editors:
|
33
36
|
|
34
|
-
|
37
|
+
**MacVim**
|
35
38
|
|
36
|
-
In
|
39
|
+
In `config/initializers/rails-footnotes.rb` do:
|
37
40
|
|
38
41
|
f.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'
|
39
42
|
|
@@ -44,26 +47,26 @@ the second %d is replaced by the column number.
|
|
44
47
|
Take note that the order in which the file name (%s), line number (%d) and column number (%d) appears is important.
|
45
48
|
We assume that they appear in that order. "foo://line=%d&file=%s" (%d precedes %s) would throw out an error.
|
46
49
|
|
47
|
-
|
50
|
+
**Sublime Text 3**
|
48
51
|
|
49
|
-
Install
|
52
|
+
Install [subl](https://github.com/dhoulb/subl), then use:
|
50
53
|
|
51
54
|
f.prefix = 'subl://open?url=file://%s&line=%d&column=%d'
|
52
55
|
|
53
|
-
|
56
|
+
**Use with Docker, Vagrant, or other virtual machines**
|
54
57
|
|
55
|
-
If you're running your app in
|
58
|
+
If you're running your app in a container or VM, you'll find that the edit links won't work because the paths point to the VM directory and not your native directory. To solve this, you can use a lambda for the prefix and modify the pathname accordingly.
|
56
59
|
|
57
60
|
For example,
|
58
61
|
|
59
62
|
f.prefix = ->(*args) do
|
60
|
-
filename = args[0].sub '/
|
63
|
+
filename = args[0].sub '/docker', '/Users/name/projects/myproject'
|
61
64
|
"subl://open?url=file://#{filename}&line=#{args[1]}&column=#{args[2]}"
|
62
65
|
end
|
63
66
|
|
64
|
-
replaces the
|
67
|
+
replaces the VM directory /docker with the macOS directory containing the source code.
|
65
68
|
|
66
|
-
|
69
|
+
**Footnotes Display Options**
|
67
70
|
|
68
71
|
By default, footnotes are appended at the end of the page with default stylesheet. If you want
|
69
72
|
to change their position, you can define a div with id "footnotes_holder" or define your own stylesheet
|
@@ -90,7 +93,7 @@ Finally, you can control which notes you want to show. The default are:
|
|
90
93
|
|
91
94
|
Setting <tt>f.notes = []</tt> will show none of the available notes, although the supporting CSS and JavaScript will still be included. To completely disable all rails-footnotes content on a page, include <tt>params[:footnotes] = 'false'</tt> in the request.
|
92
95
|
|
93
|
-
|
96
|
+
### Creating your own notes
|
94
97
|
|
95
98
|
Creating your notes to integrate with Footnotes is easy.
|
96
99
|
|
@@ -100,49 +103,52 @@ Creating your notes to integrate with Footnotes is easy.
|
|
100
103
|
|
101
104
|
For example, to create a note that shows info about the user logged in your application you just have to do:
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
106
|
+
module Footnotes
|
107
|
+
module Notes
|
108
|
+
class CurrentUserNote < AbstractNote
|
109
|
+
# This method always receives a controller
|
110
|
+
#
|
111
|
+
def initialize(controller)
|
112
|
+
@current_user = controller.instance_variable_get("@current_user")
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns the title that represents this note.
|
116
|
+
#
|
117
|
+
def title
|
118
|
+
"Current user: #{@current_user.name}"
|
119
|
+
end
|
120
|
+
|
121
|
+
# This Note is only valid if we actually found an user
|
122
|
+
# If it's not valid, it won't be displayed
|
123
|
+
#
|
124
|
+
def valid?
|
125
|
+
@current_user
|
126
|
+
end
|
127
|
+
|
128
|
+
# The fieldset content
|
129
|
+
#
|
130
|
+
def content
|
131
|
+
escape(@current_user.inspect)
|
132
|
+
end
|
129
133
|
end
|
130
134
|
end
|
131
135
|
end
|
132
|
-
end
|
133
136
|
|
134
137
|
Then put in your environment, add in your initializer:
|
135
138
|
|
136
|
-
|
139
|
+
f.notes += [:current_user]
|
137
140
|
|
138
|
-
|
141
|
+
### Footnote position
|
139
142
|
|
140
|
-
By default the notes will be showed at the bottom of your page (appended just before
|
143
|
+
By default the notes will be showed at the bottom of your page (appended just before `</body>`).
|
141
144
|
If you'd like the footnote, to be at a different place (perhaps for aesthetical reasons) you can edit one of your views and add:
|
142
|
-
|
145
|
+
|
146
|
+
<div id="footnotes_holder"></div>
|
147
|
+
|
143
148
|
at an appropriate place, your notes will now appear inside div#footnotes_holder
|
144
149
|
|
145
|
-
|
150
|
+
### Bugs and Feedback
|
146
151
|
|
147
152
|
If you discover any bugs, please open an issue.
|
148
153
|
If you just want to give some positive feedback or drop a line, that's fine too!
|
154
|
+
|
@@ -21,6 +21,9 @@ Footnotes.setup do |f|
|
|
21
21
|
# Change font size :
|
22
22
|
# f.font_size = '11px'
|
23
23
|
|
24
|
+
# Change default limit :
|
25
|
+
# f.default_limit = 25
|
26
|
+
|
24
27
|
# Allow to open multiple notes :
|
25
28
|
# f.multiple_notes = true
|
26
29
|
end if defined?(Footnotes) && Footnotes.respond_to?(:setup)
|
@@ -1,26 +1,37 @@
|
|
1
1
|
module Footnotes
|
2
2
|
class Filter
|
3
|
-
@@no_style = false
|
4
|
-
@@multiple_notes = false
|
5
3
|
@@klasses = []
|
6
|
-
@@lock_top_right = false
|
7
|
-
@@font_size = '11px'
|
8
|
-
|
9
|
-
# Default link prefix is textmate
|
10
|
-
@@prefix = 'txmt://open?url=file://%s&line=%d&column=%d'
|
11
|
-
|
12
|
-
# Edit notes
|
13
|
-
@@notes = [ :controller, :view, :layout, :partials, :stylesheets, :javascripts ]
|
14
|
-
# Show notes
|
15
|
-
@@notes += [ :assigns, :session, :cookies, :params, :filters, :routes, :env, :queries, :log]
|
16
4
|
|
5
|
+
# :default_limit => Default limit for ActiveRecord:Relation in assigns note
|
6
|
+
# :font_size => CSS font-size property
|
7
|
+
# :lock_top_right => Lock a btn to toggle notes to the top right of the browser
|
8
|
+
# :multiple_notes => Set to true if you want to open several notes at the same time
|
17
9
|
# :no_style => If you don't want the style to be appended to your pages
|
18
|
-
# :notes => Class variable that holds the notes to be processed
|
19
10
|
# :prefix => Prefix appended to FootnotesLinks
|
20
|
-
# :
|
21
|
-
|
22
|
-
|
23
|
-
|
11
|
+
# :notes => Class variable that holds the notes to be processed
|
12
|
+
thread_cattr_accessor :default_limit, default: 25
|
13
|
+
thread_cattr_accessor :font_size, default: '11px'
|
14
|
+
thread_cattr_accessor :lock_top_right, default: false
|
15
|
+
thread_cattr_accessor :multiple_notes, default: false
|
16
|
+
thread_cattr_accessor :no_style, default: false
|
17
|
+
thread_cattr_accessor :prefix, default: 'txmt://open?url=file://%s&line=%d&column=%d'
|
18
|
+
thread_cattr_accessor :notes, default: [
|
19
|
+
:assigns,
|
20
|
+
:controller,
|
21
|
+
:cookies,
|
22
|
+
:env,
|
23
|
+
:filters,
|
24
|
+
:javascripts,
|
25
|
+
:layout,
|
26
|
+
:log,
|
27
|
+
:params,
|
28
|
+
:partials,
|
29
|
+
:queries,
|
30
|
+
:routes,
|
31
|
+
:session,
|
32
|
+
:stylesheets,
|
33
|
+
:view
|
34
|
+
]
|
24
35
|
|
25
36
|
class << self
|
26
37
|
include Footnotes::EachWithRescue
|
@@ -33,7 +44,7 @@ module Footnotes
|
|
33
44
|
self.each_with_rescue(Footnotes.before_hooks) {|hook| hook.call(controller, self)}
|
34
45
|
|
35
46
|
@@klasses = []
|
36
|
-
self.each_with_rescue(
|
47
|
+
self.each_with_rescue(notes.flatten) do |note|
|
37
48
|
klass = "Footnotes::Notes::#{note.to_s.camelize}Note".constantize
|
38
49
|
klass.start!(controller) if klass.respond_to?(:start!)
|
39
50
|
@@klasses << klass
|
@@ -42,17 +53,17 @@ module Footnotes
|
|
42
53
|
|
43
54
|
# If none argument is sent, simply return the prefix.
|
44
55
|
# Otherwise, replace the args in the prefix.
|
45
|
-
|
56
|
+
alias_method :read_prefix, :prefix
|
46
57
|
def prefix(*args)
|
47
58
|
if args.empty?
|
48
|
-
|
59
|
+
read_prefix
|
49
60
|
else
|
50
61
|
args.map! { |arg| arg.to_s.split("/").map{|s| ERB::Util.url_encode(s) }.join("/") }
|
51
62
|
|
52
|
-
if
|
53
|
-
|
63
|
+
if read_prefix.respond_to? :call
|
64
|
+
read_prefix.call(*args)
|
54
65
|
else
|
55
|
-
format(
|
66
|
+
format(read_prefix, *args)
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
@@ -65,7 +76,9 @@ module Footnotes
|
|
65
76
|
@notes = []
|
66
77
|
|
67
78
|
revert_pos(controller.response_body) do
|
68
|
-
|
79
|
+
if controller.response.stream.respond_to?(:body)
|
80
|
+
@body = controller.response.body
|
81
|
+
end
|
69
82
|
end
|
70
83
|
end
|
71
84
|
|
@@ -93,7 +106,7 @@ module Footnotes
|
|
93
106
|
|
94
107
|
def add_footnotes_without_validation!
|
95
108
|
initialize_notes!
|
96
|
-
insert_styles unless
|
109
|
+
insert_styles unless no_style
|
97
110
|
insert_footnotes
|
98
111
|
end
|
99
112
|
|
@@ -147,7 +160,7 @@ module Footnotes
|
|
147
160
|
|
148
161
|
def insert_styles
|
149
162
|
#TODO More customizable(reset.css, from file etc.)
|
150
|
-
if
|
163
|
+
if lock_top_right
|
151
164
|
extra_styles = <<-STYLES
|
152
165
|
#footnotes_debug {position: fixed; top: 0px; right: 0px; width: 100%; z-index: 10000; margin-top: 0;}
|
153
166
|
#footnotes_debug #toggle_footnotes {position: absolute; right: 0; top: 0; background: #fff; border: 1px solid #ccc; color: #9b1b1b; font-size: 20px; text-align: center; padding: 8px; opacity: 0.9;}
|
@@ -163,7 +176,7 @@ module Footnotes
|
|
163
176
|
insert_text :before, /<\/head>/i, <<-HTML
|
164
177
|
<!-- Footnotes Style -->
|
165
178
|
<style type="text/css">
|
166
|
-
#footnotes_debug {font-size: #{
|
179
|
+
#footnotes_debug {font-size: #{font_size}; font-family: Consolas, monaco, monospace; font-weight: normal; margin: 2em 0 1em 0; text-align: center; color: #444; line-height: 16px; background: #fff;}
|
167
180
|
#footnotes_debug th, #footnotes_debug td {color: #444; line-height: 18px;}
|
168
181
|
#footnotes_debug a {color: #9b1b1b; font-weight: inherit; text-decoration: none; line-height: 18px;}
|
169
182
|
#footnotes_debug table {text-align: left; width: 100%;}
|
@@ -188,7 +201,7 @@ module Footnotes
|
|
188
201
|
# Fieldsets method should be called first
|
189
202
|
content = fieldsets
|
190
203
|
element_style = ''
|
191
|
-
if
|
204
|
+
if lock_top_right
|
192
205
|
element_style = 'style="display: none;"'
|
193
206
|
end
|
194
207
|
footnotes_html = <<-HTML
|
@@ -204,7 +217,7 @@ module Footnotes
|
|
204
217
|
var Footnotes = function() {
|
205
218
|
|
206
219
|
function hideAll(){
|
207
|
-
#{close unless
|
220
|
+
#{close unless multiple_notes}
|
208
221
|
}
|
209
222
|
|
210
223
|
function hideAllAndToggle(id) {
|
@@ -1,24 +1,24 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
1
3
|
module Footnotes
|
2
4
|
module Notes
|
3
5
|
class AssignsNote < AbstractNote
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@@ignored_assigns_pattern = /^@_/
|
21
|
-
cattr_accessor :ignored_assigns_pattern, :instance_writer => false
|
6
|
+
thread_cattr_accessor :ignored_assigns, instance_writer: false, default: [
|
7
|
+
:@real_format,
|
8
|
+
:@before_filter_chain_aborted,
|
9
|
+
:@performed_redirect,
|
10
|
+
:@performed_render,
|
11
|
+
:@_params,
|
12
|
+
:@_response,
|
13
|
+
:@url,
|
14
|
+
:@template,
|
15
|
+
:@_request,
|
16
|
+
:@db_rt_before_render,
|
17
|
+
:@db_rt_after_render,
|
18
|
+
:@view_runtime,
|
19
|
+
:@marked_for_same_origin_verification
|
20
|
+
]
|
21
|
+
thread_cattr_accessor :ignored_assigns_pattern, instance_writer: false, default: /^@_/
|
22
22
|
|
23
23
|
def initialize(controller)
|
24
24
|
@controller = controller
|
@@ -40,8 +40,11 @@ module Footnotes
|
|
40
40
|
def to_table
|
41
41
|
table = assigns.inject([]) do |rr, var|
|
42
42
|
class_name = assigned_value(var).class.name
|
43
|
-
|
44
|
-
|
43
|
+
var_value = assigned_value(var)
|
44
|
+
if var_value.is_a?(ActiveRecord::Relation) && var_value.limit_value.nil?
|
45
|
+
var_value = var_value.limit(Footnotes::Filter.default_limit)
|
46
|
+
end
|
47
|
+
rr << ["<strong>#{var.to_s}</strong>" + "<br /><em>#{class_name}</em>", escape(var_value.inspect)]
|
45
48
|
end
|
46
49
|
|
47
50
|
table.unshift(['Name', 'Value'])
|
@@ -14,7 +14,7 @@ module Footnotes
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def valid?
|
17
|
-
prefix? && controller_filename && File.
|
17
|
+
prefix? && controller_filename && File.exist?(controller_filename)
|
18
18
|
end
|
19
19
|
|
20
20
|
protected
|
@@ -23,7 +23,7 @@ module Footnotes
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def controller_filename
|
26
|
-
@controller_filename ||= Gem.find_files(controller_path).first
|
26
|
+
@controller_filename ||= Gem.find_files(controller_path).first
|
27
27
|
end
|
28
28
|
|
29
29
|
def controller_text
|
@@ -15,44 +15,6 @@ module Footnotes
|
|
15
15
|
formatter = @formatter || Logger::Formatter.new
|
16
16
|
@logs << formatter.call(format_severity(severity), Time.now, message, progname)
|
17
17
|
end
|
18
|
-
|
19
|
-
## Backport from rails 4 for handling logging broadcast, should be removed when rails 3 is deprecated :
|
20
|
-
|
21
|
-
# Broadcasts logs to multiple loggers.
|
22
|
-
def self.broadcast(logger) # :nodoc:
|
23
|
-
Module.new do
|
24
|
-
define_method(:add) do |*args, &block|
|
25
|
-
logger.add(*args, &block)
|
26
|
-
super(*args, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
define_method(:<<) do |x|
|
30
|
-
logger << x
|
31
|
-
super(x)
|
32
|
-
end
|
33
|
-
|
34
|
-
define_method(:close) do
|
35
|
-
logger.close
|
36
|
-
super()
|
37
|
-
end
|
38
|
-
|
39
|
-
define_method(:progname=) do |name|
|
40
|
-
logger.progname = name
|
41
|
-
super(name)
|
42
|
-
end
|
43
|
-
|
44
|
-
define_method(:formatter=) do |formatter|
|
45
|
-
logger.formatter = formatter
|
46
|
-
super(formatter)
|
47
|
-
end
|
48
|
-
|
49
|
-
define_method(:level=) do |level|
|
50
|
-
logger.level = level
|
51
|
-
super(level)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
18
|
end
|
57
19
|
end
|
58
20
|
end
|
@@ -4,8 +4,8 @@ module Footnotes
|
|
4
4
|
|
5
5
|
autoload :NoteLogger, 'rails-footnotes/notes/log_note/note_logger'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
thread_cattr_accessor :logs
|
8
|
+
thread_cattr_accessor :original_logger
|
9
9
|
|
10
10
|
def self.start!(controller)
|
11
11
|
self.logs = []
|
@@ -18,9 +18,12 @@ module Footnotes
|
|
18
18
|
else
|
19
19
|
defined?(ActiveSupport::Logger) ? ActiveSupport::Logger::SimpleFormatter.new : Logger::SimpleFormatter.new
|
20
20
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
|
22
|
+
if ::Rails::VERSION::STRING < "7.1"
|
23
|
+
::Rails.logger.extend(::ActiveSupport::Logger.broadcast(note_logger))
|
24
|
+
else
|
25
|
+
::Rails.logger = ::ActiveSupport::BroadcastLogger.new(::Rails.logger, note_logger)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
def title
|
@@ -2,12 +2,12 @@ module Footnotes
|
|
2
2
|
module Notes
|
3
3
|
class PartialsNote < AbstractNote
|
4
4
|
|
5
|
-
|
5
|
+
thread_cattr_accessor :partials
|
6
6
|
|
7
7
|
def self.start!(controller)
|
8
8
|
self.partials = []
|
9
9
|
@subscriber ||= ActiveSupport::Notifications.subscribe('render_partial.action_view') do |*args|
|
10
|
-
event = ActiveSupport::Notifications::Event.new
|
10
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
11
11
|
self.partials << {:file => event.payload[:identifier], :duration => event.duration}
|
12
12
|
end
|
13
13
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Footnotes
|
2
2
|
module Notes
|
3
3
|
class QueriesNote < AbstractNote
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@@orm = [:active_record, :data_mapper]
|
9
|
-
@@ignored_regexps = [%r{(pg_table|pg_attribute|pg_namespace|show\stables|pragma|sqlite_master)}i]
|
4
|
+
thread_cattr_accessor :alert_db_time, default: 16.0, instance_writer: false
|
5
|
+
thread_cattr_accessor :alert_sql_number, default: 8, instance_writer: false
|
6
|
+
thread_cattr_accessor :orm, default: [:active_record, :data_mapper], instance_writer: false
|
7
|
+
thread_cattr_accessor :ignored_regexps, default: [%r{(pg_table|pg_attribute|pg_namespace|show\stables|pragma|sqlite_master)}i], instance_writer: false
|
10
8
|
|
11
9
|
def self.start!(controller)
|
12
10
|
self.query_subscriber.reset!
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Footnotes
|
2
2
|
module Notes
|
3
3
|
class ViewNote < AbstractNote
|
4
|
-
|
4
|
+
thread_cattr_accessor :template
|
5
5
|
|
6
6
|
def self.start!(controller)
|
7
7
|
@subscriber ||= ActiveSupport::Notifications.subscribe('render_template.action_view') do |*args|
|
8
|
-
event = ActiveSupport::Notifications::Event.new
|
8
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
9
9
|
self.template = {:file => event.payload[:identifier], :duration => event.duration}
|
10
10
|
end
|
11
11
|
end
|
@@ -19,7 +19,7 @@ module Footnotes
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def title
|
22
|
-
"View (#{"%.3f" %
|
22
|
+
"View (#{"%.3f" % template[:duration]}ms)"
|
23
23
|
end
|
24
24
|
|
25
25
|
def link
|
@@ -27,14 +27,14 @@ module Footnotes
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def valid?
|
30
|
-
prefix? && filename && File.
|
30
|
+
prefix? && filename && File.exist?(filename)
|
31
31
|
end
|
32
32
|
|
33
33
|
protected
|
34
34
|
|
35
35
|
def filename
|
36
36
|
return @filename if defined?(@filename)
|
37
|
-
@filename =
|
37
|
+
@filename = template.try(:[], :file)
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
data/lib/rails-footnotes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'action_controller'
|
3
|
+
require 'active_support/core_ext/module/attribute_accessors_per_thread'
|
3
4
|
require 'rails-footnotes/abstract_note'
|
4
5
|
require 'rails-footnotes/each_with_rescue'
|
5
6
|
require 'rails-footnotes/filter'
|
@@ -7,14 +8,9 @@ require 'rails-footnotes/notes/all'
|
|
7
8
|
require 'rails-footnotes/extension'
|
8
9
|
|
9
10
|
module Footnotes
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
mattr_accessor :after_hooks
|
14
|
-
@@after_hooks = []
|
15
|
-
|
16
|
-
mattr_accessor :enabled
|
17
|
-
@@enabled = false
|
11
|
+
thread_mattr_accessor :before_hooks
|
12
|
+
thread_mattr_accessor :after_hooks
|
13
|
+
thread_mattr_accessor :enabled, default: false
|
18
14
|
|
19
15
|
class << self
|
20
16
|
delegate :notes, :to => Filter
|
@@ -34,25 +30,28 @@ module Footnotes
|
|
34
30
|
|
35
31
|
delegate :font_size, :to => Filter
|
36
32
|
delegate :font_size=, :to => Filter
|
33
|
+
|
34
|
+
delegate :default_limit, :to => Filter
|
35
|
+
delegate :default_limit=, :to => Filter
|
37
36
|
end
|
38
37
|
|
39
38
|
def self.before(&block)
|
40
|
-
|
39
|
+
before_hooks << block
|
41
40
|
end
|
42
41
|
|
43
42
|
def self.after(&block)
|
44
|
-
|
43
|
+
after_hooks << block
|
45
44
|
end
|
46
45
|
|
47
46
|
def self.enabled?(controller)
|
48
|
-
if
|
49
|
-
if
|
50
|
-
|
47
|
+
if enabled.is_a? Proc
|
48
|
+
if enabled.arity == 1
|
49
|
+
enabled.call(controller)
|
51
50
|
else
|
52
|
-
|
51
|
+
enabled.call
|
53
52
|
end
|
54
53
|
else
|
55
|
-
|
54
|
+
!!enabled
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -61,8 +60,11 @@ module Footnotes
|
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
63
|
+
Footnotes.before_hooks = []
|
64
|
+
Footnotes.after_hooks = []
|
65
|
+
|
64
66
|
ActiveSupport.on_load(:action_controller) do
|
65
67
|
ActionController::Base.send(:include, Footnotes::RailsFootnotesExtension)
|
66
68
|
end
|
67
69
|
|
68
|
-
load Rails.root.join('.rails_footnotes') if Rails.root
|
70
|
+
load Rails.root.join('.rails_footnotes') if Rails.root&.join('.rails_footnotes')&.exist?
|
data/rails-footnotes.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "rails-footnotes/version"
|
1
|
+
require_relative "./lib/rails-footnotes/version"
|
4
2
|
|
5
3
|
Gem::Specification.new do |s|
|
6
4
|
s.name = "rails-footnotes"
|
@@ -12,8 +10,8 @@ Gem::Specification.new do |s|
|
|
12
10
|
s.summary = %q{Every Rails page has footnotes that gives information about your application and links back to your editor.}
|
13
11
|
s.description = %q{Every Rails page has footnotes that gives information about your application and links back to your editor.}
|
14
12
|
|
15
|
-
s.add_dependency "rails", "~>
|
16
|
-
s.required_ruby_version = "
|
13
|
+
s.add_dependency "rails", "~> 7.0"
|
14
|
+
s.required_ruby_version = ">= 3.0"
|
17
15
|
|
18
16
|
s.files = `git ls-files`.split("\n")
|
19
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|