Guide for templates based on specified requirements
I need to generate docs for contracts with next requirements:
- All documented methods from base class should be inside derived class.
- All methods with keyword
internalandprivateshouldn't be inside generated docs - Function modifiers shouldn't be inside docs.
Is it possible? Should I use option -t templates_dir? Where can I find the guide of designing templates
Hi @sergorl! Thanks for asking. I haven't been able to write a guide yet, so the best I can offer is my help.
You should definitely use the -t option, and its argument should be a path to a directory where you will place the template called contract.hbs.
You can do all of these things in your template. You have several options, perhaps the easiest way is to use the functions and events arrays. Each will contain all of the functions/events including the inherited ones. For example:
{{#each functions}}
# {{signature}}
{{natspec.userdoc}}
{{/each}}
If you would like to hide internal and private members you can use a function/events's visibility field, and the eq helper, like so:
{{#each functions}}
{{#unless (eq visibility "internal")}}
# {{name}}
{{natspec.userdoc}}
{{/unless}}
{{/each}}
(Note that private functions are never included, because they are never part of the interface. So the code above will show both public and external functions.)
Unfortunately there is no reference document with the available fields you can use in your template, but you will find them all in this source file.
If you need more help just let me know.
Hi,
Here is the template I use:
# {{natspec.title}}
{{natspec.userdoc}}
{{natspec.devdoc}}
{{#each functions}}
## {{signature}}
{{natspec.userdoc}}
{{natspec.devdoc}}
**Params**
{{#each natspec.params}}
- `{{param}}`: {{description}}
{{/each}}
**Returns**
{{#each natspec.returns}}
- `{{param}}`: {{description}}
{{/each}}
{{/each}}
{{#each events}}
## `event` {{signature}}
{{natspec.userdoc}}
{{natspec.devdoc}}
**Params**
{{#each natspec.params}}
- `{{param}}`: {{description}}
{{/each}}
{{/each}}
If you would like to hide internal and private members you can use a function/events's
visibilityfield, and theeqhelper, like so:
@frangio There is no helper eq registered it seems
Never mind, I realised we can set our own helper with an helpers.ts in the template folder
Never mind, I realised we can set our own helper with an helpers.ts in the template folder
can you share your setup for this? i am also trying to register eq. did you include handlebars as a dependency?
@d1onys1us I've added the eq helper by default in the latest release. Feel free to share a link to a repo if you need further help I can take a look.