Add support for enum names with spaces inside them.

This commit is contained in:
Maksym Lapshyn 2020-11-26 14:32:35 +02:00
parent 5559a15d2a
commit 42ac5e5fa8
5 changed files with 9479 additions and 0 deletions

9470
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,7 @@ const handlebarsPlugin = () => ({
knownHelpers: {
equals: true,
notEquals: true,
containsSpaces: true,
},
});
return `export default ${templateSpec};`;

View File

@ -10,6 +10,10 @@ export enum {{{name}}} {
* {{{description}}}
*/
{{/if}}
{{#if (containsSpaces name)}}
"{{{name}}}" = {{{value}}},
{{else}}
{{{name}}} = {{{value}}},
{{/if}}
{{/each}}
}

View File

@ -8,5 +8,6 @@ describe('registerHandlebarHelpers', () => {
const helpers = Object.keys(Handlebars.helpers);
expect(helpers).toContain('equals');
expect(helpers).toContain('notEquals');
expect(helpers).toContain('containsSpaces');
});
});

View File

@ -9,4 +9,7 @@ export function registerHandlebarHelpers(): void {
Handlebars.registerHelper('notEquals', function (a: string, b: string, options: Handlebars.HelperOptions): string {
return a !== b ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('containsSpaces', function (value: string): boolean {
return /\s+/.test(value);
});
}