improve code for debuggin and changee template rendering of dev functions

pull/3475/head
Defi Boy 4 years ago committed by Aniket
parent 813d11fb25
commit 18d5238bd0
  1. 55
      src/utils/template.ts
  2. 28
      src/utils/utils.test.ts
  3. 30
      src/utils/utils.ts

@ -54,26 +54,27 @@ export const template = (
<div id="ethdoc-viewer"> <div id="ethdoc-viewer">
${ ${
functions.length === 0 functions.length === 0
? "No contract to display" ? "No contract to display"
: renderHeader(name, contractDoc) : renderHeader(name, contractDoc)
} }
${functions ${functions
.map( .map(
(item) => ` (item) => `
<h6>${item.name} - ${item.type}</h6> <hr>
<hr> <h6>${item.name} - ${item.type} </h6>
${renderParameterDocumentation(item.inputs)}
${getMethodDetails(item.devdoc)} ${getMethodDetails(item.devdoc)}
${renderParameterDocumentation(item.inputs)}
<p>Returns:</p> <p>Returns:</p>
${renderParameterDocumentation(item.outputs)} ${renderParameterDocumentation(item.outputs)}
` `
) )
.join("\n")} .join("\n")}
</div> </div>
`; `;
@ -93,7 +94,7 @@ export const renderHeader = (
) => ` ) => `
<h3>${name} ${ <h3>${name} ${
contractDoc.title ? `<small>: ${contractDoc.title}</small>` : "" contractDoc.title ? `<small>: ${contractDoc.title}</small>` : ""
}</h3> }</h3>
${contractDoc.notice ? `<p class="lead">${contractDoc.notice}</p>` : ""} ${contractDoc.notice ? `<p class="lead">${contractDoc.notice}</p>` : ""}
@ -106,8 +107,8 @@ export const renderParameterDocumentation = (
parameters: ParameterDocumentation[] parameters: ParameterDocumentation[]
) => ) =>
`${ `${
parameters.length > 0 parameters.length > 0
? `<table class="table table-sm table-bordered table-striped"> ? `<table class="table table-sm table-bordered table-striped">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@ -127,16 +128,26 @@ export const renderParameterDocumentation = (
.join("")} .join("")}
</tbody> </tbody>
</table>` </table>`
: "<p>No parameters</p>" : "<p>No parameters</p>"
}`; }`;
export const getMethodDetails = (devMethod?: Partial<MethodDoc>) => { export const getMethodDetails = (devMethod?: Partial<MethodDoc>) => {
return !devMethod const finalResult = !devMethod
? "<p><strong>**Add Documentation for the method here**</strong></p>" ? "<p><strong>**Add Documentation for the method here**</strong></p>"
: Object.keys(devMethod) : Object.keys(devMethod)
.filter((key) => key !== "params") .filter((key) => key !== "params")
.map((key) => { .map((key) => {
return (devMethodDocTemplate as any)[key]((devMethod as any)[key]); const funcToGetTemplate = (devMethodDocTemplate as any)[key];
})
.join("\n"); if (!funcToGetTemplate) {
return ''
}
const funcParameter = (devMethod as any)[key]
const result = funcToGetTemplate(funcParameter)
return result
})
.join("\n");
console.log('finalResult', finalResult)
return finalResult
}; };

File diff suppressed because one or more lines are too long

@ -65,25 +65,23 @@ export const getContractDoc = (name: string, contract: CompiledContract) => {
} }
}); });
return template(name, contractDoc, functionsDocumentation); // console.log("contractDoc", contractDoc)
}; // console.log("functionsDocumentation", functionsDocumentation)
export const getContractDocumentation = (contract: CompiledContract) => { try {
const methods: MethodsDocumentation = {}; const finalResult = template(name, contractDoc, functionsDocumentation);
return finalResult
Object.keys(contract.userdoc.methods).forEach((item) => { } catch (error) {
if (contract.devdoc.methods[item]) { console.log("ERROR", error)
const finalResult = { return ''
...contract.userdoc.methods[item], }
...contract.devdoc.methods[item],
}; };
methods[item] = finalResult;
} else {
methods[item] = contract.userdoc.methods[item];
}
});
const contractDoc = { ...contract.userdoc, ...contract.devdoc, methods }; export const getContractDocumentation = (contract: CompiledContract) => {
const methods = { ...contract.userdoc.methods, ...contract.devdoc.methods }
const contractDoc = { ...contract.userdoc, ...contract.devdoc, ...methods };
return contractDoc; return contractDoc;
}; };

Loading…
Cancel
Save