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

Loading…
Cancel
Save