Skip to content

Commit

Permalink
Writing TOCs
Browse files Browse the repository at this point in the history
  • Loading branch information
adoble committed Oct 25, 2024
1 parent 0b2b30f commit 658e487
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
75 changes: 75 additions & 0 deletions doc/usage/Writing_TOC_Templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Writing a Template for a Table of Contents.

Users can write their own templates for a table for contents (TOC) and specify that they should be used for TOCS by using `config` command or directly using the `-template`option, e.g.:

```
adr generate toc -template [My TOC Template]
```

Templates for table of contents use the [handlebars syntax](https://handlebarsjs.com/). Only a subset of this is described here. The fields available when generating TOCs are show in [ADR-J fields for TOCs](#adr-j-fields-for-tocs).

## Example TOC Template

An example for a TOC template using the handlebars syntax is:

```markdown
# List of ADRs

{{#entries}}
* [ADR {{id}}]({{filename}}) : {{title}}
{{/entries}}

Created: {{date}}
```


## Field substitution

`{{field}}` is substituted with the value of `field`, e.g.

```
* Created: {{date}}
```
After substitution this could look like:

```
* Created: 21 Oct 2024
```

Note the the date format depended on the `adr-j`configuration.

## List substitution

To iterate over the list of ADRs use the `{{#entries}}` and `{{/entries}}` helpers. Any fields within this pair will refer to an ADR. For instance:

```
{{#entries}}
* ADR {{id}}
{{/entries}}
```
could return a list of the ADRs identifiers:

```
- ADR 1
- ADR 2
- ADR 3
- ADR 4
```


# ADR-J Fields for TOCs

The following fields are used in generating TOCs:

| Name | Type | Description |
| ---- | ---- | ----------- |
| `id` | field| The identifier of the ADR |
| `filename` | field| The file name of the ADR |
| `title` | field| The title of the ADR |
| `date`| field | The current date |
| `entries` | iterator | Iterator over each ADR |



##

5 changes: 4 additions & 1 deletion doc/usage/Writing_Templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Users can write their own templates for the architecture decision records and sp

Templates use their own markup for specifying the substitutions the `adr-j` tool uses.

> [!NOTE]
> Templates for table of contents (TOCs) use a different format. See [Writing TOC Templates](Writing_TOC_Templates.md).
## Field substitution

`{{field}}` is substituted with the value of `field`, e.g.
Expand Down Expand Up @@ -43,7 +46,7 @@ The reasons the above is **not** valid are:
* No link.id field
* Fields are on separate lines.

## ADR-J fields
## ADR-J fields for ADRs

### `id`

Expand Down

0 comments on commit 658e487

Please sign in to comment.