UNPKG

solidity-docgen

Version:

Solidity API documentation automatic generator.

105 lines 3.59 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContractPage = exports.ReadmePage = exports.DefaultPage = exports.Page = void 0; const path_1 = __importDefault(require("path")); const handlebars = __importStar(require("./handlebars")); const lodash_1 = require("lodash"); class Page { constructor(sitemap) { this.sitemap = sitemap; } render(preludeTemplate) { const links = this.sitemap.links(this); const prelude = preludeTemplate({ links }); return addPrelude(this.contents, prelude); } } exports.Page = Page; class DefaultPage extends Page { constructor(sitemap, ext, contracts) { super(sitemap); this.ext = ext; this.contracts = contracts; } get contents() { return this.contracts.map(c => c.toString()).join('\n\n'); } get path() { return path_1.default.format({ name: 'index', ext: '.' + this.ext, }); } } exports.DefaultPage = DefaultPage; class ReadmePage extends Page { constructor(sitemap, readme, contracts) { super(sitemap); this.readme = readme; this.contracts = contracts; lodash_1.defaults(this, lodash_1.keyBy(this.contracts, c => c.name)); } get contents() { return this.template(this); } get template() { return handlebars.compile(this.readme.contents); } get location() { return path_1.default.dirname(this.readme.path); } get path() { const { dir, ext } = path_1.default.parse(this.readme.path); return path_1.default.normalize(path_1.default.format({ dir: path_1.default.dirname(dir), name: path_1.default.basename(dir) || 'index', ext, })); } } exports.ReadmePage = ReadmePage; class ContractPage extends Page { constructor(sitemap, contract, ext) { super(sitemap); this.contract = contract; this.ext = ext; } get contents() { return this.contract.toString(); } get contracts() { return [this.contract]; } get path() { const dir = path_1.default.dirname(this.contract.file.path); return path_1.default.format({ dir, name: this.contract.name, ext: '.' + this.ext }); } } exports.ContractPage = ContractPage; function addPrelude(contents, prelude) { const preludeRegex = /^(---\n([^]*?\n)?---\n)?/; return contents.replace(preludeRegex, (_, frontmatter) => frontmatter ? frontmatter + prelude : prelude); } //# sourceMappingURL=page.js.map