vue-docgen-cli
Version:
Generate documentation markdown files from VueJs components using the vue-docgen-api.
54 lines (50 loc) • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const paramsTmpl = (params, subComponent) => {
let ret = `
${subComponent ? '#' : ''}#### Params
| Param name | Type | Description |
| ------------- |------------- | -------------|
`;
params.forEach(p => {
const t = p.type && p.type.name ? p.type.name : '';
const n = p.name ? p.name : '';
const d = typeof p.description === 'string' ? p.description : '';
ret += `| ${(0, utils_1.mdclean)(n)} | ${(0, utils_1.mdclean)(t)} | ${(0, utils_1.mdclean)(d)} |\n`;
});
return ret;
};
const returnsTemplate = (ret, subComponent) => {
const p = ret;
const t = p.type && p.type.name ? p.type.name : '';
const d = p.description ? p.description : '';
return `
${subComponent ? '#' : ''}#### Return
| Type | Description |
| ------------- | -------------|
| ${t} | ${d} |
`;
};
const tmpl = function (methods, subComponent) {
let ret = '';
methods.forEach(m => {
ret += `
${subComponent ? '#' : ''}### ${m.name ? m.name : ''}
> ${m.description || ''}
${m.params ? paramsTmpl(m.params, subComponent) : ''}
${m.returns ? returnsTemplate(m.returns, subComponent) : ''}
`;
});
return ret;
};
exports.default = (methods, opt = {}) => {
if (Object.keys(methods).length === 0) {
return '';
}
return `
${opt.isSubComponent || opt.hasSubComponents ? '#' : ''}## Methods
${tmpl(methods, opt.isSubComponent || opt.hasSubComponents || false)}
`;
};
//# sourceMappingURL=methods.js.map
;