D'Note
Developer's notes, extracted from source code. For Ruby, and most other languages.
Developers, take note! All those TODOs and FIXMEs floating around your source code are rotting away. They are trapped, and in desperate need of your attention.
But not to fret! D'Note will help you liberate them. D'Note will scan your source code for labeled comments; collect, collate and sort them; and then return them to you in a format of your choosing. Wunderbar!
$ gem install dnote
Note Structure
D'Note scans for the common LABEL: pattern, an all-caps label followed by a colon,
used by many developers of many languages. To be more specific, for D'Note to recognize a note
it needs to conform to this simple set of rules:
-
Notes start with an all-caps label punctuated with a colon, followed by the note's text.
# LABEL: description ... -
Any note that requires more than one line must remain flush to the left margin (the margin is set by the first line). This is done because RDoc will mistake the second line for a
<pre>block if it is indented.# LABEL: description ... # continue ... -
An alternative to the limitation of the last rule is to indent the whole note (making the whole note a
<pre>block with regards to RDoc). Then the text layout is free-form.# This is a description of something... # # LABEL: description ... # continue ...
That's all there is to it. A note ends at a blank comment line or at a line of code. In the future the parsing may improve to allow page-top outlined notes as well.
There is also a command-line option, --no-colon, which deactivates the need for
a colon after the note label. However this often produces false positives, so its use is
discouraged.
Tags
A note can also be written as a tag, in the manner of YARD. A tag needs no colon.
# @TODO description ...
# continue ...
# @return [String] not part of the note
| Written as | Collected? |
|---|---|
@TODO, @WHATEVER | Always. A tag in capitals is a note. |
@todo, @fixme, @optimize, @think, @deprecate | Yes. The usual labels count in lower case too, so YARD's own @todo is picked up. |
@param, @return, @note | No. These are documentation. Ask by name to collect one: --label NOTE. |
A tag note ends at the next tag, as well as at a blank comment line or a line of code.
To turn tags off, use --no-tags.
YARD itself warns of a tag it doesn't know, such as @FIXME. To have YARD
accept one, name it in .yardopts:
--tag FIXME:"Fix Me" --hide-tag FIXME
Generating Notes
As you can see the command-line interface is quite straightforward.
USAGE:
dnote [OPTIONS] path1 [path2 ...]
OUTPUT FORMAT: (choose one)
-f, --format NAME select a format [text]
-C, --custom FILE use a custom ERB template
--file shortcut for text/file format
--list shortcut for text/list format
OTHER OPTIONS:
-l, --label LABEL labels to collect
--[no-]colon match labels with/without colon suffix
--[no-]tags match labels written as tags, e.g. @TODO [yes]
-m, --marker MARK alternative remark marker
-u, --url TEMPLATE url template for line entries (for HTML)
-c, --context INTEGER number of lines of context to display
-x, --exclude PATH exclude file or directory
-i, --ignore NAME ignore file based on any part of pathname
-t, --title TITLE title to use in header
-o, --output PATH save to file or directory
-n, --dryrun do not actually write to disk
--debug debug mode
COMMAND OPTIONS:
-T, --templates list available format templates
-h, --help show this help information
The default path is **/*.rb and the default format is -f text.
A path that is a directory takes in everything below it. The comment marker is chosen by
a file's extension; use --marker for any other.
Here are some of D'Note's own notes:
$ dnote -l TODO lib/dnote/format.rb lib/dnote/note.rb
Developer's Notes
TODO
1. Need good CSS file. (lib/dnote/format.rb:12)
2. Need XSL? (lib/dnote/format.rb:14)
3. Add +url+? (lib/dnote/note.rb:70)
4. Add +code+? Problem is that xml needs code in CDATA. (lib/dnote/note.rb:71)
(4 TODOs)
Formats
A variety of formats are available. Here is D'Note's own source in a few of them: HTML, Markdown, XML, YAML and JSON.
| Format | What you get |
|---|---|
text | Plain text, the default. |
md, rdoc | Markdown or RDoc, ready to add to your documentation. |
html | A page of its own. Give --url to link each note to its line. |
xml, json, yaml | Data, for other tools. |
soap, xoxo | Need the soap4r-ng and xoxo gems, which aren't installed with D'Note. |
Each arranges the notes by label and then by file. Add /file,
/label or /list for another arrangement, as in
-f md/list. The -T option lists them all.
For anything else, write an ERB template and pass it with --custom.
It has notes and title to work with.
Rake Task
require 'dnote/rake/dnotetask' DNote::RakeTask.new do |t| t.files = 'lib/**/*.rb' t.formats = ['html', 'md'] t.output = 'doc/notes' end
This defines a dnote task, which writes doc/notes/notes.html
and doc/notes/notes.md, and a dnote:clobber task that removes them.
With YARD
To add the notes to YARD documentation, write them to a file and list it in
.yardopts with the other extra files.
$ dnote -f md -o NOTES.md