Skip to content

Commit e754276

Browse files
committed
Finish documentation
1 parent 551b283 commit e754276

25 files changed

Lines changed: 246 additions & 111 deletions

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# mkdocstrings-crystal
22

3-
[Crystal][] language doc generator for [MkDocs][], via [mkdocstrings][].
3+
**[Crystal][] language doc generator for [MkDocs][], via [mkdocstrings][].**
44

55
[![PyPI](https://img.shields.io/pypi/v/mkdocstrings-crystal)](https://pypi.org/project/mkdocstrings-crystal/)
66
[![GitHub](https://img.shields.io/github/license/oprypin/mkdocstrings-crystal)](LICENSE.md)
77
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/oprypin/mkdocstrings-crystal/CI)](https://github.com/oprypin/mkdocstrings-crystal/actions?query=event%3Apush+branch%3Amaster)
88

9-
[crystal]: https://crystal-lang.org/
10-
[mkdocs]: https://www.mkdocs.org/
11-
[mkdocstrings]: https://pawamoy.github.io/mkdocstrings/
12-
[virtualenv]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment
13-
149
## Introduction
1510

1611
*mkdocstrings-crystal* allows you to insert API documentation (generated from [Crystal][]'s source code and doc comments) as part of any page on a [MkDocs][] site.
@@ -21,6 +16,8 @@ To install it, run (possibly in a [virtualenv][]):
2116
pip install mkdocstrings-crystal
2217
```
2318

19+
**Continue to the [documentation site][].**
20+
2421
## Usage
2522

2623
With [MkDocs][], add/merge this base config as your _mkdocs.yml_:
@@ -59,3 +56,12 @@ This, of course, happens as part of a normal MkDocs build process:
5956
mkdocs build # generate from docs/ into site/
6057
mkdocs serve # live preview
6158
```
59+
60+
**Continue to the [documentation site][].**
61+
62+
63+
[crystal]: https://crystal-lang.org/
64+
[mkdocs]: https://www.mkdocs.org/
65+
[mkdocstrings]: https://pawamoy.github.io/mkdocstrings/
66+
[virtualenv]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment
67+
[documentation site]: https://oprypin.github.io/mkdocstrings-crystal/

docs/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Crystal language doc generator for [MkDocs][], via [mkdocstrings][].
88
$ pip install mkdocstrings-crystal
99
```
1010

11-
[Continue with **quickstart**](quickstart/README.md).
11+
[Continue with **quickstart**](quickstart/index.md).
1212

1313
## Introduction
1414

15-
Crystal has [its own easy-to-use generator of API documentation sites](https://crystal-lang.org/reference/using_the_compiler/#crystal-docs), but it's very rigid, as it doesn't attempt to do anything other than API documentation, so [these sites](https://crystal-lang.org/api/) end up being very isolated and prevent the author from presenting some kind of *story* about using their library.
15+
Crystal has [its own easy-to-use generator of API documentation sites](https://crystal-lang.org/reference/using_the_compiler/#crystal-docs), but it's very rigid, as it doesn't attempt to do anything other than API documentation, so [these sites](https://crystal-lang.org/api/0.35.1/Process.html) end up being very isolated and prevent the author from presenting some kind of *story* about using their library.
1616

1717
Instead, this plugin is all about that *story*. It's very inspiring to look at [Python's documentation for `subprocess`](https://docs.python.org/3/library/subprocess.html), and hard to imagine a world in which this document is just an alphabetic dump of the functions in it.
1818

@@ -51,7 +51,9 @@ Then, in any `docs/**/*.md` file, you can **mention a Crystal identifier alone o
5151

5252
-- and in the output this will be replaced with generated API documentation for it, much like Crystal's own doc generator does.
5353

54-
This, of course, happens as part of a normal MkDocs build process:
54+
Learn more about this syntax: [in *mkdocstrings* in general](https://pawamoy.github.io/mkdocstrings/usage/) (Crystal specifics are below).
55+
56+
The auto-replacement, of course, happens as part of a normal MkDocs build process:
5557

5658
```console
5759
$ mkdocs build # generate from docs/ into site/
@@ -66,7 +68,7 @@ But another powerful feature of this plugin is that you can **[cross-reference](
6668

6769
## Usage details
6870

69-
We have been talking about seamlessly inserting Crystal documentation, but where is it coming from? The implementation actually still uses `crystal doc` generator but through [its JSON output](https://github.com/crystal-lang/crystal/pull/4746). So the requirement is the same: the source code that the doc comments and signatures are coming from is assumed to be somewhere under the _src/_ directory. If that isn't appropriate, you can select the wanted entry files by passing them to `crystal doc`, as part of [`crystal_docs_flags`](configuration.md#crystal_docs_flags) ([example](https://github.com/oprypin/athena-website/blob/c06906d5933421120c76e15fd6f529eeb5c48221/mkdocs.yml#L33)).
71+
We have been talking about seamlessly inserting Crystal documentation, but where is it coming from? The implementation actually still uses `crystal doc` generator but through [its JSON output](https://github.com/crystal-lang/crystal/pull/4746). So the requirement is the same: the source code that the doc comments and signatures are coming from is assumed to be somewhere under the _src/_ directory. If that isn't appropriate, you can select the wanted entry files by passing them to `crystal doc`, as part of [`crystal_docs_flags`](configuration.md#crystal_docs_flags) (see "Custom source directories" [in Showcase](showcase.md#athena-framework)).
7072

7173
Continue to [Configuration](configuration.md).
7274

docs/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Handler options
44

5-
(See also: [mkdocstrings global options](https://pawamoy.github.io/mkdocstrings/usage/#global-options))
5+
(See also: [*mkdocstrings* global options](https://pawamoy.github.io/mkdocstrings/usage/#global-options))
66

77
### `crystal_docs_flags:`
88

@@ -16,7 +16,7 @@ A list of command line arguments to pass to `crystal doc`. Mainly used to choose
1616
: Set to `true` to also recursively render all `Foo::Sub::Types` whenever rendering a given class `Foo`.
1717

1818
`file_filters:` [list of strings]
19-
: If a particular module spans over several files, you might want to choose to render only the sub-items (see `nested_types`) that came from a particular file. These patterns ared regular expressions (not anchored) applied to the file path. Negating the patterns is done by starting it with `!` (which is then excluded from the following regex).
19+
: If a particular module spans over several files, you might want to choose to render only the sub-items (see `nested_types`) that came from a particular file. These patterns are regular expressions (not anchored) applied to the file path. Negating the patterns is done by starting it with `!` (which is then excluded from the following regex). This is very similar to [what's done in *mkdocstrings*](https://pawamoy.github.io/mkdocstrings/reference/handlers/python/#mkdocstrings.handlers.python.PythonCollector.default_config)
2020

2121
### `rendering:`
2222

docs/extras.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ These are the built-in mogrifier implementations:
4545

4646
[Browse the API exposed by the root `DocType`](api.md).
4747

48-
## Support for [MkDocs "gen-files" plugin](https://github.com/oprypin/mkdocs-gen-files)
48+
## Support for [MkDocs "gen-files" plugin](https://oprypin.github.io/mkdocs-gen-files)
4949

5050
There's no special support, these just work well together.
5151

docs/quickstart/README.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

docs/quickstart/ci.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
You can publish the website
1+
# Continuous build and publishing
22

3-
```yaml linenums="1" hl_lines="2 13 17 19 23"
4-
--8<-- "examples/modern/.github/workflow/deploy-docs.yml"
5-
```
3+
You can build and publish the website automatically on push using GitHub Pages and GitHub Actions. Here's our recommendation:
64

7-
???+ question "Why configure like this"
8-
Crystal Nightly is needed because this plugin relies on some improvements to Crystal's doc generator that haven't made it into a release yet.
5+
???+ example ".github/workflows/deploy-docs.yml"
6+
```yaml linenums="1" hl_lines="2 13 17 19 23"
7+
--8<-- "examples/simple/.github/workflows/deploy-docs.yml"
8+
```
99

10+
???+ question "Why configure like this"
11+
* Do *not* disable the workflow for non-*master* branches or pull requests. It is nice to ensure that the site builds (there can be errors!), instead at the bottom we prevent only the actual *deploy* action from being executed on non-*master*/non-*pushes*.
12+
* Crystal Nightly is needed because this plugin relies on some improvements to Crystal's doc generator that haven't made it into a release yet.
13+
* Dependencies are installed from `requirements.txt`. Make sure you've [populated it](python-dependencies.md).
1014

1115
!!! tip
1216
You can freely have a "dev" branch for working on docs that aren't ready for release yet. Then just merge it into the main one when ready.
1317

1418
!!! tip
15-
Your docs don't have to be in the same repository as the main code. In fact, the doc site can span several projects! See [Athena's website](https://github.com/oprypin/athena-website) as an example (of particular interest are `mkdocs.yml` (`crystal_docs_flags:`) and `shard*` files.
19+
Your docs don't have to be in the same repository as the main code. In fact, the doc site can span several projects! See "Multi-repo setup" [in Showcase](../showcase.md#athena-framework).

docs/quickstart/index.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Quick-start guide
2+
3+
This assumes you already have some project in Crystal, say, a file `src/foo.cr`.
4+
5+
??? example "src/foo.cr"
6+
```crystal
7+
--8<-- "examples/simple/src/foo.cr"
8+
```
9+
10+
Hosting on GitHub is also assumed, though that's easy to adapt.
11+
12+
We'll be working from the project's root directory (the one that *contains* `src`).
13+
14+
[View the final file layout](https://github.com/oprypin/mkdocstrings-crystal/tree/master/examples/simple/)
15+
16+
## Dependencies
17+
18+
The dependencies that we'll be using can be installed like this:
19+
20+
```console
21+
$ pip install mkdocs-material mkdocstrings-crystal
22+
```
23+
24+
This assumes you have [Python][] installed, with `pip` available.
25+
26+
!!! tip
27+
You might want to install these in a [virtualenv][] (i.e. localized just to this project).
28+
29+
And check out how to **[manage Python dependencies](python-dependencies.md)** long-term.
30+
31+
## Base config
32+
33+
Let's configure [MkDocs][] with *mkdocstrings-crystal*. Add/merge this config as your `mkdocs.yml`:
34+
35+
???+ example "mkdocs.yml"
36+
```yaml
37+
--8<-- "examples/simple/mkdocs.yml"
38+
```
39+
40+
???+ question "Why configure like this"
41+
`theme:` `material`
42+
: [material](https://squidfunk.github.io/mkdocs-material/) is the only supported [MkDocs theme](https://www.mkdocs.org/user-guide/styling-your-docs/#third-party-themes).
43+
44+
`repo_url` and `icon`
45+
: Link back to your repository nicely. [See more](https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/).
46+
47+
`extra_css`
48+
: Don't forget to copy and include the [recommended styles](../styling.md#recommended-styles).
49+
50+
`mkdocstrings:` `default_handler: crystal`
51+
: Activate the upstream *mkdocstrings* plugin and tell it to collect items from Crystal, not Python, by default.
52+
53+
`watch: [src]`
54+
: Watch a directory for [auto-reload](https://pawamoy.github.io/mkdocstrings/usage/#watch-directories). Assuming the sources are under `src/`.
55+
56+
[`pymdownx.*` extensions](https://facelessuser.github.io/pymdown-extensions/)
57+
: Python-Markdown is an "old-school" Markdown parser, and these extensions bring the defaults more in line with what people are used to now.
58+
59+
`deduplicate-toc` extension
60+
: This is actually an integral part of *mkdocstrings-crystal*. [Read more](../extras.md#deduplicate-toc-extension).
61+
62+
## Add an API doc page
63+
64+
???+ example "docs/api.md"
65+
```md
66+
--8<-- "examples/simple/docs/api.md"
67+
```
68+
69+
## Add a normal page
70+
71+
???+ example "docs/index.md"
72+
```md
73+
--8<-- "examples/simple/docs/index.md"
74+
```
75+
76+
We linked directly to an identifier here, and *mkdocstrings* knows which page it's on and automatically links that. See: [identifier linking syntax](../README.md#identifier-linking-syntax).
77+
78+
## View the site
79+
80+
That's it -- we're ready!
81+
82+
```shell
83+
mkdocs build # generate from docs/ into site/
84+
mkdocs serve # live preview
85+
```
86+
87+
## Next steps
88+
89+
If you find that you have too many classes and you don't want to manually create files with callouts to them, there are ways to automate it, and good examples are in [the migration-oriented guide](migrate.md#base-config).
90+
91+
Otherwise, you're encouraged to curate per-topic pages with your API items. See "Manually curated docs page" [in Showcase](../showcase.md#crystal-chipmunk) for examples.
92+
93+
And you'll probably want to [set up a navigation config](https://www.mkdocs.org/user-guide/configuration/#documentation-layout) anyway.
94+
95+
96+
[mkdocs]: https://www.mkdocs.org/
97+
[python]: https://www.python.org/
98+
[virtualenv]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment

0 commit comments

Comments
 (0)