Merge pull request #448 from mlaps-gafe/allow-spaces-in-enum-names

Add support for enum names with spaces inside them.
This commit is contained in:
Ferdi Koomen 2020-12-16 19:20:42 +01:00 committed by GitHub
commit 3acd779074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

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,22 @@ describe('registerHandlebarHelpers', () => {
const helpers = Object.keys(Handlebars.helpers);
expect(helpers).toContain('equals');
expect(helpers).toContain('notEquals');
expect(helpers).toContain('containsSpaces');
});
describe('containsSpaces', () => {
it('should return true when string with spaces is passed', () => {
registerHandlebarHelpers();
const containsSpaces = Handlebars.helpers['containsSpaces'];
const result = containsSpaces('I have spaces insideme');
expect(result).toBeTruthy();
});
it('should return false when string without spaces is passed', () => {
registerHandlebarHelpers();
const containsSpaces = Handlebars.helpers['containsSpaces'];
const result = containsSpaces('Ihavespacesinsideme');
expect(result).toBeFalsy();
});
});
});

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);
});
}