rails-footnotes 7.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/Gemfile +3 -1
- data/Gemfile.lock +107 -68
- 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 +1 -1
- 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 +4 -4
- data/lib/rails-footnotes/version.rb +1 -1
- data/lib/rails-footnotes.rb +18 -16
- data/rails-footnotes.gemspec +1 -3
- 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 +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0806369e63f41ba98bc1ca73ea106d8d0d77a804e4118a1e4d35c8b504e76895'
|
4
|
+
data.tar.gz: 3081ed9edcd94647f9d977329de5e1fe71a859410d99325f3e42bdcb9b54cb8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c448ae88bc1b66831537d29108d8e37404ae888631e522a25cbff351341551ee875eaf443c42f8a146761e8e48db53244746628b2f0b3474c8415c215e763d7f
|
7
|
+
data.tar.gz: 0147a705dc6ccca11c82ca5fda8d14e88e116f4a3ea44f1f29822cf66596c0369e437d99b979036998307308d8c4f1bef555f6f9e6d7c44964174b7ae946d7eb
|
data/Gemfile
CHANGED
@@ -5,9 +5,11 @@ gemspec
|
|
5
5
|
ruby file: ".ruby-version"
|
6
6
|
|
7
7
|
gem "capybara", "~> 3.35"
|
8
|
+
gem "gem-release", "~> 2.2"
|
9
|
+
gem "matrix", "~> 0.4.2"
|
8
10
|
gem "nokogiri", "~> 1.12"
|
9
11
|
gem "pry", "~> 0.14.1"
|
10
12
|
gem "rake", "~> 13.0"
|
11
13
|
gem "rspec-rails", "~> 6.0"
|
12
14
|
gem "sprockets-rails", "~> 3.2"
|
13
|
-
gem "
|
15
|
+
gem "sqlite3", "~> 1.6"
|
data/Gemfile.lock
CHANGED
@@ -1,79 +1,90 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails-footnotes (7.0.
|
4
|
+
rails-footnotes (7.0.1)
|
5
5
|
rails (~> 7.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (7.
|
11
|
-
actionpack (= 7.
|
12
|
-
activesupport (= 7.
|
10
|
+
actioncable (7.1.2)
|
11
|
+
actionpack (= 7.1.2)
|
12
|
+
activesupport (= 7.1.2)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
zeitwerk (~> 2.6)
|
16
|
+
actionmailbox (7.1.2)
|
17
|
+
actionpack (= 7.1.2)
|
18
|
+
activejob (= 7.1.2)
|
19
|
+
activerecord (= 7.1.2)
|
20
|
+
activestorage (= 7.1.2)
|
21
|
+
activesupport (= 7.1.2)
|
21
22
|
mail (>= 2.7.1)
|
22
23
|
net-imap
|
23
24
|
net-pop
|
24
25
|
net-smtp
|
25
|
-
actionmailer (7.
|
26
|
-
actionpack (= 7.
|
27
|
-
actionview (= 7.
|
28
|
-
activejob (= 7.
|
29
|
-
activesupport (= 7.
|
26
|
+
actionmailer (7.1.2)
|
27
|
+
actionpack (= 7.1.2)
|
28
|
+
actionview (= 7.1.2)
|
29
|
+
activejob (= 7.1.2)
|
30
|
+
activesupport (= 7.1.2)
|
30
31
|
mail (~> 2.5, >= 2.5.4)
|
31
32
|
net-imap
|
32
33
|
net-pop
|
33
34
|
net-smtp
|
34
|
-
rails-dom-testing (~> 2.
|
35
|
-
actionpack (7.
|
36
|
-
actionview (= 7.
|
37
|
-
activesupport (= 7.
|
38
|
-
|
35
|
+
rails-dom-testing (~> 2.2)
|
36
|
+
actionpack (7.1.2)
|
37
|
+
actionview (= 7.1.2)
|
38
|
+
activesupport (= 7.1.2)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
racc
|
41
|
+
rack (>= 2.2.4)
|
42
|
+
rack-session (>= 1.0.1)
|
39
43
|
rack-test (>= 0.6.3)
|
40
|
-
rails-dom-testing (~> 2.
|
41
|
-
rails-html-sanitizer (~> 1.
|
42
|
-
actiontext (7.
|
43
|
-
actionpack (= 7.
|
44
|
-
activerecord (= 7.
|
45
|
-
activestorage (= 7.
|
46
|
-
activesupport (= 7.
|
44
|
+
rails-dom-testing (~> 2.2)
|
45
|
+
rails-html-sanitizer (~> 1.6)
|
46
|
+
actiontext (7.1.2)
|
47
|
+
actionpack (= 7.1.2)
|
48
|
+
activerecord (= 7.1.2)
|
49
|
+
activestorage (= 7.1.2)
|
50
|
+
activesupport (= 7.1.2)
|
47
51
|
globalid (>= 0.6.0)
|
48
52
|
nokogiri (>= 1.8.5)
|
49
|
-
actionview (7.
|
50
|
-
activesupport (= 7.
|
53
|
+
actionview (7.1.2)
|
54
|
+
activesupport (= 7.1.2)
|
51
55
|
builder (~> 3.1)
|
52
|
-
erubi (~> 1.
|
53
|
-
rails-dom-testing (~> 2.
|
54
|
-
rails-html-sanitizer (~> 1.
|
55
|
-
activejob (7.
|
56
|
-
activesupport (= 7.
|
56
|
+
erubi (~> 1.11)
|
57
|
+
rails-dom-testing (~> 2.2)
|
58
|
+
rails-html-sanitizer (~> 1.6)
|
59
|
+
activejob (7.1.2)
|
60
|
+
activesupport (= 7.1.2)
|
57
61
|
globalid (>= 0.3.6)
|
58
|
-
activemodel (7.
|
59
|
-
activesupport (= 7.
|
60
|
-
activerecord (7.
|
61
|
-
activemodel (= 7.
|
62
|
-
activesupport (= 7.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
activemodel (7.1.2)
|
63
|
+
activesupport (= 7.1.2)
|
64
|
+
activerecord (7.1.2)
|
65
|
+
activemodel (= 7.1.2)
|
66
|
+
activesupport (= 7.1.2)
|
67
|
+
timeout (>= 0.4.0)
|
68
|
+
activestorage (7.1.2)
|
69
|
+
actionpack (= 7.1.2)
|
70
|
+
activejob (= 7.1.2)
|
71
|
+
activerecord (= 7.1.2)
|
72
|
+
activesupport (= 7.1.2)
|
68
73
|
marcel (~> 1.0)
|
69
|
-
|
70
|
-
|
74
|
+
activesupport (7.1.2)
|
75
|
+
base64
|
76
|
+
bigdecimal
|
71
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
78
|
+
connection_pool (>= 2.2.5)
|
79
|
+
drb
|
72
80
|
i18n (>= 1.6, < 2)
|
73
81
|
minitest (>= 5.1)
|
82
|
+
mutex_m
|
74
83
|
tzinfo (~> 2.0)
|
75
84
|
addressable (2.8.5)
|
76
85
|
public_suffix (>= 2.0.2, < 6.0)
|
86
|
+
base64 (0.2.0)
|
87
|
+
bigdecimal (3.1.4)
|
77
88
|
builder (3.2.4)
|
78
89
|
capybara (3.39.2)
|
79
90
|
addressable
|
@@ -86,14 +97,22 @@ GEM
|
|
86
97
|
xpath (~> 3.2)
|
87
98
|
coderay (1.1.3)
|
88
99
|
concurrent-ruby (1.2.2)
|
100
|
+
connection_pool (2.4.1)
|
89
101
|
crass (1.0.6)
|
90
102
|
date (3.3.4)
|
91
103
|
diff-lcs (1.5.0)
|
104
|
+
drb (2.2.0)
|
105
|
+
ruby2_keywords
|
92
106
|
erubi (1.12.0)
|
107
|
+
gem-release (2.2.2)
|
93
108
|
globalid (1.2.1)
|
94
109
|
activesupport (>= 6.1)
|
95
110
|
i18n (1.14.1)
|
96
111
|
concurrent-ruby (~> 1.0)
|
112
|
+
io-console (0.6.0)
|
113
|
+
irb (1.10.0)
|
114
|
+
rdoc
|
115
|
+
reline (>= 0.3.8)
|
97
116
|
loofah (2.22.0)
|
98
117
|
crass (~> 1.0.2)
|
99
118
|
nokogiri (>= 1.12.0)
|
@@ -107,7 +126,8 @@ GEM
|
|
107
126
|
method_source (1.0.0)
|
108
127
|
mini_mime (1.1.5)
|
109
128
|
minitest (5.20.0)
|
110
|
-
|
129
|
+
mutex_m (0.2.0)
|
130
|
+
net-imap (0.4.7)
|
111
131
|
date
|
112
132
|
net-protocol
|
113
133
|
net-pop (0.1.2)
|
@@ -116,7 +136,7 @@ GEM
|
|
116
136
|
timeout
|
117
137
|
net-smtp (0.4.0)
|
118
138
|
net-protocol
|
119
|
-
nio4r (2.
|
139
|
+
nio4r (2.7.0)
|
120
140
|
nokogiri (1.15.5-arm64-darwin)
|
121
141
|
racc (~> 1.4)
|
122
142
|
nokogiri (1.15.5-x86_64-linux)
|
@@ -124,25 +144,32 @@ GEM
|
|
124
144
|
pry (0.14.2)
|
125
145
|
coderay (~> 1.1)
|
126
146
|
method_source (~> 1.0)
|
147
|
+
psych (5.1.1.1)
|
148
|
+
stringio
|
127
149
|
public_suffix (5.0.4)
|
128
150
|
racc (1.7.3)
|
129
|
-
rack (
|
151
|
+
rack (3.0.8)
|
152
|
+
rack-session (2.0.0)
|
153
|
+
rack (>= 3.0.0)
|
130
154
|
rack-test (2.1.0)
|
131
155
|
rack (>= 1.3)
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
156
|
+
rackup (2.1.0)
|
157
|
+
rack (>= 3)
|
158
|
+
webrick (~> 1.8)
|
159
|
+
rails (7.1.2)
|
160
|
+
actioncable (= 7.1.2)
|
161
|
+
actionmailbox (= 7.1.2)
|
162
|
+
actionmailer (= 7.1.2)
|
163
|
+
actionpack (= 7.1.2)
|
164
|
+
actiontext (= 7.1.2)
|
165
|
+
actionview (= 7.1.2)
|
166
|
+
activejob (= 7.1.2)
|
167
|
+
activemodel (= 7.1.2)
|
168
|
+
activerecord (= 7.1.2)
|
169
|
+
activestorage (= 7.1.2)
|
170
|
+
activesupport (= 7.1.2)
|
144
171
|
bundler (>= 1.15.0)
|
145
|
-
railties (= 7.
|
172
|
+
railties (= 7.1.2)
|
146
173
|
rails-dom-testing (2.2.0)
|
147
174
|
activesupport (>= 5.0.0)
|
148
175
|
minitest
|
@@ -150,15 +177,20 @@ GEM
|
|
150
177
|
rails-html-sanitizer (1.6.0)
|
151
178
|
loofah (~> 2.21)
|
152
179
|
nokogiri (~> 1.14)
|
153
|
-
railties (7.
|
154
|
-
actionpack (= 7.
|
155
|
-
activesupport (= 7.
|
156
|
-
|
180
|
+
railties (7.1.2)
|
181
|
+
actionpack (= 7.1.2)
|
182
|
+
activesupport (= 7.1.2)
|
183
|
+
irb
|
184
|
+
rackup (>= 1.0.0)
|
157
185
|
rake (>= 12.2)
|
158
|
-
thor (~> 1.0)
|
159
|
-
zeitwerk (~> 2.
|
186
|
+
thor (~> 1.0, >= 1.2.2)
|
187
|
+
zeitwerk (~> 2.6)
|
160
188
|
rake (13.1.0)
|
189
|
+
rdoc (6.6.0)
|
190
|
+
psych (>= 4.0.0)
|
161
191
|
regexp_parser (2.8.2)
|
192
|
+
reline (0.4.1)
|
193
|
+
io-console (~> 0.5)
|
162
194
|
rspec-core (3.12.2)
|
163
195
|
rspec-support (~> 3.12.0)
|
164
196
|
rspec-expectations (3.12.3)
|
@@ -176,6 +208,7 @@ GEM
|
|
176
208
|
rspec-mocks (~> 3.12)
|
177
209
|
rspec-support (~> 3.12)
|
178
210
|
rspec-support (3.12.1)
|
211
|
+
ruby2_keywords (0.0.5)
|
179
212
|
sprockets (4.2.1)
|
180
213
|
concurrent-ruby (~> 1.0)
|
181
214
|
rack (>= 2.2.4, < 4)
|
@@ -183,10 +216,14 @@ GEM
|
|
183
216
|
actionpack (>= 5.2)
|
184
217
|
activesupport (>= 5.2)
|
185
218
|
sprockets (>= 3.0.0)
|
219
|
+
sqlite3 (1.6.9-arm64-darwin)
|
220
|
+
sqlite3 (1.6.9-x86_64-linux)
|
221
|
+
stringio (3.1.0)
|
186
222
|
thor (1.3.0)
|
187
223
|
timeout (0.4.1)
|
188
224
|
tzinfo (2.0.6)
|
189
225
|
concurrent-ruby (~> 1.0)
|
226
|
+
webrick (1.8.1)
|
190
227
|
websocket-driver (0.7.6)
|
191
228
|
websocket-extensions (>= 0.1.0)
|
192
229
|
websocket-extensions (0.1.5)
|
@@ -202,6 +239,7 @@ PLATFORMS
|
|
202
239
|
|
203
240
|
DEPENDENCIES
|
204
241
|
capybara (~> 3.35)
|
242
|
+
gem-release (~> 2.2)
|
205
243
|
matrix (~> 0.4.2)
|
206
244
|
nokogiri (~> 1.12)
|
207
245
|
pry (~> 0.14.1)
|
@@ -209,6 +247,7 @@ DEPENDENCIES
|
|
209
247
|
rake (~> 13.0)
|
210
248
|
rspec-rails (~> 6.0)
|
211
249
|
sprockets-rails (~> 3.2)
|
250
|
+
sqlite3 (~> 1.6)
|
212
251
|
|
213
252
|
RUBY VERSION
|
214
253
|
ruby 3.2.2p53
|
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) {
|