Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DM] Documentalist! #756

Merged
merged 19 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
throw errors in tag renderers, catch them in page
then log and render error message.
also give page a className.
  • Loading branch information
Gilad Gray committed Mar 6, 2017
commit fccb4819e0bc1f2bf5be5f0d84ab461d40135e17
2 changes: 1 addition & 1 deletion packages/docs/src/common/resolveDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function resolveDocs(componentName: string, key: React.Key) {

const docsComponent = (ReactDocs as any as DocsMap)[componentName];
if (docsComponent == null) {
console.error(`Unknown @reactDocs component: ${componentName}`);
throw new Error(`Unknown @reactDocs component: ${componentName}`);
}
return React.createElement(docsComponent, { key });
}
2 changes: 1 addition & 1 deletion packages/docs/src/common/resolveExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function resolveExample(exampleName: string, key: React.Key) {

const { component, packageName } = getExample(exampleName, Examples);
if (component == null) {
throw new Error(`Unknown example component: ${exampleName}`);
throw new Error(`Unknown @example component: ${exampleName}`);
}
const fileName = exampleName.charAt(0).toLowerCase() + exampleName.slice(1) + ".tsx";
return <Example
Expand Down
13 changes: 9 additions & 4 deletions packages/docs/src/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ export const Page: React.SFC<IPageProps> = ({ tagRenderers, page }) => {
const pageContents = page.contents.map((node, i) => {
if (typeof node === "string") {
return <div className="docs-section" dangerouslySetInnerHTML={{ __html: node }} key={i} />;
} else {
}

// try rendering the tag,
try {
const renderer = tagRenderers[node.tag];
if (renderer === undefined) {
console.error("Unknown tag '@%s' in '%s'; please supply a renderer.", node.tag, page.reference);
return undefined;
throw new Error(`Unknown @tag: ${node.tag}`);
}
return renderer(node.value, i, page);
} catch (ex) {
console.error(ex.message);
return <h3><code>{ex.message}</code></h3>
}
});
return <div>{pageContents}</div>;
return <div className="docs-page">{pageContents}</div>;
};