From 12b79301c1caf6be0b3905a8e50946a7b783e846 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Sun, 14 Jun 2020 17:59:48 -0700 Subject: [PATCH] feat: Add examples to sdk source --- plugins/gatsby-source-newrelic-sdk/src/docInfo.js | 8 ++++++-- plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js diff --git a/plugins/gatsby-source-newrelic-sdk/src/docInfo.js b/plugins/gatsby-source-newrelic-sdk/src/docInfo.js index c326232cf..0298361c8 100644 --- a/plugins/gatsby-source-newrelic-sdk/src/docInfo.js +++ b/plugins/gatsby-source-newrelic-sdk/src/docInfo.js @@ -1,4 +1,6 @@ -module.exports.getComponentDoc = (name, sdk) => { +const { getExamples } = require('./exampleInfo'); + +exports.getComponentDoc = (name, sdk) => { const component = sdk[name]; if (!component) { @@ -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) { @@ -23,5 +26,6 @@ module.exports.getApiDoc = (name, sdk) => { name, usage: `import { ${name} } from 'nr1'`, description: api.__docs__.text, + examples: getExamples(api), }; }; diff --git a/plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js b/plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js new file mode 100644 index 000000000..02a49b372 --- /dev/null +++ b/plugins/gatsby-source-newrelic-sdk/src/exampleInfo.js @@ -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, + }) + ); +};