-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation generator for main page, demo, and sandbox.
- Loading branch information
Showing
10 changed files
with
329 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const Generator = require('yeoman-generator'); | ||
|
||
const documentationGenerator = require.resolve('../documentation/index.js'); | ||
|
||
module.exports = class extends Generator { | ||
prompting() { | ||
return this.prompt([{ | ||
message: 'What do you want to create?', | ||
name: 'fileType', | ||
type: 'list', | ||
choices: [{ | ||
name: 'Page', | ||
value: 'documentation', | ||
}, { | ||
name: 'Page demo', | ||
value: 'demo', | ||
}, { | ||
name: 'Sandbox', | ||
value: 'sandbox', | ||
}], | ||
}]).then(answers => { | ||
this.config = answers; | ||
}); | ||
} | ||
|
||
writing() { | ||
this.composeWith(documentationGenerator, { | ||
fileType: this.config.fileType, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
const chalk = require('chalk'); | ||
const Generator = require('yeoman-generator'); | ||
const utils = require('../utils'); | ||
|
||
const DOCUMENTATION_PAGE_PATH = 'ui_framework/doc_site/src/views'; | ||
|
||
module.exports = class extends Generator { | ||
constructor(args, options) { | ||
super(args, options); | ||
|
||
this.fileType = options.fileType; | ||
} | ||
|
||
prompting() { | ||
const prompts = [{ | ||
message: 'What\'s the name of the component you\'re documenting? Use snake_case, please.', | ||
name: 'name', | ||
type: 'input', | ||
store: true, | ||
}]; | ||
|
||
if (this.fileType === 'demo') { | ||
prompts.push({ | ||
message: 'What would you like to name this demo? Use snake_case, please.', | ||
name: 'demoName', | ||
type: 'input', | ||
store: true, | ||
}); | ||
} | ||
|
||
return this.prompt(prompts).then(answers => { | ||
this.config = answers; | ||
}); | ||
} | ||
|
||
writing() { | ||
const config = this.config; | ||
|
||
const writeDocumentationPage = () => { | ||
const componentExampleName = utils.makeComponentName(config.name, false); | ||
const componentExamplePrefix = utils.lowerCaseFirstLetter(componentExampleName); | ||
const fileName = config.name; | ||
|
||
const path = DOCUMENTATION_PAGE_PATH; | ||
|
||
const vars = config.documentationVars = { | ||
componentExampleName, | ||
componentExamplePrefix, | ||
fileName, | ||
}; | ||
|
||
const documentationPagePath | ||
= config.documentationPagePath | ||
= `${path}/${config.name}/${config.name}_example.js`; | ||
|
||
this.fs.copyTpl( | ||
this.templatePath('documentation_page.js'), | ||
this.destinationPath(documentationPagePath), | ||
vars | ||
); | ||
}; | ||
|
||
const writeDocumentationPageDemo = () => { | ||
const fileName = config.demoName || config.name; | ||
const componentExampleName = utils.makeComponentName(fileName, false); | ||
const componentExamplePrefix = utils.lowerCaseFirstLetter(componentExampleName); | ||
const componentName = utils.makeComponentName(config.name); | ||
|
||
const path = DOCUMENTATION_PAGE_PATH; | ||
|
||
const vars = config.demoVars = { | ||
componentExampleName, | ||
componentExamplePrefix, | ||
componentName, | ||
fileName, | ||
}; | ||
|
||
const documentationPageDemoPath | ||
= config.documentationPageDemoPath | ||
= `${path}/${config.name}/${fileName}.js`; | ||
|
||
this.fs.copyTpl( | ||
this.templatePath('documentation_page_demo.js'), | ||
this.destinationPath(documentationPageDemoPath), | ||
vars | ||
); | ||
}; | ||
|
||
const writeSandbox = () => { | ||
const fileName = config.name; | ||
const componentExampleName = utils.makeComponentName(fileName, false); | ||
|
||
const path = DOCUMENTATION_PAGE_PATH; | ||
|
||
const vars = config.sandboxVars = { | ||
componentExampleName, | ||
fileName, | ||
}; | ||
|
||
const sandboxPath | ||
= config.documentationPageDemoPath | ||
= `${path}/${config.name}/${fileName}`; | ||
|
||
this.fs.copyTpl( | ||
this.templatePath('documentation_sandbox.html'), | ||
this.destinationPath(`${sandboxPath}_sandbox.html`) | ||
); | ||
|
||
this.fs.copyTpl( | ||
this.templatePath('documentation_sandbox.js'), | ||
this.destinationPath(`${sandboxPath}_sandbox.js`), | ||
vars | ||
); | ||
}; | ||
|
||
switch (this.fileType) { | ||
case 'documentation': | ||
writeDocumentationPage(); | ||
writeDocumentationPageDemo(); | ||
break; | ||
|
||
case 'demo': | ||
writeDocumentationPageDemo(); | ||
break; | ||
|
||
case 'sandbox': | ||
writeSandbox(); | ||
break; | ||
} | ||
} | ||
|
||
end() { | ||
const showImportDocumentationPageSnippet = () => { | ||
const { | ||
componentExampleName, | ||
fileName, | ||
} = this.config.demoVars; | ||
|
||
this.log(chalk.gray('\n// Import example into routes.js.')); | ||
this.log( | ||
`${chalk.magenta('import')} ${componentExampleName}Example\n` + | ||
` ${chalk.magenta('from')} ${chalk.cyan(`'../../views/${fileName}/${fileName}_example'`)};` | ||
); | ||
}; | ||
|
||
const showImportDemoSnippet = () => { | ||
const { | ||
componentExampleName, | ||
componentExamplePrefix, | ||
fileName, | ||
} = this.config.demoVars; | ||
|
||
this.log(chalk.gray('\n// Import demo into example.')); | ||
this.log( | ||
`${chalk.magenta('import')} ${componentExampleName} from './${fileName};\n` + | ||
`${chalk.magenta('const')} ${componentExamplePrefix}Source = require('!!raw!./${fileName}');\n` + | ||
`${chalk.magenta('const')} ${componentExamplePrefix}Html = renderToHtml(${componentExampleName});` | ||
); | ||
}; | ||
|
||
const showImportSandboxSnippet = () => { | ||
const { | ||
componentExampleName, | ||
fileName, | ||
} = this.config.sandboxVars; | ||
|
||
this.log(chalk.gray('\n// Import example into routes.js.')); | ||
this.log( | ||
`${chalk.magenta('import')} ${componentExampleName}Sandbox\n` + | ||
` ${chalk.magenta('from')} ${chalk.cyan(`'../../views/${fileName}/${fileName}_sandbox'`)};` | ||
); | ||
}; | ||
|
||
this.log('------------------------------------------------'); | ||
this.log(chalk.bold('Import snippets:')); | ||
|
||
switch (this.fileType) { | ||
case 'documentation': | ||
showImportDocumentationPageSnippet(); | ||
break; | ||
|
||
case 'demo': | ||
showImportDemoSnippet(); | ||
break; | ||
|
||
case 'sandbox': | ||
showImportSandboxSnippet(); | ||
break; | ||
} | ||
this.log('------------------------------------------------'); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
ui_framework/generator-kui/documentation/templates/documentation_page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { | ||
GuideDemo, | ||
GuidePage, | ||
GuideSection, | ||
GuideSectionTypes, | ||
GuideText, | ||
} from '../../components'; | ||
|
||
import <%= componentExampleName %> from './<%= fileName %>'; | ||
const <%= componentExamplePrefix %>Source = require('!!raw!./<%= fileName %>'); | ||
const <%= componentExamplePrefix %>Html = renderToHtml(<%= componentExampleName %>); | ||
|
||
export default props => ( | ||
<GuidePage title={props.route.name}> | ||
<GuideSection | ||
title="<%= componentExampleName %>" | ||
source={[{ | ||
type: GuideSectionTypes.JS, | ||
code: <%= componentExamplePrefix %>Source, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: <%= componentExamplePrefix %>Html, | ||
}]} | ||
> | ||
<GuideText> | ||
Description needed: how to use the <%= componentExampleName %> component. | ||
</GuideText> | ||
|
||
<GuideDemo> | ||
<<%= componentExampleName %> /> | ||
</GuideDemo> | ||
</GuideSection> | ||
</GuidePage> | ||
); |
11 changes: 11 additions & 0 deletions
11
ui_framework/generator-kui/documentation/templates/documentation_page_demo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
<%= componentName %>, | ||
} from '../../../../components'; | ||
|
||
export default () => ( | ||
<<%= componentName %>> | ||
|
||
</<%= componentName %>> | ||
); |
1 change: 1 addition & 0 deletions
1
ui_framework/generator-kui/documentation/templates/documentation_sandbox.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Do whatever you want here!</p> |
27 changes: 27 additions & 0 deletions
27
ui_framework/generator-kui/documentation/templates/documentation_sandbox.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
GuideDemo, | ||
GuideSandbox, | ||
GuideSandboxCodeToggle, | ||
GuideSectionTypes, | ||
} from '../../components'; | ||
|
||
const html = require('./<%= fileName %>_sandbox.html'); | ||
|
||
export default props => ( | ||
<GuideSandbox> | ||
<GuideDemo | ||
isFullScreen={true} | ||
html={html} | ||
/> | ||
|
||
<GuideSandboxCodeToggle | ||
source={[{ | ||
type: GuideSectionTypes.HTML, | ||
code: html, | ||
}]} | ||
title={props.route.name} | ||
/> | ||
</GuideSandbox> | ||
); |
Oops, something went wrong.