UNPKG

wt2doc

Version:

WebTemplate to Asciidoc documentation - a util by Bifrost for Bifrost

215 lines 7.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocBuilder = void 0; const isEntry_1 = require("./isEntry"); const StringBuilder_1 = require("./StringBuilder"); class DocBuilder { constructor(wt) { this.wt = wt; this.sb = new StringBuilder_1.StringBuilder(); this.defaultLang = 'nb'; this.defaultLang = wt.defaultLanguage; this.generate(); } toString() { return this.sb.toString(); } generate() { // this.sb.append(`= ${this.wt.templateId}`); const f = this.wt.tree; this.sb.append(`= ${f.name}`).newline(); this.sb.append(`== Metadata`).newline(); this.sb.append(`TemplateId:: ${this.wt.templateId}`).newline(); this.sb.append(`Archetype:: ${f.nodeId}`).newline(); this.sb.newline(); this.walk(this.wt.tree); } walkChildren(f) { if (f.children) { f.children.forEach((child) => { this.walk(child); }); } } walk(f) { if (f.aqlPath === '/category') { // skipping category } else if (isEntry_1.isEntry(f.rmType)) { this.walkEntry(f); } else if (isEntry_1.isDataValue(f.rmType)) { this.walkElement(f); } else if (isEntry_1.isSection(f.rmType)) { this.walkSection(f); } else if (f.rmType === 'CLUSTER') { this.appendClusterOrEntryRow(f); this.walkChildren(f); } else { switch (f.rmType) { case 'COMPOSITIION': this.walkChildren(f); break; case 'ISM_TRANSITION': break; case 'EVENT_CONTEXT': f.name = 'EVENT_CONTEXT'; this.walkEntry(f); break; default: this.sb.append('// Not supported rmType ' + f.rmType); this.walkChildren(f); break; } } } walkSection(f) { this.sb.append(`== ${f.name}`); if (f.children) { f.children.forEach((child) => { this.walk(child); }); } } /** * Append a table row wi+th colspan to get all on ine line * @param f the form elment */ appendClusterOrEntryRow(f) { this.sb.append(`5+a|*${f.name}* + \n${f.rmType}: _${f.nodeId}_`); if (f.annotations && f.annotations.comment) { this.sb.newline().append(`${f.annotations.comment}`); } } walkEntry(f) { this.sb.append(`== ${f.name}`); this.sb.append('[options="header", cols="3,3,5,5,30"]'); this.sb.append('|===='); this.sb.append('|NodeId|Attr.|RM Type| Navn |Beskrivelse'); this.appendClusterOrEntryRow(f); if (f.children) { f.children.forEach((child) => { if (child.inContext !== undefined && child.inContext) { // Will not document things in contexts (which is included in openEHR RM) } else { this.walk(child); } }); this.sb.append('|===='); } } walkElement(f) { const max = f.max < 0 ? '*' : `${f.max}`; this.sb.append(`|${f.nodeId}| ${f.min}..${max}| ${f.rmType} | ${f.name}`); if (f.name === undefined) this.sb.append(`// ${f.id} - ${f.aqlPath}`); switch (f.rmType) { case 'DV_CODED_TEXT': this.walkDvCodedText(f); break; case 'DV_TEXT': this.walkDvText(f); break; case 'DV_DATE': this.walkDvDateTime(f); break; case 'DV_DATE_TIME': this.walkDvDateTime(f); break; case 'DV_QUANTITY': this.walkDvQuantity(f); break; case 'DV_ORDINAL': this.walkDvOrdinal(f); break; case 'DV_COUNT': this.walkDvCount(f); break; case 'DV_DURATION': this.walkDvDuration(f); break; case 'DV_BOOLEAN': this.walkDvBoolean(f); break; default: this.sb.append('|Not supported rm type' + f.rmType); } if (f.annotations) { this.sb.newline(); this.sb.append(f.annotations.comment); } // this.sb.append(`${this.getValueOfRecord(f.localizedDescriptions)}`); } walkDvBoolean(f) { this.sb.append('|'); } walkDvDuration(f) { this.sb.append('|'); } walkDvCount(f) { this.sb.append('|'); } walkDvOrdinal(f) { this.sb.append('a|'); if (f.inputs) { const fi = f.inputs; // const term = fi.terminology == undefined ? "local" : fi.terminology; fi.forEach((item) => { const formItems = item.list === undefined ? [] : item.list; formItems.forEach((n) => { this.sb.append(`* ${n.ordinal} - ${n.label} ${this.getValueOfRecord(n.localizedDescriptions)}`); }); }); } } getValueOfRecord(record) { if (record) { return record[this.defaultLang]; } else { return ''; } } walkDvQuantity(f) { this.sb.append('|'); } walkDvText(f) { this.sb.append('a|'); if (f.inputs) { f.inputs.forEach((item) => { if (item.list) { item.list.forEach((val) => { this.sb.append(`* ${val.value}`); }); } }); } } walkDvDateTime(f) { this.sb.append('|'); } walkDvCodedText(f) { this.sb.append('a|'); if (f.inputs) { f.inputs.forEach((item) => { const term = item.terminology === undefined ? 'local' : item.terminology; if (item.list) { item.list.forEach((list) => { if (term === 'local') { this.sb.append(`* ${list.value} -> ${list.label} `); } else { this.sb.append(`* ${list.label} (${term}: ${list.value})`); } }); } }); } } } exports.DocBuilder = DocBuilder; //# sourceMappingURL=DocBuilder.js.map