Reference and examples
This page keeps a reference complete and each example true. Make the pages from data, run each example in the build, and make each picture with a tool.
Reference pages from data
A reference has many entries in one form. When the entries are data, a tool can check that each one is complete, and a plugin can make the pages.
The command reference of ztcl works this way:
- Each command has one file of declarations,
docs/reference/NAME.tcl. It has the synopsis, the summary, each argument and option, the examples, and the errors. - A tool reads each file in a sandbox and checks its shape: each subcommand has a summary, each option has a type.
- A second tool runs each example and each error of each entry in a runner, and compares the result with the entry.
- A third tool checks that each command of the program has an entry.
- The docs build reads the entries and makes a page for each command.
command string {
synopsis {string SUBCOMMAND ?ARG ...?}
summary {The commands for text: length, search, compare, change, and test.}
subcommand map {
synopsis {string map ?-nocase? MAPPING STRING}
summary {Replaces each key of a list of keys and values with its value.}
example {string map {a 1 b 2} abcab} 12c12
error {string map a} {wrong # args: should be "string map ?-nocase? charMap string"} {TCL WRONGARGS}
}
}
In Flight Manual, a plugin with the hook pages makes the pages from data. The example api makes a page for each function of a JSON file.
Examples that cannot lie
An example that does not run goes out of date with the next change of the program. Put each example where the build or CI runs it, and compare its output:
- A command reference entry has examples with their results, and a tool runs them (above).
- A whole site, program, or project goes in the examples folder of the repository. CI builds it and compares the output with a copy in the repository. Flight Manual does this for each site of
examples/. - A page shows parts of an example and links to the whole example.
When an example changes its output on purpose, update the copy of the output in the same commit. The diff then shows the change to the reviewer.
Pictures that the build makes
A picture made by hand is old after the next change of the look. Make each picture with a tool of the repository:
- Flight Manual makes the pictures of Examples with
tools/example-shots.sh: it builds each example and takes a picture of it in a headless Chromium. - ztk draws the pictures of its widget reference from data of the entries, with a tool that runs the widget.
Run the tool after each change of the look, and commit the pictures with the change.
Next: Review a page.