| 1 | # API documentation generation using PasDoc |
| 2 | |
| 3 | The script here generates the API documentation for [Castle Game Engine](https://castle-engine.io/) using [PasDoc](https://pasdoc.github.io/). |
| 4 | |
| 5 | The online version of this documentation is already generated for you: |
| 6 | |
| 7 | - On https://castle-engine.io/apidoc/html/ . |
| 8 | |
| 9 | Right now this corresponds to 7.0-alpha.snapshot version, and is automatically regenerated after every commit. |
| 10 | |
| 11 | - If you [download the engine](https://castle-engine.io/download) then you also already have an offline version of this documentation generated in `doc/reference/`. |
| 12 | |
| 13 | ## How to generate the docs yourself using PasDoc |
| 14 | |
| 15 | Run `make html` here. |
| 16 | |
| 17 | - You must first install `pasdoc`. It's available in some Linux distributions packages, or you can get it from https://pasdoc.github.io/ . |
| 18 | |
| 19 | If you install PasDoc yourself (not from packages), be sure to put the `pasdoc` binary on `$PATH`, so that calling just `pasdoc` from the command-line works. |
| 20 | |
| 21 | - For example, on Unix (Linux, macOS...) add something like this to your `$HOME/.bashrc` file: |
| 22 | |
| 23 | ``` |
| 24 | export PATH="$HOME/installed/pasdoc/bin:$PATH" |
| 25 | ``` |
| 26 | |
| 27 | - On Windows, search Internet for _"how to modify PATH Windows"_ or something similar, to learn how to set the $PATH correctly. |
| 28 | |
| 29 | - Running `make html` should work out-of-the-box on any Unix (Linux, macOS...) system. |
| 30 | |
| 31 | On Windows you will need to additionally install [Cygwin](http://cygwin.com/) or [MSYS2](https://www.msys2.org/). In particular `mk_docs.sh` relies on GNU `find`, not default Windows defunct `find` command. |
| 32 | |
| 33 | ## API docs "parts" matching CGE website |
| 34 | |
| 35 | The `html-parts/` subdirectory here contains some files (HTMLs, and some images/CSS/JS in subdirectories) copied (or generated from) our actual website on https://castle-engine.io/ . For your comfort, these files are already present inside `html-parts/` here, committed. |
| 36 | |
| 37 | They will be automatically used as necessary by `make html` documented above. |
| 38 | |
| 39 | If you would like to regenerate them (e.g. because cge-www header / footer changed), do this: |
| 40 | |
| 41 | ``` |
| 42 | cd html-parts |
| 43 | make clean |
| 44 | make |
| 45 | ``` |
| 46 | |
| 47 | Note: For this, you will need to have command-line `php` installed, and you will need our website sources from https://github.com/castle-engine/cge-www (cloned such that `cge-www` and `castle-engine` repos are siblings). |
| 48 | |
| 49 | ## How to write documentation for the engine |
| 50 | |
| 51 | See also [coding conventions](https://castle-engine.io/coding_conventions). |
| 52 | |
| 53 | The documentation is just comments in the unit interface. Place a simple text in plain English that describes the intention of your identifier (a unit, a function, a class, a property, an enumeration value...). |
| 54 | |
| 55 | The documentation style: |
| 56 | |
| 57 | - Always use full, English sentences, that start with an upper letter |
| 58 | and end with a dot. So instead of |
| 59 | |
| 60 | ``` |
| 61 | { returns true if camera view orientation is known } |
| 62 | ``` |
| 63 | |
| 64 | it's better to write: |
| 65 | |
| 66 | ``` |
| 67 | { Returns true if camera view orientation is known. } |
| 68 | ``` |
| 69 | |
| 70 | - The first sentence (up to the first dot, see https://github.com/pasdoc/pasdoc/wiki/AutoAbstractOption ) is automatically understood to be an "abstract" by PasDoc. So it's ultra-important. It should stand on it's own, and be a good summary of what the given identifier does. |
| 71 | |
| 72 | It should be concise, and not repeat anything obvious. So, continuing the previous example, it's even better to write: |
| 73 | |
| 74 | ``` |
| 75 | { Returns if camera view orientation is known. } |
| 76 | ``` |
| 77 | |
| 78 | or even more better |
| 79 | |
| 80 | ``` |
| 81 | { Is the camera view orientation known. } |
| 82 | ``` |
| 83 | |
| 84 | BTW, do not be tempted to end the above sentence with a question mark, "?". End it with ".", as it's not a question -- it's a description of the value. Also, Pasdoc's `--auto-abstract` expects the sentence to end with ".", not "?". |
| 85 | |
| 86 | - In general, avoid words that do not actually enhance the meaning, especially in that first sentence. Try to keep the English simple and clean. |
| 87 | |
| 88 | - Instead of _"Returns blah."_, you can usually say just _"Blah."_ (e.g. _"Returns the game state."_ -> _"Game state."_) |
| 89 | |
| 90 | - Instead of _"Controls blah."_, _"Determines blah."_, ... you can also usually (but, admittedly, not always) say _"Blah._" |
| 91 | |
| 92 | - Do *not* start the documentation string with _"This..."_, like _"This procedure performs eating a fruit."_ or _"This class represents a fruit."_ or _"This function calculates a square root."_. Instead just write _"Eat a fruit."_, _"A fruit."_, _"Square root."_. |
| 93 | |
| 94 | The reader already sees the identifier declaration, so you don't need to explicitly tell that "this is a class", or a "procedure", or ... |
| 95 | |
| 96 | These guidelines are somewhat inspired by the javadoc standards, http://www.oracle.com/technetwork/articles/java/index-137868.html . |
| 97 | |
| 98 | - PasDoc supports many @-tags to format your documentation nicer. Use them. |
| 99 | |
| 100 | E.g. |
| 101 | |
| 102 | - `@italic(this is italic)`, |
| 103 | - `@bold(this is bold)`, |
| 104 | - `@unorderedList( @item(One) @item(Two) )`, |
| 105 | - see https://pasdoc.github.io/SupportedTags for the list. |
| 106 | |
| 107 | - We use the `--auto-link` feature of PasDoc. This means that identifiers are automatically linked, without the need to surround them in `@link()` tag... unless they are a common English word and we added them as an exception to `auto_link_exclude.txt` file here. So: |
| 108 | |
| 109 | - If you have an identifier that's a common English word, add it to `auto_link_exclude.txt` and use `@link` to link to it. |
| 110 | |
| 111 | - Otherwise, just write it's name anywhere in the documentation string, and it will be automatically picked up. Sometimes, it's reasonable to use an explicit `@link` anyway, to make sure that the link is correct (PasDoc will warn if `@link` contents are incorrect, e.g. you make a typo). |
| 112 | |
| 113 | - An exception to the rule _"put comments in the unit interface"_ are the X3D fields. |
| 114 | |
| 115 | They should be documented using "doc:" tag in txt files like this: `tools/internal/x3d-nodes-to-pascal/nodes-specification/Rendering.txt`. This makes it possible to regenerate the include files in "auto_generated_node_helpers" when necessary. |