Update docs pipeline to solidity-docgen@0.6 (#3707)
(cherry picked from commit c52625018b)
This commit is contained in:
committed by
Francisco Giordano
parent
f0de978a9e
commit
50501a751e
85
docs/templates/contract.hbs
vendored
Normal file
85
docs/templates/contract.hbs
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
{{#each items}}
|
||||
:{{name}}: pass:normal[xref:#{{anchor}}[`++{{name}}++`]]
|
||||
{{/each}}
|
||||
|
||||
[.contract]
|
||||
[[{{anchor}}]]
|
||||
=== `++{{name}}++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v{{oz-version}}/{{__item_context.file.absolutePath}}[{github-icon},role=heading-link]
|
||||
|
||||
[.hljs-theme-light.nopadding]
|
||||
```solidity
|
||||
import "@openzeppelin/{{__item_context.file.absolutePath}}";
|
||||
```
|
||||
|
||||
{{{natspec.dev}}}
|
||||
|
||||
{{#if modifiers}}
|
||||
[.contract-index]
|
||||
.Modifiers
|
||||
--
|
||||
{{#each modifiers}}
|
||||
* {xref-{{anchor~}} }[`++{{name}}({{names params}})++`]
|
||||
{{/each}}
|
||||
--
|
||||
{{/if}}
|
||||
|
||||
{{#if has-functions}}
|
||||
[.contract-index]
|
||||
.Functions
|
||||
--
|
||||
{{#each inherited-functions}}
|
||||
{{#unless @first}}
|
||||
[.contract-subindex-inherited]
|
||||
.{{contract.name}}
|
||||
{{/unless}}
|
||||
{{#each functions}}
|
||||
* {xref-{{anchor~}} }[`++{{name}}({{names params}})++`]
|
||||
{{/each}}
|
||||
|
||||
{{/each}}
|
||||
--
|
||||
{{/if}}
|
||||
|
||||
{{#if has-events}}
|
||||
[.contract-index]
|
||||
.Events
|
||||
--
|
||||
{{#each inheritance}}
|
||||
{{#unless @first}}
|
||||
[.contract-subindex-inherited]
|
||||
.{{name}}
|
||||
{{/unless}}
|
||||
{{#each events}}
|
||||
* {xref-{{anchor~}} }[`++{{name}}({{names params}})++`]
|
||||
{{/each}}
|
||||
|
||||
{{/each}}
|
||||
--
|
||||
{{/if}}
|
||||
|
||||
{{#each modifiers}}
|
||||
[.contract-item]
|
||||
[[{{anchor}}]]
|
||||
==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}})++` [.item-kind]#modifier#
|
||||
|
||||
{{{natspec.dev}}}
|
||||
|
||||
{{/each}}
|
||||
|
||||
{{#each functions}}
|
||||
[.contract-item]
|
||||
[[{{anchor}}]]
|
||||
==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}}){{#if returns}} → {{typed-params returns}}{{/if}}++` [.item-kind]#{{visibility}}#
|
||||
|
||||
{{{natspec.dev}}}
|
||||
|
||||
{{/each}}
|
||||
|
||||
{{#each events}}
|
||||
[.contract-item]
|
||||
[[{{anchor}}]]
|
||||
==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}})++` [.item-kind]#event#
|
||||
|
||||
{{{natspec.dev}}}
|
||||
|
||||
{{/each}}
|
||||
46
docs/templates/helpers.js
vendored
Normal file
46
docs/templates/helpers.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
const { version } = require('../../package.json');
|
||||
|
||||
module.exports['oz-version'] = () => version;
|
||||
|
||||
module.exports['readme-path'] = (opts) => {
|
||||
return 'contracts/' + opts.data.root.id.replace(/\.adoc$/, '') + '/README.adoc';
|
||||
};
|
||||
|
||||
module.exports.names = (params) => params.map(p => p.name).join(', ');
|
||||
|
||||
module.exports['typed-params'] = (params) => {
|
||||
return params.map(p => `${p.type}${p.name ? ' ' + p.name : ''}`).join(', ');
|
||||
};
|
||||
|
||||
const slug = module.exports.slug = (str) => {
|
||||
if (str === undefined) {
|
||||
throw new Error('Missing argument');
|
||||
}
|
||||
return str.replace(/\W/g, '-');
|
||||
};
|
||||
|
||||
const linksCache = new WeakMap();
|
||||
|
||||
function getAllLinks (items) {
|
||||
if (linksCache.has(items)) {
|
||||
return linksCache.get(items);
|
||||
}
|
||||
const res = {};
|
||||
linksCache.set(items, res);
|
||||
for (const item of items) {
|
||||
res[`xref-${item.anchor}`] = `xref:${item.__item_context.page}#${item.anchor}`;
|
||||
res[slug(item.fullName)] = `pass:normal[xref:${item.__item_context.page}#${item.anchor}[\`${item.fullName}\`]]`;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports['with-prelude'] = (opts) => {
|
||||
const links = getAllLinks(opts.data.site.items);
|
||||
const contents = opts.fn();
|
||||
const neededLinks = contents
|
||||
.match(/\{[-._a-z0-9]+\}/ig)
|
||||
.map(m => m.replace(/^\{(.+)\}$/, '$1'))
|
||||
.filter(k => k in links);
|
||||
const prelude = neededLinks.map(k => `:${k}: ${links[k]}`).join('\n');
|
||||
return prelude + '\n' + contents;
|
||||
};
|
||||
4
docs/templates/page.hbs
vendored
Normal file
4
docs/templates/page.hbs
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
:github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]
|
||||
{{#with-prelude}}
|
||||
{{readme (readme-path)}}
|
||||
{{/with-prelude}}
|
||||
49
docs/templates/properties.js
vendored
Normal file
49
docs/templates/properties.js
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
const { isNodeType } = require('solidity-ast/utils');
|
||||
const { slug } = require('./helpers');
|
||||
|
||||
module.exports.anchor = function anchor ({ item, contract }) {
|
||||
let res = '';
|
||||
if (contract) {
|
||||
res += contract.name + '-';
|
||||
}
|
||||
res += item.name;
|
||||
if ('parameters' in item) {
|
||||
const signature = item.parameters.parameters.map(v => v.typeName.typeDescriptions.typeString).join(',');
|
||||
res += slug('(' + signature + ')');
|
||||
}
|
||||
if (isNodeType('VariableDeclaration', item)) {
|
||||
res += '-' + slug(item.typeName.typeDescriptions.typeString);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
module.exports.inheritance = function ({ item, build }) {
|
||||
if (!isNodeType('ContractDefinition', item)) {
|
||||
throw new Error('used inherited-items on non-contract');
|
||||
}
|
||||
|
||||
return item.linearizedBaseContracts
|
||||
.map(id => build.deref('ContractDefinition', id))
|
||||
.filter((c, i) => c.name !== 'Context' || i === 0);
|
||||
};
|
||||
|
||||
module.exports['has-functions'] = function ({ item }) {
|
||||
return item.inheritance.some(c => c.functions.length > 0);
|
||||
};
|
||||
|
||||
module.exports['has-events'] = function ({ item }) {
|
||||
return item.inheritance.some(c => c.events.length > 0);
|
||||
};
|
||||
|
||||
module.exports['inherited-functions'] = function ({ item }) {
|
||||
const { inheritance } = item;
|
||||
const baseFunctions = new Set(
|
||||
inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? [])),
|
||||
);
|
||||
return inheritance.map((contract, i) => ({
|
||||
contract,
|
||||
functions: contract.functions.filter(f =>
|
||||
!baseFunctions.has(f.id) && (f.name !== 'constructor' || i === 0),
|
||||
),
|
||||
}));
|
||||
};
|
||||
Reference in New Issue
Block a user