Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support explicit model #43

Merged
merged 2 commits into from
Jun 25, 2019
Merged

Conversation

dirty49374
Copy link
Contributor

In this patch, format() function returns the model used in render() call not the rendered string.
( I did it because I want to write a wrapper javascript generator and I wanted to reuse current one. )

changes are like this.

// before
export namespace EnumFormatter {
    export function format(enumDescriptor: EnumDescriptorProto, indentLevel: number): string {
        let enumName = enumDescriptor.getName();
        let values: { [key: string]: number } = {};
        enumDescriptor.getValueList().forEach(value => {
            values[value.getName().toUpperCase()] = value.getNumber();
        });
        return TplEngine.render('partial/enum', {
            indent: Utility.generateIndent(indentLevel),
            enumName: enumName,
            values: values,
        });
    }
}
// after
export namespace EnumFormatter {
    export interface EnumModel {
        indent: string;
        enumName: string;
        values: { [key: string]: number };
    }
    export function format(enumDescriptor: EnumDescriptorProto, indent: string): EnumModel {
        let enumName = enumDescriptor.getName();
        let values: { [key: string]: number } = {};
        enumDescriptor.getValueList().forEach(value => {
            values[value.getName().toUpperCase()] = value.getNumber();
        });
        return {
            indent,
            enumName: enumName,
            values: values,
        };
    }
}
// before
{{#each message.formattedEnumListStr}}
{{{this}}}
{{/each}}

// after
{{#each message.formattedEnumListStr}}
{{{render 'partial/enum' this}}}
{{/each}}

this commit also contains hbs template cache.

@agreatfool agreatfool merged commit c4d824a into agreatfool:master Jun 25, 2019
@agreatfool
Copy link
Owner

Just merged & latest 2.5.4 has been released. Thank you guys for the great enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants