react-docgen-renderer-template
A helper library for creating templates based on react-docgen
objects.
Install
npm install --save-dev react-docgen-renderer-template
Usage
Template Creators
const template type = ; // The template function gets an object of key/value pairs that represent type mappings for the template.// The key is the type name and the value is a string to be displayed for that type.// The string can also be a template string with functions inside that get the context (current prop definition) and a getType function that returns the type of a specific prop. const templateCreator = ; const template = templateCreator`This is my custom template to render a component docs.I can use custom functions that will interpolate according to the metadata about the component, like so:`
The result of the template should be passed as-is to a renderer instance, for example react-docgen-markdown-renderer
.
Renderer Creators
The TemplateObject
contains two methods.
template.setPlugins
This function gets an array of plugins to apply on the template.
A plugin is an object with a function getTypeMapping
that gets an options object with an extension
- the extension of the template. That function returns an object with a key/value pairs, where each key is a type returned by react-docgen
and the value is either a string to display for that type or a template string with functions as the templates (these will be called to populate the actual type) and should return a string.
template.instantiate
This function instatiates the template.
It gets the context to apply on the template, and the extension this template will be saved as (typically the format).
This function returns the full blown template as a sring to be saved to the disk.
License
MIT