Update docs

This commit is contained in:
github-actions
2023-09-19 19:19:10 +00:00
commit dbe796d542
624 changed files with 107720 additions and 0 deletions

111
docs/templates/contract.hbs vendored Normal file
View File

@ -0,0 +1,111 @@
{{#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}}
{{#if has-errors}}
[.contract-index]
.Errors
--
{{#each inheritance}}
{{#unless @first}}
[.contract-subindex-inherited]
.{{name}}
{{/unless}}
{{#each errors}}
* {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}}
{{#each errors}}
[.contract-item]
[[{{anchor}}]]
==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}})++` [.item-kind]#error#
{{{natspec.dev}}}
{{/each}}

46
docs/templates/helpers.js vendored Normal file
View 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.indexed ? ' indexed' : ''}${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]+\}/gi)
.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
View 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
View 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['has-errors'] = function ({ item }) {
return item.inheritance.some(c => c.errors.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)),
}));
};