Skip to content

Commit

Permalink
feat: Add examples to sdk source
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 15, 2020
1 parent 51558e5 commit 12b7930
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugins/gatsby-source-newrelic-sdk/src/docInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports.getComponentDoc = (name, sdk) => {
const { getExamples } = require('./exampleInfo');

exports.getComponentDoc = (name, sdk) => {
const component = sdk[name];

if (!component) {
Expand All @@ -9,10 +11,11 @@ module.exports.getComponentDoc = (name, sdk) => {
name,
usage: `import { ${name} } from 'nr1'`,
description: component.__docs__.text,
examples: getExamples(component),
};
};

module.exports.getApiDoc = (name, sdk) => {
exports.getApiDoc = (name, sdk) => {
const api = sdk[name];

if (!api) {
Expand All @@ -23,5 +26,6 @@ module.exports.getApiDoc = (name, sdk) => {
name,
usage: `import { ${name} } from 'nr1'`,
description: api.__docs__.text,
examples: getExamples(api),
};
};
11 changes: 11 additions & 0 deletions plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const IGNORED_PREVIEWS = ['Dropdown', 'Modal', 'Tooltip'];

exports.getExamples = (component) => {
return (component.__docs__.tags.examples || []).map(
({ label, options, sourceCode }) => ({
label,
sourceCode,
preview: IGNORED_PREVIEWS.includes(component.name) ? false : options.live,
})
);
};

0 comments on commit 12b7930

Please sign in to comment.