templates \o/
This commit is contained in:
parent
a70e576822
commit
1b31436e58
4 changed files with 62 additions and 19 deletions
|
|
@ -15,3 +15,31 @@ export function getFileName(item: MediaTypeModel) {
|
|||
export function replaceIllegalFileNameCharactersInString(string: string) {
|
||||
return string.replace(/[\\,#%&{}/*<>$"@.]*/g, '').replace(/:+/g, ' -');
|
||||
}
|
||||
|
||||
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel): string {
|
||||
const resolvedTemplate = template.replace(new RegExp('{{ .*? }}', 'g'), (match: string) => replaceTag(match, mediaTypeModel));
|
||||
|
||||
return resolvedTemplate;
|
||||
}
|
||||
|
||||
function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
|
||||
let tag = match;
|
||||
tag = tag.substring(3);
|
||||
tag = tag.substring(0, tag.length - 3);
|
||||
|
||||
let parts = tag.split('.');
|
||||
|
||||
let o: any = mediaTypeModel;
|
||||
|
||||
for (let part of parts) {
|
||||
if (o !== undefined) {
|
||||
o = o[part];
|
||||
}
|
||||
}
|
||||
|
||||
if (o === undefined) {
|
||||
o = '{{ INVALID TEMPLATE TAG }}';
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue