woocommerce/plugins/woocommerce-blocks/bin/hook-docs/format-hook-doc/example.js

28 lines
550 B
JavaScript

/**
* External dependencies
*/
const fs = require( 'fs' );
const example = ( hookDoc ) => {
const tags = hookDoc.tags || [];
const exampleDoc =
tags.filter( ( { name: tagName } ) => tagName === 'example' )[ 0 ] ||
undefined;
const exampleSource = exampleDoc ? exampleDoc.content : false;
if ( ! exampleSource ) {
return null;
}
const buffer = fs.readFileSync( `${ exampleSource }` );
const exampleContent = buffer.toString();
return exampleContent
? {
html: exampleContent,
}
: null;
};
module.exports = { example };