Skip to content
rubyworksPublic

About

Extract Developers Notes from Source

Resources

Stars

44 stars

Watchers

0 watching

Forks

Latest commit

 

History

139 Commits

Folders and files

Repository files navigation

Source Code / Report Issue / API <img src=“https://github.com/rubyworks/dnote/actions/workflows/ci.yml/badge.svg” alt=“CI” />

Extract development notes from source code and generate some nice output formats for them.

DNote scans for the common note patterns used by developers of many languages in the form of an all-caps labels followed by a colon. To be more specific, for DNote to recognize a note, it needs to follow this simple set of rules:

1) Notes start with an all-caps label punctuated with a colon, followed by the note’s text.

# LABEL: description ...

2) 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 note for a pre block if it is indented.

# LABEL: description ...
# continue ...

3) An alternative to the previous limitation is to indent the whole note, making it a &lt;pre&gt; block when rendered by RDoc. Then the text layout is free-form.

# This is a description of something...
#
#   LABEL: description ...
#          continue ...

A note ends at a blank comment line or at a line of code.

There is also a command-line option, --no-colon, which deactives the need for a colon after the note label. However this often produces false positives, so it’s use is discouraged.

A note can also be written as a tag, in the manner of YARD. A tag needs no colon.

# @LABEL description ...
#   continue ...

A tag in capitals is always taken as a note. The usual labels, TODO, FIXME, OPTIMIZE, THINK and DEPRECATE, are taken as notes in lower case too, so YARD’s own @todo tag is collected along with the rest. Other lower case tags, such as @param and @return, are documentation and are left alone, unless asked for by name, e.g. --label NOTE collects @note.

A tag note ends at the next tag, as well as at a blank comment line or a line of code.

YARD itself warns of a tag it doesn’t know, such as @FIXME, and leaves it out of the documentation. To have YARD accept such a tag, name it in .yardopts, e.g. --tag FIXME:"Fix Me", and add --hide-tag FIXME to keep it out of the documentation.

To turn tags off use --no-tags.

As you can see the commandline interface is pretty straight-forward.

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 (# where it isn’t known); use --marker for any other.

Here is an example of DNote’s notes in RDoc format, from dnote -f rdoc -l TODO lib/dnote/format.rb:

= Developer's Notes

== TODO

=== file://lib/dnote/format.rb

* TODO: Need good CSS file. (12)
* TODO: Need XSL? (14)

(2 TODOs)

The formats are text, md, rdoc, html, xml, json, yaml, soap and xoxo. Each arranges the notes by label and then file. Add /file, /label or /list for another arrangement, e.g. -f md/list.

The soap format needs the soap4r-ng gem and the xoxo format needs the xoxo gem. Neither is installed with DNote.

A custom template is an ERB file. It has notes and title to work with, and h to escape text for HTML or XML.

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.

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

The usual RubyGem’s command will do the trick.

$ gem install dnote

DNote needs Ruby 3.1 or newer.

Copyright © 2006 Thomas Sawyer, Rubyworks

DNote is distributable in accordance with the terms of the FreeBSD license.

See COPYING.rdoc for details.

About

Extract Developers Notes from Source

Resources

Stars

44 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages