Skip to content

Commit

Permalink
Merge pull request #2508 from subjectix/improve-docs-codgen-prop-table
Browse files Browse the repository at this point in the history
Slightly improve how the props table is generated.
  • Loading branch information
oliviertassinari committed Dec 13, 2015
2 parents 65c2b24 + e5df5c7 commit 7493e75
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions docs/src/app/components/PropTypeDescription.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function generatePropType(type) {
return type.raw;

case 'enum':
const values = type.value.map(v => v.value).join(', ');
return `enum[${values}]`;
const values = type.value.map(v => v.value).join('<br>&nbsp;');
return `enum:<br>&nbsp;${values}<br>`;

default:
return type.name;
Expand All @@ -42,7 +42,7 @@ const PropTypeDescription = React.createClass({
} = this.props;

let text = `${header}
| Name | Type | Default | Description|
| Name | Type | Default | Description |
|:-----|:-----|:-----|:-----|\n`;

const componentInfo = parse(code);
Expand All @@ -56,11 +56,15 @@ const PropTypeDescription = React.createClass({
defaultValue = prop.defaultValue.value;
}

const description = (prop.required ? '**required**' : '*optional*') +
'. ' + prop.description.replace(/\n/g, '<br>');
const requirement = `${prop.required ? '**required**' : '*optional*'}.`;

text += `| ${key} | ${generatePropType(prop.type)} |`;
text += `${defaultValue} |${description} |\n`;
// two new lines result in a newline in the table. all other new lines
// must be eliminated to prevent markdown mayhem.
const jsDocText = prop.description.replace(/\n\n/g, '<br>').replace(/\n/g, ' ');

const description = `${requirement} ${jsDocText}`;

text += `| ${key} | ${generatePropType(prop.type)} | ${defaultValue} | ${description} |\n`;
}

return (
Expand Down

0 comments on commit 7493e75

Please sign in to comment.