dnote 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/HISTORY.rdoc +29 -0
- data/README.rdoc +81 -25
- data/lib/dnote/core_ext.rb +54 -75
- data/lib/dnote/format.rb +15 -7
- data/lib/dnote/notes.rb +60 -14
- data/lib/dnote/rake/dnotetask.rb +69 -50
- data/lib/dnote/session.rb +11 -2
- data/lib/dnote/templates/html/file.erb +1 -1
- data/lib/dnote/templates/html/label.erb +1 -1
- data/lib/dnote/templates/html/list.erb +2 -2
- data/lib/dnote/templates/html.erb +1 -1
- data/lib/dnote/templates/xml/file.erb +1 -1
- data/lib/dnote/templates/xoxo/file.erb +3 -1
- data/lib/dnote/templates/xoxo/label.erb +3 -1
- data/lib/dnote/templates/xoxo.erb +3 -1
- data/lib/dnote/version.rb +2 -14
- metadata +68 -68
- data/.ruby +0 -55
- data/.yardopts +0 -5
- data/lib/dnote.yml +0 -55
- data/test/notes_case.rb +0 -64
- data/try/sample.bas +0 -7
- data/try/sample.js +0 -11
- data/try/sample.rb +0 -11
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f879bf8a990918d87b1f64fc3cc10fba7a227b7a23bfdfb9eb5138fc99c72daf
|
|
4
|
+
data.tar.gz: a9376ea576ed8fcc8686666dbc46782738b547eb7c21a8f592f36c69ad435db0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 00f02b797117805b33615aedcb54645a6358786d029dcad65122273cd9309351e69dfe71565ff06835661bd1f43829cd32445b4a1a533deca75b99ebfe2214a9
|
|
7
|
+
data.tar.gz: cd0c6287d0cf741455aa9c3e1a2c6ad8af4b60da4e350878cf3809e7cd492a0a95a75fd26d13cf81336a0c53af01e376f91228ffa231805921177b40b0931be7
|
data/HISTORY.rdoc
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
= RELEASE HISTORY
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
== 1.8.0 / 2026-11-30
|
|
5
|
+
|
|
6
|
+
DNote runs on current Ruby again; it needs Ruby 3.1 or newer. Notes can
|
|
7
|
+
now be written as tags, in the manner of YARD, e.g. `@TODO Fix this.`
|
|
8
|
+
A tag in capitals is always a note. The usual labels (TODO, FIXME,
|
|
9
|
+
OPTIMIZE, THINK and DEPRECATE) are notes in lower case too, so YARD's
|
|
10
|
+
own `@todo` is collected. Use `--no-tags` to turn tags off.
|
|
11
|
+
|
|
12
|
+
Changes:
|
|
13
|
+
|
|
14
|
+
* Support Ruby 3.1 and newer (ERB is called with keywords).
|
|
15
|
+
* Add tag notes, such as `@TODO`, and the `--[no-]tags` option.
|
|
16
|
+
* A tag, such as YARD's `@return`, ends the note before it.
|
|
17
|
+
* Fix the first line of code after a note being left out of its context.
|
|
18
|
+
* Fix `html/list` and `xml/file` formats, which failed with any notes.
|
|
19
|
+
* Fix `xoxo` formats, which never finished.
|
|
20
|
+
* Fix label-and-file groupings when the plain grouping was used first.
|
|
21
|
+
* Fix the Rake task, which was written for another tool's task library.
|
|
22
|
+
* Fix `--dryrun`, which wrote the file all the same.
|
|
23
|
+
* Escape code context in HTML formats.
|
|
24
|
+
* Read files that aren't valid UTF-8, rather than fail on them.
|
|
25
|
+
* The string methods the templates use are refinements, no longer
|
|
26
|
+
added to String itself.
|
|
27
|
+
* A format whose library isn't installed (soap, xoxo) says so.
|
|
28
|
+
* Recognize the comment markers of more languages.
|
|
29
|
+
* Drop the dependency on REXML.
|
|
30
|
+
|
|
31
|
+
|
|
3
32
|
== 1.7.1 / 2012-01-10
|
|
4
33
|
|
|
5
34
|
The `dnote.yml` file which provides project metadata, particularly the DNote::VERSION setting,
|
data/README.rdoc
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
= DNote
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
{Source Code}[https://github.com/rubyworks/dnote] /
|
|
4
|
+
{Report Issue}[https://github.com/rubyworks/dnote/issues] /
|
|
5
|
+
{API}[https://rubydoc.info/gems/dnote]
|
|
6
|
+
{<img src="https://github.com/rubyworks/dnote/actions/workflows/ci.yml/badge.svg" alt="CI" />}[https://github.com/rubyworks/dnote/actions/workflows/ci.yml]
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
== DESCRIPTION
|
|
@@ -30,7 +31,7 @@ the note for a <code>pre</code> block if it is indented.
|
|
|
30
31
|
# LABEL: description ...
|
|
31
32
|
# continue ...
|
|
32
33
|
|
|
33
|
-
3) An alternative to the previous limitation is to indent the whole note, making it
|
|
34
|
+
3) An alternative to the previous limitation is to indent the whole note, making it
|
|
34
35
|
a <tt><pre></tt> block when rendered by RDoc. Then the text layout is free-form.
|
|
35
36
|
|
|
36
37
|
# This is a description of something...
|
|
@@ -38,13 +39,33 @@ a <tt><pre></tt> block when rendered by RDoc. Then the text layout is free
|
|
|
38
39
|
# LABEL: description ...
|
|
39
40
|
# continue ...
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
we may eventually be able to relax the flush rule too, which would be very nice.
|
|
42
|
+
A note ends at a blank comment line or at a line of code.
|
|
43
43
|
|
|
44
44
|
There is also a command-line option, <code>--no-colon</code>, which deactives the need for
|
|
45
45
|
a colon after the note label. However this often produces false positives, so it's use is
|
|
46
46
|
discouraged.
|
|
47
47
|
|
|
48
|
+
=== Tags
|
|
49
|
+
|
|
50
|
+
A note can also be written as a tag, in the manner of YARD. A tag needs no colon.
|
|
51
|
+
|
|
52
|
+
# @LABEL description ...
|
|
53
|
+
# continue ...
|
|
54
|
+
|
|
55
|
+
A tag in capitals is always taken as a note. The usual labels, +TODO+, +FIXME+,
|
|
56
|
+
+OPTIMIZE+, +THINK+ and +DEPRECATE+, are taken as notes in lower case too, so YARD's
|
|
57
|
+
own <tt>@todo</tt> tag is collected along with the rest. Other lower case tags, such
|
|
58
|
+
as <tt>@param</tt> and <tt>@return</tt>, are documentation and are left alone,
|
|
59
|
+
unless asked for by name, e.g. <code>--label NOTE</code> collects <tt>@note</tt>.
|
|
60
|
+
|
|
61
|
+
A tag note ends at the next tag, as well as at a blank comment line or a line of code.
|
|
62
|
+
|
|
63
|
+
YARD itself warns of a tag it doesn't know, such as <tt>@FIXME</tt>, and leaves it out
|
|
64
|
+
of the documentation. To have YARD accept such a tag, name it in +.yardopts+,
|
|
65
|
+
e.g. <code>--tag FIXME:"Fix Me"</code>, and add <code>--hide-tag FIXME</code>
|
|
66
|
+
to keep it out of the documentation.
|
|
67
|
+
|
|
68
|
+
To turn tags off use <code>--no-tags</code>.
|
|
48
69
|
|
|
49
70
|
=== Generating Notes
|
|
50
71
|
|
|
@@ -53,55 +74,90 @@ As you can see the commandline interface is pretty straight-forward.
|
|
|
53
74
|
USAGE:
|
|
54
75
|
|
|
55
76
|
dnote [OPTIONS] path1 [path2 ...]
|
|
56
|
-
|
|
77
|
+
|
|
57
78
|
OUTPUT FORMAT: (choose one)
|
|
58
79
|
-f, --format NAME select a format [text]
|
|
59
|
-
-
|
|
80
|
+
-C, --custom FILE use a custom ERB template
|
|
60
81
|
--file shortcut for text/file format
|
|
61
82
|
--list shortcut for text/list format
|
|
62
|
-
|
|
83
|
+
|
|
63
84
|
OTHER OPTIONS:
|
|
64
85
|
-l, --label LABEL labels to collect
|
|
65
86
|
--[no-]colon match labels with/without colon suffix
|
|
87
|
+
--[no-]tags match labels written as tags, e.g. @TODO [yes]
|
|
66
88
|
-m, --marker MARK alternative remark marker
|
|
67
|
-
-u
|
|
89
|
+
-u, --url TEMPLATE url template for line entries (for HTML)
|
|
90
|
+
-c, --context INTEGER number of lines of context to display
|
|
68
91
|
-x, --exclude PATH exclude file or directory
|
|
69
|
-
-i, --ignore NAME ignore based on any part of
|
|
92
|
+
-i, --ignore NAME ignore file based on any part of pathname
|
|
70
93
|
-t, --title TITLE title to use in header
|
|
71
|
-
-o, --output PATH
|
|
94
|
+
-o, --output PATH save to file or directory
|
|
72
95
|
-n, --dryrun do not actually write to disk
|
|
73
96
|
--debug debug mode
|
|
74
|
-
|
|
97
|
+
|
|
75
98
|
COMMAND OPTIONS:
|
|
76
99
|
-T, --templates list available format templates
|
|
77
100
|
-h, --help show this help information
|
|
78
101
|
|
|
79
|
-
The default path is <tt>**/*.rb</tt> and the default format is <tt>-f
|
|
80
|
-
|
|
102
|
+
The default path is <tt>**/*.rb</tt> and the default format is <tt>-f text</tt>.
|
|
103
|
+
A path that is a directory takes in everything below it. The comment marker is
|
|
104
|
+
chosen by a file's extension (<tt>#</tt> where it isn't known); use <code>--marker</code>
|
|
105
|
+
for any other.
|
|
106
|
+
|
|
107
|
+
Here is an example of DNote's notes in RDoc format, from
|
|
108
|
+
<code>dnote -f rdoc -l TODO lib/dnote/format.rb</code>:
|
|
81
109
|
|
|
82
|
-
=
|
|
110
|
+
= Developer's Notes
|
|
83
111
|
|
|
84
112
|
== TODO
|
|
85
113
|
|
|
86
|
-
=== file://lib/dnote/
|
|
114
|
+
=== file://lib/dnote/format.rb
|
|
87
115
|
|
|
88
|
-
* TODO:
|
|
89
|
-
|
|
90
|
-
* TODO: Need good CSS file. (22)
|
|
91
|
-
* TODO: Need XSL? (24)
|
|
116
|
+
* TODO: Need good CSS file. (12)
|
|
117
|
+
* TODO: Need XSL? (14)
|
|
92
118
|
|
|
93
|
-
|
|
119
|
+
(2 TODOs)
|
|
94
120
|
|
|
95
|
-
|
|
121
|
+
=== Formats
|
|
96
122
|
|
|
97
|
-
|
|
123
|
+
The formats are +text+, +md+, +rdoc+, +html+, +xml+, +json+, +yaml+, +soap+
|
|
124
|
+
and +xoxo+. Each arranges the notes by label and then file. Add <tt>/file</tt>,
|
|
125
|
+
<tt>/label</tt> or <tt>/list</tt> for another arrangement, e.g. <code>-f md/list</code>.
|
|
126
|
+
|
|
127
|
+
The +soap+ format needs the +soap4r-ng+ gem and the +xoxo+ format needs the +xoxo+ gem.
|
|
128
|
+
Neither is installed with DNote.
|
|
129
|
+
|
|
130
|
+
A custom template is an ERB file. It has +notes+ and +title+ to work with, and
|
|
131
|
+
+h+ to escape text for HTML or XML.
|
|
132
|
+
|
|
133
|
+
=== Rake Task
|
|
134
|
+
|
|
135
|
+
require 'dnote/rake/dnotetask'
|
|
136
|
+
|
|
137
|
+
DNote::RakeTask.new do |t|
|
|
138
|
+
t.files = 'lib/**/*.rb'
|
|
139
|
+
t.formats = ['html', 'md']
|
|
140
|
+
t.output = 'doc/notes'
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
This defines a +dnote+ task, which writes <tt>doc/notes/notes.html</tt> and
|
|
144
|
+
<tt>doc/notes/notes.md</tt>, and a <tt>dnote:clobber</tt> task that removes them.
|
|
145
|
+
|
|
146
|
+
=== With YARD
|
|
147
|
+
|
|
148
|
+
To add the notes to YARD documentation, write them to a file and list it in
|
|
149
|
+
+.yardopts+ with the other extra files.
|
|
150
|
+
|
|
151
|
+
$ dnote -f md -o NOTES.md
|
|
98
152
|
|
|
99
153
|
|
|
100
154
|
== INSTALLATION
|
|
101
155
|
|
|
102
156
|
The usual RubyGem's command will do the trick.
|
|
103
157
|
|
|
104
|
-
$
|
|
158
|
+
$ gem install dnote
|
|
159
|
+
|
|
160
|
+
DNote needs Ruby 3.1 or newer.
|
|
105
161
|
|
|
106
162
|
|
|
107
163
|
== COPYRIGHT
|
data/lib/dnote/core_ext.rb
CHANGED
|
@@ -1,92 +1,71 @@
|
|
|
1
|
-
module Enumerable
|
|
2
|
-
|
|
3
|
-
# Taken from Ruby Facets.
|
|
4
|
-
def group_by #:yield:
|
|
5
|
-
#h = k = e = nil
|
|
6
|
-
r = Hash.new
|
|
7
|
-
each{ |e| (r[yield(e)] ||= []) << e }
|
|
8
|
-
r
|
|
9
|
-
end unless method_defined?(:group_by)
|
|
10
|
-
|
|
11
|
-
end
|
|
12
|
-
|
|
13
1
|
module DNote
|
|
14
2
|
|
|
15
|
-
#
|
|
16
|
-
#
|
|
3
|
+
# String methods used by the templates. They are refinements, so they
|
|
4
|
+
# are not added to String for the rest of the program. A custom template
|
|
5
|
+
# has them, since it is rendered where they are in effect.
|
|
17
6
|
#
|
|
18
|
-
|
|
7
|
+
# These methods are taken from Ruby Facets.
|
|
8
|
+
module StringMethods
|
|
19
9
|
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
# x = %Q{
|
|
23
|
-
# | This
|
|
24
|
-
# | is
|
|
25
|
-
# | margin controlled!
|
|
26
|
-
# }.margin
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# NOTE: This may still need a bit of tweaking.
|
|
30
|
-
#
|
|
31
|
-
# CREDIT: Trans
|
|
10
|
+
refine ::String do
|
|
32
11
|
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
12
|
+
# Provides a margin controlled string.
|
|
13
|
+
#
|
|
14
|
+
# x = %Q{
|
|
15
|
+
# | This
|
|
16
|
+
# | is
|
|
17
|
+
# | margin controlled!
|
|
18
|
+
# }.margin
|
|
19
|
+
#
|
|
20
|
+
# CREDIT: Trans
|
|
21
|
+
def margin(n=0)
|
|
22
|
+
d = ((/\A.*\n\s*(.)/.match(self)) ||
|
|
23
|
+
(/\A\s*(.)/.match(self)))[1]
|
|
24
|
+
return '' unless d
|
|
25
|
+
if n == 0
|
|
26
|
+
gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '')
|
|
27
|
+
else
|
|
28
|
+
gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n)
|
|
29
|
+
end
|
|
43
30
|
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Preserves relative tabbing.
|
|
47
|
-
# The first non-empty line ends up with n spaces before nonspace.
|
|
48
|
-
#
|
|
49
|
-
# CREDIT: Gavin Sinclair
|
|
50
31
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
# Preserves relative tabbing.
|
|
33
|
+
# The first non-empty line ends up with n spaces before nonspace.
|
|
34
|
+
#
|
|
35
|
+
# CREDIT: Gavin Sinclair
|
|
36
|
+
def tabto(n)
|
|
37
|
+
if self =~ /^( *)\S/
|
|
38
|
+
indent(n - $1.length)
|
|
39
|
+
else
|
|
40
|
+
self
|
|
41
|
+
end
|
|
56
42
|
end
|
|
57
|
-
end
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
gsub(/^ {0,#{-n}}/, "")
|
|
44
|
+
# Indent left or right by n spaces.
|
|
45
|
+
#
|
|
46
|
+
# CREDIT: Gavin Sinclair
|
|
47
|
+
# CREDIT: Trans
|
|
48
|
+
def indent(n)
|
|
49
|
+
if n >= 0
|
|
50
|
+
gsub(/^/, ' ' * n)
|
|
51
|
+
else
|
|
52
|
+
gsub(/^ {0,#{-n}}/, "")
|
|
53
|
+
end
|
|
70
54
|
end
|
|
71
|
-
end
|
|
72
55
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
# Indent so that the least indented line starts at column n.
|
|
57
|
+
def tabset(n)
|
|
58
|
+
i = lines.map do |line|
|
|
59
|
+
line.strip.empty? ? nil : line.index(/\S/)
|
|
60
|
+
end
|
|
61
|
+
x = i.compact.min
|
|
62
|
+
t = n - x.to_i
|
|
63
|
+
t = 0 if t < 0
|
|
64
|
+
indent(t)
|
|
78
65
|
end
|
|
79
|
-
x = i.compact.min
|
|
80
|
-
t = n - x.to_i
|
|
81
|
-
t = 0 if t < 0
|
|
82
|
-
indent(t)
|
|
83
|
-
end
|
|
84
66
|
|
|
85
|
-
|
|
67
|
+
end
|
|
86
68
|
|
|
87
|
-
class ::String #:nodoc:
|
|
88
|
-
include DNote::String
|
|
89
69
|
end
|
|
90
70
|
|
|
91
71
|
end
|
|
92
|
-
|
data/lib/dnote/format.rb
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
require 'dnote/core_ext'
|
|
2
|
+
|
|
1
3
|
module DNote
|
|
2
4
|
|
|
5
|
+
# The string methods the templates use (+indent+, +tabset+ and so on)
|
|
6
|
+
# are refinements, in effect here and so in any template rendered.
|
|
7
|
+
using DNote::StringMethods
|
|
8
|
+
|
|
3
9
|
# = Notes Formatter
|
|
4
10
|
#
|
|
5
11
|
#--
|
|
@@ -11,8 +17,6 @@ module DNote
|
|
|
11
17
|
|
|
12
18
|
require 'fileutils'
|
|
13
19
|
require 'erb'
|
|
14
|
-
require 'rexml/text'
|
|
15
|
-
require 'dnote/core_ext'
|
|
16
20
|
|
|
17
21
|
#DEFAULT_OUTPUT_DIR = "log/dnote"
|
|
18
22
|
|
|
@@ -79,8 +83,12 @@ module DNote
|
|
|
79
83
|
def render_template
|
|
80
84
|
template = File.join(File.dirname(__FILE__), 'templates', "#{format}.erb")
|
|
81
85
|
raise "No such format - #{format}" unless File.exist?(template)
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
begin
|
|
87
|
+
result = erb(template)
|
|
88
|
+
rescue LoadError => err
|
|
89
|
+
raise "The #{format} format needs a library that is not installed (#{err.message})."
|
|
90
|
+
end
|
|
91
|
+
publish(result)
|
|
84
92
|
end
|
|
85
93
|
|
|
86
94
|
private
|
|
@@ -115,7 +123,7 @@ module DNote
|
|
|
115
123
|
puts "write: #{file}"
|
|
116
124
|
else
|
|
117
125
|
dir = File.dirname(file)
|
|
118
|
-
fu.
|
|
126
|
+
fu.mkdir_p(dir) unless File.exist?(dir)
|
|
119
127
|
File.open(file, 'w'){ |f| f << result }
|
|
120
128
|
end
|
|
121
129
|
return file
|
|
@@ -154,12 +162,12 @@ module DNote
|
|
|
154
162
|
end
|
|
155
163
|
#
|
|
156
164
|
def render(file)
|
|
157
|
-
erb = ERB.new(File.read(file),
|
|
165
|
+
erb = ERB.new(File.read(file), trim_mode: '<>')
|
|
158
166
|
erb.result(binding)
|
|
159
167
|
end
|
|
160
168
|
#
|
|
161
169
|
def h(string)
|
|
162
|
-
|
|
170
|
+
ERB::Util.html_escape(string)
|
|
163
171
|
end
|
|
164
172
|
#
|
|
165
173
|
def method_missing(s, *a)
|
data/lib/dnote/notes.rb
CHANGED
|
@@ -7,10 +7,14 @@ module DNote
|
|
|
7
7
|
#
|
|
8
8
|
# This class goes through you source files and compiles a list
|
|
9
9
|
# of any labeled comments. Labels are all-cap single word prefixes
|
|
10
|
-
# to a comment ending in a colon
|
|
10
|
+
# to a comment ending in a colon, as in <tt>TODO: Do something</tt>.
|
|
11
11
|
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
12
|
+
# A label can also be written as a tag, in the manner of YARD, in which
|
|
13
|
+
# case the colon isn't needed, as in <tt>@TODO Do something</tt>.
|
|
14
|
+
#
|
|
15
|
+
# The usual labels, +TODO+, +FIXME+, +OPTIMIZE+, +THINK+ and +DEPRECATE+,
|
|
16
|
+
# are recognized as tags in lower case too, so YARD's own <tt>@todo</tt>
|
|
17
|
+
# tag is collected.
|
|
14
18
|
#
|
|
15
19
|
#--
|
|
16
20
|
# TODO: Add ability to read header notes. They often
|
|
@@ -22,7 +26,8 @@ module DNote
|
|
|
22
26
|
# Default paths (all ruby scripts).
|
|
23
27
|
DEFAULT_PATHS = ["**/*.rb"]
|
|
24
28
|
|
|
25
|
-
#
|
|
29
|
+
# The usual note labels. When no labels are asked for, all labels are
|
|
30
|
+
# collected, and these are also recognized as lower-case tags.
|
|
26
31
|
DEFAULT_LABELS = ['TODO', 'FIXME', 'OPTIMIZE', 'THINK', 'DEPRECATE']
|
|
27
32
|
|
|
28
33
|
# Files to search for notes.
|
|
@@ -37,6 +42,9 @@ module DNote
|
|
|
37
42
|
# Specific remark marker (+nil+ for auto).
|
|
38
43
|
attr_accessor :marker
|
|
39
44
|
|
|
45
|
+
# Recognize tag notes, such as <tt>@TODO</tt>? Default is +true+.
|
|
46
|
+
attr_accessor :tags
|
|
47
|
+
|
|
40
48
|
# Link template.
|
|
41
49
|
attr_accessor :url
|
|
42
50
|
|
|
@@ -49,6 +57,7 @@ module DNote
|
|
|
49
57
|
@labels = [options[:labels] || DEFAULT_LABELS].flatten.compact
|
|
50
58
|
@colon = options[:colon].nil? ? true : options[:colon]
|
|
51
59
|
@marker = options[:marker] #|| '#'
|
|
60
|
+
@tags = options[:tags].nil? ? true : options[:tags]
|
|
52
61
|
@url = options[:url]
|
|
53
62
|
@context = options[:context] || 0
|
|
54
63
|
|
|
@@ -95,6 +104,7 @@ module DNote
|
|
|
95
104
|
mark = remark(fname)
|
|
96
105
|
lineno, note, text, capt = 0, nil, nil, nil
|
|
97
106
|
File.readlines(fname).each do |line|
|
|
107
|
+
line = line.scrub unless line.valid_encoding?
|
|
98
108
|
#while line = f.gets
|
|
99
109
|
lineno += 1
|
|
100
110
|
note = match(line, lineno, fname)
|
|
@@ -110,15 +120,21 @@ module DNote
|
|
|
110
120
|
when /^\s*#{mark}+\s*$/, /^\s*#{mark}\-\-/, /^\s*#{mark}\+\+/
|
|
111
121
|
text.strip!
|
|
112
122
|
text = nil
|
|
123
|
+
when /^\s*#{mark}\s*@\w/
|
|
124
|
+
# another tag, such as YARD's `@return`, ends the note
|
|
125
|
+
text.strip!
|
|
126
|
+
text = nil
|
|
113
127
|
when /^\s*#{mark}/
|
|
114
|
-
if text[-1,1] == "\n"
|
|
128
|
+
if text.empty? || text[-1,1] == "\n"
|
|
115
129
|
text << line.gsub(/^\s*#{mark}\s*/,'')
|
|
116
130
|
else
|
|
117
131
|
text << "\n" << line.gsub(/^\s*#{mark}\s*/,'')
|
|
118
132
|
end
|
|
119
133
|
else
|
|
134
|
+
# a line of code ends the note, and is its first line of context
|
|
120
135
|
text.strip!
|
|
121
136
|
text = nil
|
|
137
|
+
capt << line if capt && capt.size < context
|
|
122
138
|
end
|
|
123
139
|
else
|
|
124
140
|
if line !~ /^\s*#{mark}/
|
|
@@ -135,11 +151,43 @@ module DNote
|
|
|
135
151
|
|
|
136
152
|
# Is this line a note?
|
|
137
153
|
def match(line, lineno, file)
|
|
154
|
+
note = (
|
|
155
|
+
if labels.empty?
|
|
156
|
+
match_general(line, lineno, file)
|
|
157
|
+
else
|
|
158
|
+
match_special(line, lineno, file)
|
|
159
|
+
end
|
|
160
|
+
)
|
|
161
|
+
note || (tags ? match_tag(line, lineno, file) : nil)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Match notes written as tags, such as <tt>@TODO</tt>. A tag has no
|
|
165
|
+
# need of a colon, though it may have one.
|
|
166
|
+
#
|
|
167
|
+
# A tag in capitals is always a note. In lower case it is a note only
|
|
168
|
+
# if it is one of the labels asked for, or one of the usual labels
|
|
169
|
+
# when none were asked for. So YARD's <tt>@todo</tt> is collected, and
|
|
170
|
+
# its <tt>@param</tt> and <tt>@return</tt> are not.
|
|
171
|
+
def match_tag(line, lineno, file)
|
|
172
|
+
md = match_tag_regex(file).match(line)
|
|
173
|
+
return nil unless md
|
|
174
|
+
|
|
175
|
+
name, text = md[1], md[2].to_s
|
|
176
|
+
label = name.upcase
|
|
177
|
+
|
|
138
178
|
if labels.empty?
|
|
139
|
-
|
|
179
|
+
return nil unless name == label || DEFAULT_LABELS.include?(label)
|
|
140
180
|
else
|
|
141
|
-
|
|
181
|
+
return nil unless labels.include?(label)
|
|
142
182
|
end
|
|
183
|
+
|
|
184
|
+
Note.new(self, file, label, lineno, text, remark(file))
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#
|
|
188
|
+
def match_tag_regex(file)
|
|
189
|
+
mark = remark(file)
|
|
190
|
+
/#{mark}\s*@([A-Za-z]+)[:]?(?:\s+(.*?))?$/
|
|
143
191
|
end
|
|
144
192
|
|
|
145
193
|
# Match special notes.
|
|
@@ -155,9 +203,7 @@ module DNote
|
|
|
155
203
|
rec
|
|
156
204
|
end
|
|
157
205
|
|
|
158
|
-
|
|
159
|
-
# TODO: ruby-1.9.1-p378 reports: `match': invalid byte sequence in UTF-8
|
|
160
|
-
#++
|
|
206
|
+
#
|
|
161
207
|
def match_special_regex(label, file)
|
|
162
208
|
mark = remark(file)
|
|
163
209
|
if colon
|
|
@@ -218,7 +264,7 @@ module DNote
|
|
|
218
264
|
# Organize notes into a hash with labels for keys, followed
|
|
219
265
|
# by a hash with filename for keys.
|
|
220
266
|
def by_label_file
|
|
221
|
-
@
|
|
267
|
+
@by_label_file ||= (
|
|
222
268
|
list = {}
|
|
223
269
|
notes.each do |note|
|
|
224
270
|
list[note.label] ||= {}
|
|
@@ -233,7 +279,7 @@ module DNote
|
|
|
233
279
|
# Organize notes into a hash with filenames for keys, followed
|
|
234
280
|
# by a hash with labels for keys.
|
|
235
281
|
def by_file_label
|
|
236
|
-
@
|
|
282
|
+
@by_file_label ||= (
|
|
237
283
|
list = {}
|
|
238
284
|
notes.each do |note|
|
|
239
285
|
list[note.file] ||= {}
|
|
@@ -270,11 +316,11 @@ module DNote
|
|
|
270
316
|
def guess_marker(file)
|
|
271
317
|
return @marker if @marker # forced marker
|
|
272
318
|
case File.extname(file)
|
|
273
|
-
when '.js', '.c', 'cpp', '.css'
|
|
319
|
+
when '.js', '.c', '.cpp', '.h', '.css', '.java', '.go', '.rs', '.ts'
|
|
274
320
|
'//'
|
|
275
321
|
when '.bas'
|
|
276
322
|
"'"
|
|
277
|
-
when '.sql', '.ada'
|
|
323
|
+
when '.sql', '.ada', '.lua', '.hs'
|
|
278
324
|
'--'
|
|
279
325
|
when '.asm'
|
|
280
326
|
';'
|