npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solidity-handlebars

v1.0.1

Published

Handlebar Templates for generating solidity contract interfaces and documentation

Downloads

5

Readme

solidity-handlebars

Handlebar Templates for generating solidity contract interfaces and documentation

Solidity DocGen

natspec source via @snreynolds

Documentation generator for smart contract libraries. Use the inline documentation in your Solidity code for generating websites or any sort of document.

The output is completely customizable through Handlebars templates that provide easy access to all the metadata of your smart contract.

Usage

npm install solidity-docgen

solidity-docgen takes as input a directory of contracts and README documents. This directory is specified using the --input/-i flag, defaulting to ./contracts. It produces a set of files that it will place in the output directory specified by --output/-o, defaulting to ./docs.

solidity-docgen [ -i <input-dir> ] [ -o <output-dir> ] [ -t <templates-dir> ]

Solidity 0.7

The built in compiler remains solc 0.6, but users who want to use the newer compiler version can do so by installing the desired solc version and using the flag --solc-module. Here's an example using npm aliases:

npm install -D solc-0.7@npm:solc@^0.7.0
npx solidity-docgen --solc-module solc-0.7

Example Handlebars Formatting

Each of the following examples will go through various methods exposed by the solidity-docgen library, how to use them in handlebars, and what the resulting markdown output would look like.

  1. Getting the natspec @dev and @notice tags

Handlebars formatting:

    {{{natspec.devdoc}}}

Markdown output:

This is the comment next to the @notice tag. This is the comment next to the @dev tag.

  1. Functions and Events Your handlebars template can check if the underlying contract code is a function or an event with {{#if ownFunctions}} and {{#if ownEvents}} respectively. This lets you generate different markdown depending on if the underlying natspec is for functions or events. Use {{ownFunctions}} and {{ownEvents}} to iterate over all functions and events in the contract respectively.

Handlebars formatting:

    ### Functions
    {{/if}}
    {{#ownFunctions}}
    - function {{name}}
    {{/ownFunctions}}
    {{/if ownFunctions}}

Markdown Output:

Functions

  • function example1
  • function example2
  • function example3
  1. Getting more data about a funcion

In 2. we saw how to iterate over the functions in a contract and each of the function names. Here is an example that gets more information related to a function including the input parameters, and visibility.

Handlebars formatting:

    ### Functions
    {{/if}}
    {{#ownFunctions}}
    #### function {{name}}
    Parameters:
    {{natspec.params}}
    - {{param}}
    {{/natspec.params}}
    Visibility:
    - {{visibility}}
    {{#if outputs}}
    Outputs:
    - {{outputs}}
    {{/if}}
    {{/ownFunctions}}
    {{/if ownFunctions}}

Markdown Output:

Functions

function example1

Parameters:

  • param1
  • param2 Visibliity:
  • external Outputs:
  • bool return1

function example2

Parameters:

  • param1
  • param2
  • param3 Visibliity:
  • internal Outputs:
  • uint128 return0, uint128 return1

function example3

Parameters:

  • param1 Visibliity:
  • external Outputs:
  • int24 return1
  1. Formatting a function signature The nice thing about handlebars templating is that it just populates data into a markdown format. So you can use any markdown syntax to arrange your data such that it looks pretty when the markdown is generated! (The below does some fancy handlebar manipulation that you don't really need to understand. It essentially is populating the types of the parameters so that the output in markdown looks like a function signature.)

Handlebars formatting:

### {{name}}
```solidity
  function {{name}}(
    {{#natspec.params}}
    {{#lookup ../args.types @index}}{{/lookup}} {{param}}{{#if @last}}{{else}},{{/if}}
    {{/natspec.params}}
  ) {{visibility}}{{#if outputs}} returns ({{outputs}}){{/if}}```

Markdown Output:

Here is what the output for the example1 function would look like.

example1

    function example1(
    int24 param1,
    int24 param2
  ) external returns (bool return1)