summaryrefslogtreecommitdiffstats
path: root/src/Lang/Cpp/CppDocGen.ts
diff options
context:
space:
mode:
authorChristoph Schlosser <christophschlosser@users.noreply.github.com>2019-06-28 23:56:15 +0200
committerGitHub <noreply@github.com>2019-06-28 23:56:15 +0200
commit75e169ef3aebcf7a75edba4fa28bee370782b00b (patch)
tree589fad4429487bce7efbbc8daa756a909ebdfcd6 /src/Lang/Cpp/CppDocGen.ts
parent2d7a744527e469397a6dce6f27d60fac4382ee53 (diff)
parent903fdc1d30c288a9794ebcf9052112712b10080c (diff)
downloaddoxdocgen-75e169ef3aebcf7a75edba4fa28bee370782b00b.tar.gz
Merge pull request #116 from christophschlosser/indent-option
Indent option
Diffstat (limited to 'src/Lang/Cpp/CppDocGen.ts')
-rw-r--r--src/Lang/Cpp/CppDocGen.ts45
1 files changed, 39 insertions, 6 deletions
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index bc5a355..5d2483f 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -119,8 +119,34 @@ export class CppDocGen implements IDocGen {
return this.activeEditor.document.lineAt(this.activeEditor.selection.start.line).text.match("^\\s*")[0];
}
+ protected getIndentedTemplate(replace: string): string {
+ if (replace === undefined || replace === null || replace === "") {
+ return "";
+ }
+ const snippets = replace.split(/({indent:\d+})/);
+
+ let indentedString: string = "";
+ let indentWidth: number = 0;
+
+ // tslint:disable-next-line:prefer-for-of
+ snippets.forEach((element) => {
+ if (element.match(/{indent:\d+}/)) {
+ const indents = parseInt(element.match(/{indent:(\d+)}/)[1], 10);
+ indentWidth = indents;
+ const numSpaces = Math.max(indentWidth - indentedString.length, 0);
+ indentedString += " ".repeat(numSpaces);
+ } else {
+ // just some text
+ indentedString += element;
+ }
+ });
+
+ return indentedString;
+ }
+
protected getTemplatedString(replace: string, template: string, param: string): string {
- return template.replace(replace, param);
+ const replacedTemplate = template.replace(replace, param);
+ return this.getIndentedTemplate(replacedTemplate);
}
protected getMultiTemplatedString(replace: string[], template: string, param: string[]): string {
@@ -190,12 +216,15 @@ export class CppDocGen implements IDocGen {
}
protected generateBrief(lines: string[]) {
- lines.push(this.getTemplatedString(this.cfg.textTemplateReplace,
- this.cfg.C.commentPrefix + this.cfg.Generic.briefTemplate,
+ lines.push(this.cfg.C.commentPrefix + this.getTemplatedString(this.cfg.textTemplateReplace,
+ this.cfg.Generic.briefTemplate,
this.getSmartText()));
}
- protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) {
+ protected generateFromTemplate(lines: string[],
+ replace: string,
+ template: string,
+ templateWith: string[]) {
let line: string = "";
templateWith.forEach((element: string) => {
@@ -410,8 +439,12 @@ export class CppDocGen implements IDocGen {
case "param": {
if (this.cfg.Generic.paramTemplate.trim().length !== 0 && this.params.length > 0) {
const paramNames: string[] = this.params.map((p) => p.name);
- // tslint:disable-next-line:max-line-length
- this.generateFromTemplate(lines, this.cfg.paramTemplateReplace, this.cfg.Generic.paramTemplate, paramNames);
+ this.generateFromTemplate(
+ lines,
+ this.cfg.paramTemplateReplace,
+ this.cfg.Generic.paramTemplate,
+ paramNames,
+ );
}
break;
}