Skip to content

Commit

Permalink
Add import statements and GitHub link in API docs (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Jun 11, 2021
1 parent 9d5f77d commit 75f6dbb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docs/contract.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

[.contract]
[[{{anchor}}]]
=== `++{{name}}++`
=== `++{{name}}++` link:{{github-link file.path}}[{github-icon},role=heading-link]

[.hljs-theme-light.nopadding]
```solidity
import "@openzeppelin/contracts/{{file.path}}";
```

{{natspec.devdoc}}

Expand Down
10 changes: 10 additions & 0 deletions docs/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { version } = require('../package.json');

module.exports = {
'github-link': (contractPath) => {
if (typeof contractPath !== 'string') {
throw new Error('Missing argument');
}
return `https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v${version}/contracts/${contractPath}`;
},
};
2 changes: 2 additions & 0 deletions docs/prelude.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]

{{#links}}
:{{slug target.fullName}}: pass:normal[xref:{{path}}#{{target.anchor}}[`{{target.fullName}}`]]
:xref-{{slug target.anchor}}: xref:{{path}}#{{target.anchor}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"compile": "hardhat compile",
"coverage": "hardhat coverage",
"docs": "oz-docs",
"docs:watch": "npm run docs watch contracts 'docs/*.hbs'",
"docs:watch": "npm run docs watch contracts 'docs/*.hbs' docs/helpers.js",
"prepare-docs": "scripts/prepare-docs.sh",
"lint": "npm run lint:js && npm run lint:sol",
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
Expand Down
1 change: 1 addition & 0 deletions scripts/prepare-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ solidity-docgen \
-o "$OUTDIR" \
-e contracts/mocks,contracts/examples \
--output-structure readmes \
--helpers ./docs/helpers.js \
--solc-module ./scripts/prepare-docs-solc.js

node scripts/gen-nav.js "$OUTDIR" > "$OUTDIR/../nav.adoc"

0 comments on commit 75f6dbb

Please sign in to comment.