@@ -296,15 +296,18 @@ defmodule Mix.Tasks.Docs do
296
296
### Grouping functions, types, and callbacks
297
297
298
298
Types, functions, and callbacks inside a module can also be organized in groups.
299
- By default, ExDoc respects the `:group` metadata field:
299
+
300
+ #### Group metadata
301
+
302
+ By default, ExDoc respects the `:group` metadata field to dertermine in which
303
+ group an element belongs:
300
304
301
305
@doc group: "Queries"
302
306
def get_by(schema, fields)
303
307
304
308
The function above will be automatically listed under the "Queries" section in
305
309
the sidebar. The benefit of using `:group` is that it can also be used by tools
306
- such as IEx during autocompletion. These groups are then ordered alphabetically
307
- in the sidebar.
310
+ such as IEx during autocompletion. These groups are then displayed in the sidebar.
308
311
309
312
It is also possible to tell ExDoc to either enrich the group metadata or lookup a
310
313
different field via the `:default_group_for_doc` configuration. The default is:
@@ -322,9 +325,8 @@ defmodule Mix.Tasks.Docs do
322
325
end
323
326
end
324
327
325
- Whenever using the `:group` key, the groups will be ordered alphabetically.
326
- If you also want control over the group order, you can also use the `:groups_for_docs`
327
- which works similarly as the one for modules/extra pages.
328
+ Finally, you can also use the `:groups_for_docs` which works similarly as the
329
+ one for modules/extra pages.
328
330
329
331
`:groups_for_docs` is a keyword list of group titles and filtering functions
330
332
that receive the documentation metadata and must return a boolean.
@@ -358,6 +360,51 @@ defmodule Mix.Tasks.Docs do
358
360
then falls back to the appropriate "Functions", "Types" or "Callbacks"
359
361
section respectively.
360
362
363
+ #### Group descriptions
364
+
365
+ It is possible to display a description for each group under its respective section
366
+ in a module's page. This helps to better explain what is the intended usage of each
367
+ group elements instead of describing everything in the displayed `@moduledoc`.
368
+
369
+ Descriptions can be provided as `@moduledoc` metadata. Groups without descriptions are
370
+ also supported to define group ordering.
371
+
372
+ @moduledoc groups: [
373
+ "Main API",
374
+ %{title: "Helpers", description: "Functions shared with other modules."}
375
+ ]
376
+
377
+ Descriptions can also be given in the `:default_group_for_doc` configuration:
378
+
379
+ default_group_for_doc: fn metadata ->
380
+ csae metadata[:group] do
381
+ :main_api -> "Main API"
382
+ :helpers -> [title: "Helpers", description: "Functions shared with other modules."]
383
+ _ -> nil
384
+ end
385
+ end
386
+
387
+ Keyword lists or maps are supported in either case.
388
+
389
+ When using `:groups_for_docs`, if all the elements for a given group are matched then the
390
+ `:default_group_for_doc` is never invoked and ExDoc will not know about the description.
391
+ In that case, the description should be provided in the `@moduledoc` `:groups` metadata.
392
+
393
+ Whenever using the `:group` key, the groups will be ordered alphabetically.
394
+ If you also want control over the group order, you can also use the `:groups_for_docs`
395
+ which works similarly as the one for modules/extra pages.
396
+
397
+ #### Group ordering
398
+
399
+ Groups in the sidebar and main page body are ordered according to the following
400
+ rules:
401
+
402
+ * First, groups defined as `@moduledoc groups: [...]` in the given order.
403
+ * Then groups defined as keys in the `:groups_for_docs` configuration.
404
+ * Then default groups: Types, Callbacks and Functions.
405
+ * Finally, other groups returned by `:default_group_for_doc` by alphabetical
406
+ order.
407
+
361
408
## Meta-tags configuration
362
409
363
410
It is also possible to configure some of ExDoc behaviour using meta tags.
0 commit comments