Skip to content

Instantly share code, notes, and snippets.

@thufschmitt
Created October 27, 2023 15:34
Show Gist options
  • Save thufschmitt/77dccf6b0831a6c84e69cc9ca49410eb to your computer and use it in GitHub Desktop.
Save thufschmitt/77dccf6b0831a6c84e69cc9ca49410eb to your computer and use it in GitHub Desktop.
Quick and dirty doc generator for Nickel
let lib = {
handle_record_field = fun rec_name { fields, type, contracts, documentation } =>
m%"
<details>
<summary>%{rec_name}</summary>
<div style="margin-left:12px">
%{if documentation != null then documentation else "_no documentation_"}
%{if type != null then "- *type*: %{type}" else ""}
%{if contracts != [] then "- *contracts*:\n%{
contracts
|> std.array.map (fun x => " - %{x}")
|> std.string.join "\n"
}" else ""}
%{handle_record fields}
</div>
</details>
"%,
handle_record = fun record =>
if record == null then "" else
record
|> std.record.map handle_record_field
|> std.record.values
|> std.string.join "\n"
}
in
let json_doc = import ".nickel/doc/organist.json" in
json_doc
|> lib.handle_record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment