Skip to content

Commit 75f6dbb

Browse files
authored
Add import statements and GitHub link in API docs (OpenZeppelin#2714)
1 parent 9d5f77d commit 75f6dbb

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

docs/contract.hbs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
[.contract]
1010
[[{{anchor}}]]
11-
=== `++{{name}}++`
11+
=== `++{{name}}++` link:{{github-link file.path}}[{github-icon},role=heading-link]
12+
13+
[.hljs-theme-light.nopadding]
14+
```solidity
15+
import "@openzeppelin/contracts/{{file.path}}";
16+
```
1217

1318
{{natspec.devdoc}}
1419

docs/helpers.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { version } = require('../package.json');
2+
3+
module.exports = {
4+
'github-link': (contractPath) => {
5+
if (typeof contractPath !== 'string') {
6+
throw new Error('Missing argument');
7+
}
8+
return `https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v${version}/contracts/${contractPath}`;
9+
},
10+
};

docs/prelude.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]
2+
13
{{#links}}
24
:{{slug target.fullName}}: pass:normal[xref:{{path}}#{{target.anchor}}[`{{target.fullName}}`]]
35
:xref-{{slug target.anchor}}: xref:{{path}}#{{target.anchor}}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"compile": "hardhat compile",
1515
"coverage": "hardhat coverage",
1616
"docs": "oz-docs",
17-
"docs:watch": "npm run docs watch contracts 'docs/*.hbs'",
17+
"docs:watch": "npm run docs watch contracts 'docs/*.hbs' docs/helpers.js",
1818
"prepare-docs": "scripts/prepare-docs.sh",
1919
"lint": "npm run lint:js && npm run lint:sol",
2020
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",

scripts/prepare-docs.sh

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ solidity-docgen \
1515
-o "$OUTDIR" \
1616
-e contracts/mocks,contracts/examples \
1717
--output-structure readmes \
18+
--helpers ./docs/helpers.js \
1819
--solc-module ./scripts/prepare-docs-solc.js
1920

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

0 commit comments

Comments
 (0)