1 | import { IHtmlEngineHelper, IHandlebarsOptions } from './html-engine-helper.interface';
|
2 | import { JsdocTagInterface } from '../../interfaces/jsdoc-tag.interface';
|
3 | import { kindToType } from '../../../utils/kind-to-type';
|
4 |
|
5 | export class JsdocParamsHelper implements IHtmlEngineHelper {
|
6 | public helperFunc(
|
7 | context: any,
|
8 | jsdocTags: Array<JsdocTagInterface | any>,
|
9 | options: IHandlebarsOptions
|
10 | ) {
|
11 | let i = 0;
|
12 | let len = jsdocTags.length;
|
13 | let tags = [];
|
14 |
|
15 | for (i; i < len; i++) {
|
16 | if (jsdocTags[i].tagName) {
|
17 | if (jsdocTags[i].tagName.text === 'param') {
|
18 | let tag = {} as JsdocTagInterface;
|
19 | if (jsdocTags[i].typeExpression && jsdocTags[i].typeExpression.type.kind) {
|
20 | tag.type = kindToType(jsdocTags[i].typeExpression.type.kind);
|
21 | }
|
22 | if (jsdocTags[i].typeExpression && jsdocTags[i].typeExpression.type.name) {
|
23 | tag.type = jsdocTags[i].typeExpression.type.name.text;
|
24 | } else {
|
25 | tag.type = jsdocTags[i].type;
|
26 | }
|
27 | if (jsdocTags[i].comment) {
|
28 | tag.comment = jsdocTags[i].comment;
|
29 | }
|
30 | if (jsdocTags[i].defaultValue) {
|
31 | tag.defaultValue = jsdocTags[i].defaultValue;
|
32 | }
|
33 | if (jsdocTags[i].name) {
|
34 | if (jsdocTags[i].name.text) {
|
35 | tag.name = jsdocTags[i].name.text;
|
36 | } else {
|
37 | tag.name = jsdocTags[i].name;
|
38 | }
|
39 | }
|
40 | if (jsdocTags[i].optional) {
|
41 | (tag as any).optional = true;
|
42 | }
|
43 | tags.push(tag);
|
44 | }
|
45 | }
|
46 | }
|
47 | if (tags.length >= 1) {
|
48 | context.tags = tags;
|
49 | return options.fn(context);
|
50 | }
|
51 | }
|
52 | }
|