Skip to content

Commit

Permalink
Add example of doc generation with metaprogramming (JuliaLang#15363)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Apr 30, 2020
1 parent f5103cd commit 704fd8a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/src/manual/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,23 @@ end
will add documentation to `f(x)` when `condition()` is `true`. Note that even if `f(x)` goes
out of scope at the end of the block, its documentation will remain.

It is possible to make use of metaprogramming to assist in the creation of documentation.
When using string-interpolation within the docstring you will need to use an extra `$` as
shown with `$($name)`:

```julia
for func in (:day, :dayofmonth)
name = string(func)
@eval begin
@doc """
$($name)(dt::TimeType) -> Int64
The day of month of a `Date` or `DateTime` as an `Int64`.
""" $func(dt::Dates.TimeType)
end
end
```

### Dynamic documentation

Sometimes the appropriate documentation for an instance of a type depends on the field values of that
Expand Down

0 comments on commit 704fd8a

Please sign in to comment.