Skip to content

Commit d0c028e

Browse files
authored
Add showcase page to manual (#78)
1 parent c061537 commit d0c028e

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

docs/Showcase/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Showcase.jl
2+
3+
The demo library for DocStringExtensions.

docs/Showcase/src/Showcase.jl

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
This docstring is attached to the [`Showcase`](@ref) module itself.
3+
4+
The [`EXPORTS`](@ref) abbreviation creates a bulleted list of all the exported names:
5+
6+
$(EXPORTS)
7+
8+
Similarly, the [`IMPORTS`](@ref) abbreviation lists all the imported modules:
9+
10+
$(IMPORTS)
11+
12+
The [`README`](@ref) can be used to include the `README.md` file in a docstring. The content
13+
between the horizontal lines is spliced by the abbreviation:
14+
15+
---
16+
17+
$(README)
18+
19+
---
20+
21+
The [`LICENSE`](@ref) abbreviation can be used in the same way for the `LICENSE.md` file.
22+
"""
23+
module Showcase
24+
using DocStringExtensions
25+
26+
"""
27+
This docstring is attached to an [empty function
28+
definitions](https://docs.julialang.org/en/v1/manual/methods/#Empty-generic-functions-1).
29+
The [`METHODLIST`](@ref) abbreviation allows you to list all the methods though:
30+
31+
$(METHODLIST)
32+
"""
33+
function foo end
34+
35+
"""
36+
This docstring is attached to a method that uses default values for some positional
37+
arguments: `foo(x::Int, y=3)`.
38+
39+
As this effectively means that there are two different methods taking different numbers of
40+
arguments, the [`SIGNATURES`](@ref) abbreviation produces the following result:
41+
42+
$(SIGNATURES)
43+
44+
---
45+
46+
The [`TYPEDSIGNATURES`](@ref) abbreviation can be used to also get the types of the
47+
variables in the function signature:
48+
49+
$(TYPEDSIGNATURES)
50+
51+
---
52+
53+
The [`FUNCTIONNAME`](@ref) abbreviation can be used to directly include the name of the
54+
function in the docstring (e.g. here: $(FUNCTIONNAME)). This can be useful when writing your
55+
own type signatures:
56+
57+
$(FUNCTIONNAME)(x, ...)
58+
"""
59+
foo(x::Int, y=3) = nothing
60+
61+
"""
62+
A different method for [`$(FUNCTIONNAME)`](@ref). [`SIGNATURES`](@ref) abbreviation:
63+
64+
$(SIGNATURES)
65+
66+
And the [`TYPEDSIGNATURES`](@ref) abbreviation:
67+
68+
$(TYPEDSIGNATURES)
69+
"""
70+
foo(x::AbstractString) = nothing
71+
72+
73+
"""
74+
The [`TYPEDEF`](@ref) abbreviation includes the type signature:
75+
76+
$(TYPEDEF)
77+
78+
---
79+
80+
The [`FIELDS`](@ref) abbreviation creates a list of all the fields of the type.
81+
If the fields has a docstring attached, that will also get included.
82+
83+
$(FIELDS)
84+
85+
---
86+
87+
[`TYPEDFIELDS`](@ref) also adds in types for the fields:
88+
89+
$(TYPEDFIELDS)
90+
"""
91+
struct Foobar{T <: AbstractString}
92+
"Docstring for the `x` field."
93+
x :: Nothing
94+
y :: T # y is missing a docstring
95+
"Docstring for the `z` field."
96+
z :: Vector{T}
97+
end
98+
99+
export foo, Foobar
100+
101+
end

docs/make.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
# Add docs/lib to LOAD_PATH so that we could load the Showcase module like a library.
2+
let doclib = abspath(joinpath(@__DIR__, "Showcase", "src"))
3+
doclib in LOAD_PATH || pushfirst!(LOAD_PATH, doclib)
4+
end
5+
16
using Documenter, DocStringExtensions
7+
import Showcase
28

39
makedocs(
410
sitename = "DocStringExtensions.jl",
5-
modules = [DocStringExtensions],
11+
modules = [DocStringExtensions, Showcase],
612
clean = false,
7-
pages = Any["Home" => "index.md"],
13+
pages = Any[
14+
"Home" => "index.md",
15+
"Showcase" => "showcase.md",
16+
],
817
format = Documenter.HTML(
918
assets = ["assets/favicon.ico"],
1019
),

docs/src/showcase.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Showcase
2+
3+
```@meta
4+
CurrentModule = Showcase
5+
```
6+
7+
This page shows how the various abbreviations look.
8+
The docstrings themselves can be found in `docs/Showcase/src/Showcase.jl`.
9+
10+
## Modules
11+
12+
```@docs
13+
Showcase
14+
```
15+
16+
## Functions and methods
17+
18+
```@docs
19+
foo
20+
foo(::Int)
21+
foo(::String)
22+
```
23+
24+
## Types
25+
26+
```@docs
27+
Foobar
28+
```

0 commit comments

Comments
 (0)