Skip to content

Commit 77c00d3

Browse files
committed
[docs] improvements
1 parent 6268626 commit 77c00d3

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

README.md

+32-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
Features:
2323
- **Customizable** output styles.
24-
- Call your own module's code within the docstring, e.g., to **render examples**.
24+
- Automatically [**render code examples**](#example).
2525
- **Annotate types** of parameters and return values.
2626
- Automatically read off default values for named parameters.
27-
- **Help** feature for your package.
28-
- Docstring tests.
27+
- [**Help** feature](#generate-a-help-command-for-you-package) for your package.
28+
- [Docstring tests](#docstring-tests).
2929

3030

3131
The [guide](./docs/tidy-guide.pdf) fully describes the usage of this module and defines the format for the docstrings.
@@ -81,6 +81,35 @@ The code in the docstrings is evaluated via `eval()`. In order to access user-de
8181
```
8282
The docstrings in `my-module.typ` may now access the image with `#img` and can call any function or variable from `my-module` in the style of `#my-module.my-function()`. This makes rendering examples right in the docstrings as easy as a breeze!
8383

84+
## Generate a help command for you package
85+
With **tidy**, you can add a help command to you package that allows users to obtain the documentation of a specific definition or parameter right in the document. This is similar to CLI-style help commands. If you have already written docstrings for your package, it is quite low-effort to add this feature. Once set up, the end-user can use it like this:
86+
87+
```typ
88+
// happily coding, but how do I use this one complex function again?
89+
90+
#mypackage.help("func")
91+
#mypackage.help("func(param1)") // print only parameter description of param1
92+
```
93+
94+
This will print the documentation of `func` directly into the document — no need to look it up in a manual. Read up in the [guide](./docs/tidy-guide.pdf) for setup instructions.
95+
96+
## Docstring tests
97+
It is possible to add simple docstring tests — assertions that will be run when the documentation is generated. This is useful if you want to keep small tests and documentation in one place.
98+
```typ
99+
/// #test(
100+
/// `num.my-square(2) == 4`,
101+
/// `num.my-square(4) == 16`,
102+
/// )
103+
#let my-square(n) = n * n
104+
```
105+
With the short-hand syntax, a unfulfilled assertion will even print the line number of the failed test:
106+
```typ
107+
/// >>> my-square(2) == 4
108+
/// >>> my-square(4) == 16
109+
#let my-square(n) = n * n
110+
```
111+
A few test assertion functions are available to improve readability, simplicity, and error messages. Currently, these are `eq(a, b)` for equality tests, `ne(a, b)` for inequality tests and `approx(a, b, eps: 1e-10)` for floating point comparisons. These assertion helper functions are always available within docstring tests (with both `test()` and `>>>` syntax).
112+
84113

85114
## Changelog
86115

docs/tidy-guide.typ

+23-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ As alternative to using `test()`, the following dedicated shorthand syntax can b
388388

389389
When using the shorthand syntax, the error message even shows the line number of the failed test in the corresponding module.
390390

391-
A few test assertation functions are available to improve readability, simplicity and error messages. Currently, these are `eq(a, b)` for equality tests, `ne(a, b)` for inequality tests and `approx(a, b, eps: 1e-10)` for floating point comparisons. These assertation helper functions are always available within docstring tests (with both `test()` and `>>>` syntax).
391+
A few test assertion functions are available to improve readability, simplicity and error messages. Currently, these are `eq(a, b)` for equality tests, `ne(a, b)` for inequality tests and `approx(a, b, eps: 1e-10)` for floating point comparisons. These assertion helper functions are always available within docstring tests (with both `test()` and `>>>` syntax).
392392

393393
Docstring tests can be disabled by passing `enable-tests: false` to #ref-fn("show-module()").
394394

@@ -423,3 +423,25 @@ Let us now "self-document" this package:
423423
omit-private-definitions: true
424424
)
425425
}
426+
427+
= End
428+
429+
#tidy.help("show-module()")
430+
#tidy.help("parse-module()")
431+
#tidy.help("parse-module(label-prefix)")
432+
433+
434+
435+
#pagebreak()
436+
#disable-codly()
437+
438+
#import "/examples/sincx.typ"
439+
440+
#let docs = tidy.parse-module(
441+
read("/examples/sincx.typ"),
442+
scope: (sincx: sincx),
443+
preamble: "#import sincx: *;"
444+
)
445+
446+
#set heading(numbering: none)
447+
#block(width: 10cm, tidy.show-module(docs, show-outline: false))

0 commit comments

Comments
 (0)