Skip to content

Commit

Permalink
Add generic tag adding
Browse files Browse the repository at this point in the history
  • Loading branch information
neild3r committed Jan 12, 2019
1 parent bc8388d commit 01c4cb3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ config option per key to add additional control.

#### Supported template keys

| Key | Aplies to type | Description |
|-----------------|-----------------|------------------------------------------------|
| message | All | Space for entering a description of your block |
| extra | All | Adds in your custom tags from the extra config |
| param | Function | Function @param items |
| return | Function | Function @return item |
| var | Property | Property @var item |
| Key | Aplies to type | Description |
|-----------------|-----------------|-----------------------------------------------------------------------------------|
| message | All | Space for entering a description of your block |
| extra | All | Adds in your custom tags from the extra config |
| param | Function | Function @param items |
| return | Function | Function @return item |
| var | Property | Property @var item |
| * | All | This is for any key that is unmatched you can use the content option to add a tag |

#### Supported template config options

| Option | Aplies to key(s) | Description |
|-----------------|------------------|------------------------------------------------|
| gapBefore | All | Adds a gap before the tag section starts |
| gapAfter | All | Adds a gap after the tag section ends |
| content | * | Adds a gap after the tag section ends |

#### Configured function template example

Expand Down
11 changes: 3 additions & 8 deletions src/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,7 @@ export class Doc
}

if (Array.isArray(extra) && extra.length > 0) {
extraString = "";
for (var index = 0; index < extra.length; index++) {
var element = extra[index];
if (index > 0) {
extraString += "\n";
}
extraString += element;
}
extraString = extra.join("\n");
}


Expand All @@ -153,6 +146,8 @@ export class Doc
propString = paramString;
} else if (key == 'extra' && extraString) {
propString = extraString;
} else if (propConfig.content !== undefined) {
propString = propConfig.content;
}

if (propString && propConfig.gapBefore && templateArray[templateArray.length - 1] != "") {
Expand Down
3 changes: 3 additions & 0 deletions test/doc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ suite("Snippet build tests", () => {
} else {
empty = true;
}
if (Config.instance.get('template')) {
doc.template = Config.instance.get('template');
}
assert.equal(doc.build(empty).value, testData.expected.join("\n"));
});
});
Expand Down
35 changes: 35 additions & 0 deletions test/fixtures/doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,40 @@
" * @param ${2:int} \\$name",
" */"
]
},
{
"name": "Function template",
"config": {
"template": {
"message": {
"gapAfter": true
},
"author": {
"content": "@author Neil Brayfield <[email protected]>"
},
"param": {
"gapBefore": true
}
}
},
"input": {
"message": "Undocumented function",
"params": [
{
"name": "$name",
"type": "int"
}
],
"return": "void"
},
"expected": [
"/**",
" * ${1:Undocumented function}",
" *",
" * @author Neil Brayfield <[email protected]>",
" *",
" * @param ${2:int} \\$name",
" */"
]
}
]

0 comments on commit 01c4cb3

Please sign in to comment.