Skip to content

Commit 56f9b6f

Browse files
committedNov 29, 2024·
add docs
1 parent 4a3d5b5 commit 56f9b6f

File tree

10 files changed

+185
-457
lines changed

10 files changed

+185
-457
lines changed
 

‎CONFIG.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Configuration options
2+
The configuration file is a TOML file with the following sections:
3+
4+
## `project`
5+
- `name`: Project name.
6+
- `version`: Project version.
7+
8+
## `input`
9+
- `glob`: Glob to use for finding documented files.
10+
- `compiler_arguments`: List of arguments to pass to libclang while parsing code.
11+
12+
13+
## `output`
14+
- `static_dir`: Path to a directory containing static files that will be copied in the output directory, this is where `style.css` will typically be located.
15+
- `path`: Path to the output directory.
16+
- `root_namespace` (optional): Namespace to use as the root, this is useful for libraries that only globally expose one namespace and want the index to be based on that namespace.
17+
- `base_url`: Base URL to prepend all paths with.
18+
19+
## `pages`
20+
- `index` (optional): Markdown file to use as the index file, if an index page is not specified, the root namespace's comment will be used instead.
21+
- `extra` (optional): List of file paths to serve as extra documentation pages.
22+
23+
## `doctests` (optional)
24+
- `enable`: Whether to enable documentation tests or not.
25+
- `run`: Whether to run documentation tests or not (if disabled, tests will only be compiled).
26+
- `compiler_invocation`: Compiler invocation to use to compile documentation tests, this is represented as an array containing `argv`. The sentinel values `{file}` and `{out}` are replaced at runtime by the appropriate values.
27+
28+
29+
# Example
30+
31+
```toml
32+
[project]
33+
name = "Example"
34+
version = "0.1.0"
35+
36+
[input]
37+
glob = "include/**/*.hpp"
38+
compiler_arguments = ["-Iinclude", "-std=gnu++20", "-xc++"]
39+
40+
[pages]
41+
index = "README.md"
42+
extra = ["extra-page.md"]
43+
44+
[output]
45+
static_dir = "static"
46+
path = "docs"
47+
base_url = "/cppdoc"
48+
49+
[doctests]
50+
enable = false
51+
run = true
52+
compiler_invocation = ["clang++", "{file}", "-o", "{out}", "-Iinclude", "-std=c++20"]
53+
```
54+

‎README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,20 @@ cppdoc is a C++ documentation generator inspired by `rustdoc`
1010
- libclang-based parser with support for records, enums, functions and namespaces
1111
- Fair performance, with generation usually being faster than clang-backed Doxygen
1212

13+
## Usage
14+
See [USAGE.md](USAGE.md)
15+
1316
## Preview
14-
Screenshot soon :tm:
17+
There is a live demo available [here](https://rdmsr.github.io/cppdoc).
18+
19+
Here is what cppdoc looks like with three different stylesheets:
20+
21+
`example/static/light.css`:
22+
![light preview](assets/light-preview.png)
23+
24+
`example/static/ayu.css`:
25+
![ayu preview](assets/ayu-preview.png)
26+
27+
`example/static/gruvbox.css`:
28+
![gruvbox preview](assets/gruvbox-preview.png)
29+

‎USAGE.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Usage
2+
Projects using `cppdoc` must have a `cppdoc.toml` configuration file, see [CONFIG.md](CONFIG.md) for the available configuration options.
3+
4+
## Command-line options:
5+
To build documentation for a project:
6+
7+
```
8+
cppdoc build
9+
```
10+
11+
To output JSON representing the codebase:
12+
13+
```
14+
cppdoc build -d
15+
```
16+
17+
More command-line options can be displayed using `-h` or `--help`.
18+
19+
20+
## Comments
21+
Comments are written using `///` or `//<`, the latter being used for inline documentation, as such:
22+
23+
```cpp
24+
/// Documentation for 'MyEnum'
25+
enum MyEnum {
26+
A //< Documentation for 'A'
27+
}
28+
```
29+
30+
Comments content are parsed as cppdoc-flavored markdown, there is no support for `javadoc`/Doxygen-style comments.
31+
32+
## Markdown syntax
33+
`cppdoc` introduces a few extensions to markdown.
34+
35+
- To link documentation objects, one must prefix the link path with `::`. For example:
36+
37+
```
38+
See [MyStruct](::MyStruct)
39+
```
40+
41+
- Mermaid graphs can be displayed using `mermaid` codeblocks:
42+
43+
```mermaid
44+
graph TD;
45+
A-->B;
46+
A-->C;
47+
B-->D;
48+
C-->D;
49+
```
50+
51+
## Documentation tests
52+
`cppdoc` supports running documentation tests akin to `rustdoc`, these tests are written in `cpp` and `c++` codeblocks and help ensure that code examples are up-to-date with API usage.
53+
54+
Documentation codeblocks feature special syntax:
55+
- Lines prefixed with `@` won't be displayed, but will be added to the source code:
56+
57+
```
58+
@int a = 1;
59+
int b = a + 2;
60+
```
61+
62+
Will only display:
63+
64+
```
65+
int b = a + 2;
66+
```
67+
68+
But will be compiled fully, that is with `int a = 1` included.
69+
70+
71+
- Similarly, `@include` allows for quiet inclusion of a header file:
72+
73+
```
74+
@include "file.h"
75+
int a = 1;
76+
```
77+
78+
Will only display:
79+
80+
```
81+
int a = 1;
82+
```
83+
84+
Notice that documentation tests don't need a `main` function, this is because documentation tests run by default in `main`, to disable this behavior one must set the codeblock language to `nomain` instead of `c++` or `cpp`.
85+
86+
87+
### Test framework
88+
`cppdoc` includes a basic test framework for documentation tests, this is useful for testing that examples still run successfully.
89+
The following macros are defined:
90+
91+
- `ASSERT` and `ASSERT_EQ`: test for truth and equality, respectively
92+
- `ASSERT_FALSE` and `ASSERT_NE`: test for falsity and inequality, respectively
93+
- `ASSERT_GT` and `ASSERT_LT`: test for greater than and less than, respectively
94+
- `ASSERT_GE` and `ASSERT_LE`: test for greater than or equal and less than or equal, respectively
95+
96+
Therefore, it is possible to write code like so:
97+
98+
```c++
99+
int a = 1;
100+
101+
ASSERT(a == 1);
102+
```
103+
104+
The code above will compile and run successfuly, but the following code will fail to run:
105+
106+
```c++
107+
int a = 2;
108+
ASSERT(a == 1);
109+
```
110+
111+
112+
# Styling
113+
`cppdoc` expects a `style.css` file to be present at the root of the generated documentation. It is recommended to put the stylesheets in a static directory and set the `static` option in the configuration file.

‎assets/ayu-preview.png

50.5 KB
Loading

‎assets/gruvbox-preview.png

49.4 KB
Loading

‎assets/light-preview.png

40 KB
Loading

‎assets/stylesheets/ayu.css

-96
This file was deleted.

‎assets/stylesheets/gruvbox.css

-134
This file was deleted.

‎assets/stylesheets/style.css

-224
This file was deleted.

‎example/static/style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "light.css";
1+
@import "ayu.css";
22

33
body {
44
font-family: var(--font-secondary);
@@ -224,4 +224,4 @@ div.sidebar a {
224224
.item-table .item-desc * {
225225
margin-left: 20px;
226226
}
227-
}
227+
}

0 commit comments

Comments
 (0)
Please sign in to comment.