diff --git a/docs/contract.hbs b/docs/contract.hbs index 450c296d5..8690cf8a2 100644 --- a/docs/contract.hbs +++ b/docs/contract.hbs @@ -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}} diff --git a/docs/helpers.js b/docs/helpers.js new file mode 100644 index 000000000..9b71f44f3 --- /dev/null +++ b/docs/helpers.js @@ -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}`; + }, +}; diff --git a/docs/prelude.hbs b/docs/prelude.hbs index 6f5624b83..f531d72f0 100644 --- a/docs/prelude.hbs +++ b/docs/prelude.hbs @@ -1,3 +1,5 @@ +:github-icon: pass:[] + {{#links}} :{{slug target.fullName}}: pass:normal[xref:{{path}}#{{target.anchor}}[`{{target.fullName}}`]] :xref-{{slug target.anchor}}: xref:{{path}}#{{target.anchor}} diff --git a/package.json b/package.json index eb4acc2ad..28d14ac76 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/prepare-docs.sh b/scripts/prepare-docs.sh index 336a4c980..2f22a0081 100755 --- a/scripts/prepare-docs.sh +++ b/scripts/prepare-docs.sh @@ -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"