summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Anderson <dean@locomation.ai>2018-09-27 16:51:01 -0400
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-09-29 19:08:20 +0200
commit4939806ae705953cfc1ca8cf54f20d98e9be9d03 (patch)
tree71c291d9c5edd2927f350b2dbdf738ca7ff6dfbf
parentd3452b0a1e9f4424591b5621ee107a95a61300d5 (diff)
downloaddoxdocgen-4939806ae705953cfc1ca8cf54f20d98e9be9d03.tar.gz
customTag will supply ISO date format if user configured format empty
Added separate templates for author name {author} and email {email} Added method to make multiple template substitutions in a string customTag will now replace {author}, {email}, {date} and {year} templates
-rw-r--r--package.json12
-rw-r--r--src/Config.ts8
-rw-r--r--src/Lang/Cpp/CppDocGen.ts42
-rw-r--r--src/test/CppTests/Config.test.ts2
-rw-r--r--src/test/CppTests/FileDescription.test.ts33
5 files changed, 86 insertions, 11 deletions
diff --git a/package.json b/package.json
index a6112da..1aed081 100644
--- a/package.json
+++ b/package.json
@@ -141,10 +141,20 @@
"type": "number",
"default": 20
},
+ "doxdocgen.generic.authorName": {
+ "description": "Set the name of the author. Replaces {author}.",
+ "type": "string",
+ "default": "your name"
+ },
+ "doxdocgen.generic.authorEmail": {
+ "description": "Set the e-mail address of the author. Replaces {email}.",
+ "type": "string",
+ "default": "you@domain.com"
+ },
"doxdocgen.generic.authorTag": {
"description": "Set the style of the author tag and your name.",
"type": "string",
- "default": "@author your name"
+ "default": "@author {author} ({email})"
},
"doxdocgen.generic.dateTemplate": {
"description": "The template for the date parameter in Doxygen.",
diff --git a/src/Config.ts b/src/Config.ts
index 54d227a..b33aff2 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -49,7 +49,9 @@ class Generic {
public paramTemplate: string = "@param {param} ";
public returnTemplate: string = "@return {type} ";
public linesToGet: number = 20;
- public authorTag: string = "@author your name";
+ public authorName: string = "your name";
+ public authorEmail: string = "you@domain.com";
+ public authorTag: string = "@author {author} ({email})";
public dateTemplate: string = "@date {date}";
public dateFormat: string = "YYYY-MM-DD";
public generateSmartText: boolean = true;
@@ -86,6 +88,8 @@ export class Config {
values.Generic.returnTemplate = Generic.getConfiguration().get<string>("returnTemplate", values.Generic.returnTemplate);
values.Generic.linesToGet = Generic.getConfiguration().get<number>("linesToGet", values.Generic.linesToGet);
values.Generic.authorTag = Generic.getConfiguration().get<string>("authorTag", values.Generic.authorTag);
+ values.Generic.authorName = Generic.getConfiguration().get<string>("authorName", values.Generic.authorName);
+ values.Generic.authorEmail = Generic.getConfiguration().get<string>("authorEmail", values.Generic.authorEmail);
values.Generic.dateTemplate = Generic.getConfiguration().get<string>("dateTemplate", values.Generic.dateTemplate);
values.Generic.dateFormat = Generic.getConfiguration().get<string>("dateFormat", values.Generic.dateFormat);
values.Generic.generateSmartText = Generic.getConfiguration().get<boolean>("generateSmartText", values.Generic.generateSmartText);
@@ -98,6 +102,8 @@ export class Config {
public readonly paramTemplateReplace: string = "{param}";
public readonly typeTemplateReplace: string = "{type}";
public readonly nameTemplateReplace: string = "{name}";
+ public readonly authorTemplateReplace: string = "{author}";
+ public readonly emailTemplateReplace: string = "{email}";
public readonly dateTemplateReplace: string = "{date}";
public readonly yearTemplateReplace: string = "{year}";
public readonly textTemplateReplace: string = "{text}";
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index e71d39e..705b72c 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -105,6 +105,18 @@ export class CppDocGen implements IDocGen {
return template.replace(replace, param);
}
+ protected getMultiTemplatedString(replace: string[], template: string, param: string[]): string {
+ // FIXME I find this argument order a bit strange. I would probably have template first
+ // For each replace entry, attempt to replace it with the corresponding param in the template
+ for(var i=0;i<replace.length;i++) {
+ if (i<param.length) {
+ template = template.replace(replace[i],param[i]);
+ }
+ // TODO: warn if mismatch string lengths? Probably should use tuple of tuples
+ }
+ return template;
+ }
+
protected getSmartText(): string {
if (!this.cfg.Generic.generateSmartText) {
return "";
@@ -211,9 +223,17 @@ export class CppDocGen implements IDocGen {
return params;
}
+
protected generateAuthorTag(lines: string[]) {
if (this.cfg.Generic.authorTag.trim().length !== 0) {
- lines.push(this.cfg.C.commentPrefix + this.cfg.Generic.authorTag);
+ // Allow substitution of {author} and {email} only
+ lines.push(this.cfg.C.commentPrefix +
+ this.getMultiTemplatedString(
+ [this.cfg.authorTemplateReplace, this.cfg.emailTemplateReplace],
+ this.cfg.Generic.authorTag,
+ [this.cfg.Generic.authorName,this.cfg.Generic.authorEmail]
+ )
+ );
}
}
@@ -235,6 +255,7 @@ export class CppDocGen implements IDocGen {
}
protected generateCopyrightTag(lines: string[]) {
+ // This currently only supports year substitution
this.cfg.File.copyrightTag.forEach((element) => {
this.generateFromTemplate(
lines,
@@ -246,12 +267,21 @@ export class CppDocGen implements IDocGen {
}
protected generateCustomTag(lines: string[]) {
+ let dateFormat: string = "YYYY-MM-DD"; // Default to ISO standard if not defined
+ if ( this.cfg.Generic.dateFormat.trim().length != 0) {
+ dateFormat = this.cfg.Generic.dateFormat; // Overwrite with user format
+ }
+ // For each line of the customTag
this.cfg.File.customTag.forEach((element) => {
- this.generateFromTemplate(
- lines,
- this.cfg.dateTemplateReplace,
- element,
- [moment().format(this.cfg.Generic.dateFormat)],
+ // Allow any of date, year, author, email to be replaced
+ lines.push(this.cfg.C.commentPrefix +
+ this.getMultiTemplatedString(
+ [this.cfg.authorTemplateReplace, this.cfg.emailTemplateReplace,
+ this.cfg.dateTemplateReplace, this.cfg.yearTemplateReplace],
+ element,
+ [this.cfg.Generic.authorName, this.cfg.Generic.authorEmail,
+ moment().format(dateFormat), moment().format("YYYY")]
+ )
);
});
}
diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts
index 69837ce..a4c96e6 100644
--- a/src/test/CppTests/Config.test.ts
+++ b/src/test/CppTests/Config.test.ts
@@ -113,7 +113,7 @@ suite("C++ - Configuration Tests", () => {
testSetup.firstLine = 0;
testSetup.cfg.File.fileOrder = ["brief", "author", "date", "file"];
const result = testSetup.SetLine("").GetResult();
- assert.equal("/**\n * @brief \n * @author your name\n" +
+ assert.equal("/**\n * @brief \n * @author your name (you@domain.com)\n" +
" * @date " + moment().format("YYYY-MM-DD") + "\n * @file MockDocument.h\n */", result);
});
diff --git a/src/test/CppTests/FileDescription.test.ts b/src/test/CppTests/FileDescription.test.ts
index 8c8d4d4..362c17a 100644
--- a/src/test/CppTests/FileDescription.test.ts
+++ b/src/test/CppTests/FileDescription.test.ts
@@ -15,18 +15,20 @@ import TestSetup from "./TestSetup";
// Defines a Mocha test suite to group tests of similar kind together
suite("File Description Tests", () => {
const testSetup: TestSetup = new TestSetup("void foo();");
+ testSetup.cfg.File.fileOrder = ["brief", "empty", "file", "author", "date"];
const date = moment().format("YYYY-MM-DD");
+ const year = moment().format("YYYY");
// Tests
test("#include on next line", () => {
const result = testSetup.SetLine("#include <iostream>").GetResult();
- assert.equal("/**\n * @brief \n * \n * @file MockDocument.h\n * @author your name\n" +
+ assert.equal("/**\n * @brief \n * \n * @file MockDocument.h\n * @author your name (you@domain.com)\n" +
" * @date " + date + "\n */", result);
});
test("On first line of document", () => {
const result = testSetup.SetLine("").GetResult();
- assert.equal("/**\n * @brief \n * \n * @file MockDocument.h\n * @author your name\n" +
+ assert.equal("/**\n * @brief \n * \n * @file MockDocument.h\n * @author your name (you@domain.com)\n" +
" * @date " + date + "\n */", result);
});
@@ -35,4 +37,31 @@ suite("File Description Tests", () => {
const result = testSetup.SetLine("").GetResult();
assert.equal("/**\n */", result);
});
+
+ test("version block", () => {
+ testSetup.cfg.File.fileOrder = ["version"];
+ const result = testSetup.SetLine("").GetResult();
+ assert.equal("/**\n * @version 0.1\n */", result);
+ });
+
+ test("Copyright block", () => {
+ testSetup.cfg.File.fileOrder = ["copyright"];
+ const result = testSetup.SetLine("").GetResult();
+ assert.equal("/**\n * @copyright Copyright (c) " + year + "\n */", result);
+ });
+
+ test("version block", () => {
+ testSetup.cfg.File.fileOrder = ["version"];
+ const result = testSetup.SetLine("").GetResult();
+ assert.equal("/**\n * @version 0.1\n */", result);
+ });
+
+ test("custom block", () => {
+ testSetup.cfg.File.fileOrder = ["custom"];
+ testSetup.cfg.File.customTag = ["First Line", "{year} Year Line", "{date} Date Line",
+ "{author} Author Line", "{email} Email Line"];
+ const result = testSetup.SetLine("").GetResult();
+ assert.equal("/**\n * First Line\n * " + year + " Year Line\n * " + date + " Date Line\n" +
+ " * your name Author Line\n * you@domain.com Email Line\n */", result);
+ });
});