A SolDoc theme is simply an npm module that exports a single function with the signature:
Params:
filepath
- the original file's path (eg.path/to/file.sol
).contractName
- the name of the contract (eg.MyAwesomeContract
).info
- an info object.options
- other custom options passed to the function, plusrepoUrl
if available.
Returns:
An object containing:
content
of typestring
- The rendered result.extension
of typestring
- The file extension (eg.'.md'
).
In this example we are going to create the simplest theme possible, we'll call it @soldoc/json
.
The full code for this example is available here
- Clone the repo:
git clone https://github.com/dev-matan-tsuberi/soldoc.git && cd soldoc
. - Create a file
packages/json/index.js
:
module.exports = (filepath, contractName, info, options) => {
return {
content: JSON.stringify({filepath, contractName, info, options},undefined,2),
extension: '.json'
}
}
- And a
packages/json/package.json
:
{
"name": "@soldoc/json",
"publishConfig": {
"access": "public"
},
"description": "Json theme for SolDoc",
"main": "index.js",
"repository": "https://github.com/dev-matan-tsuberi/soldoc/tree/master/packages/json",
"author": "[your name] <[your email]>",
"license": "MIT",
"private": false
}
- Test your theme by running
cd ./packages/soldoc && yarn soldoc --theme ../json
, you should see your output indocs/
. - PR your change into this repo.
The info object contains all the information needed to render a contract and has the following structure:
{
"[filepath]":{
"[contract name]":{
"executionCost":"[number | undefined]",
"deploymentCost":"[number | undefined]",
"title":"[@title documentation | undefined]",
"author":"[@author documentation | undefined]",
"notice":"[@notice documentation | undefined]",
"details":"[@dev documentation | undefined]",
"return":"[@return documentation | undefined]",
"constructor":{
"executionCost":"[number | undefined]",
"author":"[@author documentation | undefined]",
"notice":"[@notice documentation | undefined]",
"details":"[@dev documentation | undefined]",
"return":"[@return documentation | undefined]",
"payable":"[true | false | undefined]",
"constant":"[true | false | undefined]",
"stateMutability":"['pure' | 'constant' | 'view' | 'payable']",
"params":{
"[param name]":{
"type":"[type (eg. 'byte32[]')]",
"details":"[@param documentation]"
}
}
},
"fallback":{
"executionCost":"[number | undefined]",
"author":"[@author documentation | undefined]",
"notice":"[@notice documentation | undefined]",
"details":"[@dev documentation | undefined]",
"return":"[@return documentation | undefined]",
"payable":"[true | false | undefined]",
"constant":"[true | false | undefined]",
"stateMutability":"['pure' | 'constant' | 'view' | 'payable']"
},
"methods":{
"[method signature (eg. 'payMe(address,uint)']":{
"executionCost":"[number | undefined]",
"author":"[@author documentation | undefined]",
"notice":"[@notice documentation | undefined]",
"details":"[@dev documentation | undefined]",
"return":"[@return documentation | undefined]",
"payable":"[true | false | undefined]",
"constant":"[true | false | undefined]",
"stateMutability":"['pure' | 'constant' | 'view' | 'payable']",
"params":{
"[param name]":{
"type":"[type (eg. 'byte32[]')]",
"details":"[@param documentation]"
}
},
"outputs":{
"[output name]":{
"type":"[type (eg. 'byte32[]')]"
}
}
}
},
"events":{
"[event signature (eg. 'Payed(address,uint)']":{
"indexed":"[true | false | undefined]",
"params":{
"[param name]":{
"type":"[type (eg. 'byte32[]')]"
}
}
}
}
}
}
}
Pro Tip: Use the soldoc --json path/to/info.json
option to write this object to a json file to see it's output while developing.