Skip to content

Commit

Permalink
feat(markdown): generate additional detail
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 10, 2019
1 parent c9f19e1 commit cc07df2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ const { argv } = yargs
.coerce('i', i => nodepath.resolve(i))

.alias('p', 'properties')
.describe('p', 'A comma separated list with custom properties which should be also in the description of an element.')
.array('p')
.describe('p', 'name of a custom property which should be also in the description of an element (may be used multiple times)')
.default('p', [])
.alias('h', 'header')
.describe('h', 'if the value is false the header will be skipped')
.default('h', true);
Expand Down Expand Up @@ -188,6 +190,7 @@ readdirp.promise(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtensio
build({
header: argv.h,
links: docs,
includeproperties: argv.p
}),


Expand Down
34 changes: 33 additions & 1 deletion lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { gentitle } = require('./formattingTools');
const { basename } = require('path');
const ghslugger = require('github-slugger');

function build({ header, links = {} }) {
function build({ header, links = {}, includeproperties = [] } = {}) {
const headerprops = [
{
name: 'type',
Expand Down Expand Up @@ -250,6 +250,27 @@ function build({ header, links = {} }) {
return retval;
}

function makenullablefact(definition) {
const alltypes = Array.isArray(definition.type) ? definition.type : [definition.type];
// filter out types that are null
const realtypes = alltypes.filter(type => type!=='null');
// can the type be `null`
const nullable = alltypes.filter(type => type === 'null').length > 0;

if (nullable) {
return listItem(paragraph(text(i18n`can be null`)));
} else {
return listItem(paragraph(text(i18n`cannot be null`)));
}
}

function makedefinedinfact(definition) {
return listItem(paragraph([
text(i18n`defined in: `),
link(`${definition[s.slug]}.md`, definition[s.id] + '#' + definition[s.pointer], text(definition[s.titles][0] || i18n`Untitled schema`))
]));
}

function makefactlist(name, definition, required = []) {
const children = [];

Expand All @@ -261,6 +282,17 @@ function build({ header, links = {} }) {
}

children.push(maketypefact(definition));
children.push(makenullablefact(definition));
children.push(makedefinedinfact(definition));

const additionalfacts = includeproperties.map(propname => {
if (definition[propname]) {
return listItem(text(propname + ': ' + String(definition[propname])));
}
return undefined;
}).filter(item => item != undefined);

children.push(...additionalfacts);

return list('unordered', children);
}
Expand Down

0 comments on commit cc07df2

Please sign in to comment.