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

leafleth

v0.0.9

Published

Documentation generator for Solidity

Downloads

16

Readme

📑 Leafleth

Leafleth is a documentation generator for your Solidity smart-contracts. It also integrates a template engine to allow anyone to create customized documentation in a snap.

Note: This tool is still in development and new fixes are pushed almost daily, I highly recommend you to update it every time you use it!

🎉 Example

This example was generated using the default template provided by Leafleth.

📦 Installation

You can install Leafleth as a global package:

Using npm:

npm i -g leafleth

Or using yarn:

yarn add global leafleth

Additionally, Leafleth can be installed as a local package in your project.

🚀 Usage

First of all, be sure to comment your smart-contracts according to the NatSpec format. Once you're done, compile your contracts and let Leafleth handle the rest!

Use the following command to generate your documentation:

leafleth -s <source>

The source is the only required option, and it must refer to the path of a .json file (a compiled contract) or to an entire directory (for example, the build/contracts directory if you are using Truffle).

🎛 Options

  • -s or --source (required): The path to a file or a directory, which will be used to generate the documentation.
  • -o or --output: The directory used to output the documentation. If no value is provided, Leafleth will output the documentation into the source directory.
  • -t or --template: The template used to generate the documentation. If no value is provided, the default template will be used.
  • -d or --debug: Enable debug mode.
  • -V or --version: Display the version number.
  • -h or --help: Display usage information.

🎨 Create your own themes

Internally, Leafleth uses Squirrelly for its template engine. This means that any type of documentation (Markdown, HTML, ...) can be generated if you provide the right template.

To create a new template, you can use the default one as a base or start a new .sqrl file from scratch. The content of the templates is totally free, and the only requirement is that they must be a valid Squirrelly template.

While generating the documentation, Leafleth will send the following object to your template:

{
  "contract": {
    "name": "BasicExample",
    "notice": "A notice for the basic contract",
    "title": "A basic contract",
    "details": "Some dev stuff for the basic contract",
    "author": "Clemlak",
    "networks": {
      "1574932643895": {
        "events": {},
        "links": {},
        "address": "0x4f6DEA8B720BFED4789229156F8d6FbA05572902",
        "transactionHash": "0xe0350f631339cf61cea08d168edcf3787829bf39825437fa9c1c3a4561de8b89"
      }
    }
  },
  "methods": {
    "setNumber": {
      "constant": false,
      "payable": true,
      "stateMutability": "payable",
      "type": "function",
      "outputs": [],
      "notice": "Sets a number",
      "details": "This is an external function",
      "author": "ClemLak",
      "params": {
        "newNumber": {
          "description": "The new value of the number",
          "type": "uint256"
        }
      }
    },
    "setNumberIfContractIsReady": {
      "constant": false,
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function",
      "outputs": [],
      "notice": "Sets a number if the contract is ready",
      "details": "This is an external function",
      "params": {
        "newNumber": {
          "description": "The new value of the number",
          "type": "uint256"
        }
      }
    },
    "getTwoNumbers": {
      "constant": true,
      "payable": false,
      "stateMutability": "pure",
      "type": "function",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "notice": "Gets two numbers",
      "details": "This function looks complex",
      "return": "A cool numberAnother cool number"
    },
    "add": {
      "constant": true,
      "payable": false,
      "stateMutability": "pure",
      "type": "function",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "notice": "Add two numbers",
      "details": "This function looks complex",
      "return": "The sum of a + b",
      "params": {
        "b": {
          "description": "Another number",
          "type": "uint256"
        }
      }
    }
  }
}

To display a value, you'll simply have to use its global reference. For example:

<h1>{{contract.title}}</h1>

Methods or other objects can be listed using loops.

When you're ready, simply run the following command to generate your documentation using your own template:

leafleth -s <source> -t <yourTemplate>

🛠 Contributing

Feel free to open an issue or create a PR if you want to contribute. Also, submitting new templates will be really appreciated!

❌ Known issues

The following issues have been found and will be resolved soon:

  • Private or internal functions are not displayed
  • Modifiers are not displayed
  • Functions from an inherited contract may not be displayed correctly
  • Overloaded functions may not be displayed correctly

📄 License

MIT