solidity-docgen icon indicating copy to clipboard operation
solidity-docgen copied to clipboard

Guide for templates based on specified requirements

Open sergorl opened this issue 6 years ago • 7 comments

I need to generate docs for contracts with next requirements:

  1. All documented methods from base class should be inside derived class.
  2. All methods with keyword internal and private shouldn't be inside generated docs
  3. 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

sergorl avatar Nov 13 '19 12:11 sergorl

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.)

frangio avatar Nov 13 '19 18:11 frangio

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.

frangio avatar Nov 13 '19 18:11 frangio

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}}

Thykof avatar Sep 14 '20 08:09 Thykof

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:

@frangio There is no helper eq registered it seems

wighawag avatar Nov 01 '22 11:11 wighawag

Never mind, I realised we can set our own helper with an helpers.ts in the template folder

wighawag avatar Nov 01 '22 12:11 wighawag

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?

dionysuzx avatar Dec 27 '22 18:12 dionysuzx

@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.

frangio avatar Dec 29 '22 20:12 frangio