Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
fix return output
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch committed Aug 30, 2017
1 parent 25a7114 commit c836df2
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 16 deletions.
12 changes: 7 additions & 5 deletions lib/compile/parse-abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ exports.default = function (contract) {
// don't write this
delete devDocs.params;

var outputs = void 0;
var outputs = [];
try {
var outputParams = JSON.parse(devDocs.return);
outputs = method.outputs.map(function (param) {
return _extends({}, param, { description: outputParams[param.name] });
});
if (typeof devDocs.return !== 'undefined') {
var outputParams = JSON.parse(devDocs.return);
outputs = method.outputs.map(function (param) {
return _extends({}, param, { description: outputParams[param.name] });
});
}
} catch (e) {
process.stderr.write('warning: invalid @return for ' + method.name + ' - output may be effected\n');
outputs = method.outputs;
Expand Down
2 changes: 1 addition & 1 deletion lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var _dot2 = _interopRequireDefault(_dot);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var template = '\n# {{=it.name}}\n{{? it.author }}\n{{=it.author}}{{?}}\n{{~it.abiDocs :docItem:index}}{{? docItem.type === \'function\'}}\n## *{{=docItem.type}}* {{=docItem.name}}\n\n{{=it.name}}.{{=docItem.name}}({{=docItem.argumentList}}){{?docItem.payable}}`payable`{{?}} `{{=docItem.signatureHash}}`\n{{?docItem.notice}}\n**{{=docItem.notice}}**\n{{?}}\n{{?docItem.details}}> {{=docItem.details}}\n{{?}}\n{{? docItem.inputs.length > 0 }}Inputs\n\n| | | |\n|-|-|-|{{~docItem.inputs :input}}\n| *{{=input.type}}* | {{=input.name}} | {{=input.description}} |{{~}}{{?}}\n{{? docItem.outputs.length > 0 }}Outputs\n\n| | | |\n|-|-|-|{{~docItem.outputs :output}}\n| *{{=output.type}}* | {{=output.name}} | {{=output.description}} |{{~}}{{?}}{{?}}\n{{~}}\n---';
var template = '\n# {{=it.name}}\n{{? it.author }}\n{{=it.author}}{{?}}\n{{~it.abiDocs :docItem:index}}{{? docItem.type === \'function\'}}\n## *{{=docItem.type}}* {{=docItem.name}}\n\n{{=it.name}}.{{=docItem.name}}({{=docItem.argumentList}}){{?docItem.payable}}`payable`{{?}} `{{=docItem.signatureHash}}`\n{{?docItem.notice}}\n**{{=docItem.notice}}**\n{{?}}\n{{?docItem.details}}> {{=docItem.details}}\n{{?}}\n{{? docItem.inputs.length > 0 }}Inputs\n\n| | | |\n|-|-|-|{{~docItem.inputs :input}}\n| *{{=input.type}}* | {{=input.name}} | {{=input.description}} |{{~}}{{?}}\n{{? docItem.outputs.length > 0 }}\nOutputs\n\n| | | |\n|-|-|-|{{~docItem.outputs :output}}\n| *{{=output.type}}* | {{=output.name}} | {{=output.description}} |{{~}}{{?}}{{?}}\n{{~}}\n---';

_dot2.default.templateSettings.strip = false;

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solmd",
"version": "0.1.3",
"version": "0.1.4",
"description": "Markdown documentation generator for Solidity",
"engines": {
"node": ">=4"
Expand Down
10 changes: 7 additions & 3 deletions src/compile/parse-abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export default function (contract) {
// don't write this
delete devDocs.params;

let outputs;
let outputs = [];
try {
const outputParams = JSON.parse(devDocs.return);
outputs = method.outputs.map(param => ({ ...param, description: outputParams[param.name] }));
if (typeof devDocs.return !== 'undefined') {
const outputParams = JSON.parse(devDocs.return);
outputs = method.outputs.map(param => (
{ ...param, description: outputParams[param.name] }
));
}
} catch (e) {
process.stderr.write(`warning: invalid @return for ${method.name} - output may be effected\n`);
outputs = method.outputs;
Expand Down
3 changes: 2 additions & 1 deletion src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const template = `
| | | |
|-|-|-|{{~docItem.inputs :input}}
| *{{=input.type}}* | {{=input.name}} | {{=input.description}} |{{~}}{{?}}
{{? docItem.outputs.length > 0 }}Outputs
{{? docItem.outputs.length > 0 }}
Outputs
| | | |
|-|-|-|{{~docItem.outputs :output}}
Expand Down
14 changes: 14 additions & 0 deletions test/contracts/GavCoin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ contract GavCoin {
balances[msg.sender] -= valueInmGAV;
}
}

/**
@notice change owner
@dev dev
@param _owner this is the owner
@return {
"previousOwner": "the previous owner"
}
*/
function setOwner(address _owner) returns (address previousOwner) {
previousOwner = owner;
owner = _owner;
return previousOwner;
}
}
24 changes: 20 additions & 4 deletions test/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@ const GavCoin = `
Gavin Wood
## *function* balances
## *function* setOwner
GavCoin.balances() \`27e235e3\`
GavCoin.setOwner(_owner) \`13af4035\`
**change owner**
> dev
Inputs
| | | |
|-|-|-|
| *address* | | undefined |
| *address* | _owner | this is the owner |
Outputs
| | | |
|-|-|-|
| *uint256* | | undefined |
| *address* | previousOwner | the previous owner |
## *function* balances
GavCoin.balances() \`27e235e3\`
Inputs
| | | |
|-|-|-|
| *address* | | undefined |
## *function* send
Expand Down

0 comments on commit c836df2

Please sign in to comment.