From 892158b2e0da18613ec8ee86b0f913fdd1d53e1e Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 8 Dec 2022 19:45:55 +0300 Subject: [PATCH] Tuning codegen --- tpl/macro.twig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tpl/macro.twig b/tpl/macro.twig index 2ead37b..1130e30 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -122,25 +122,25 @@ func (self *{{o.name}}) WriteFields(writer meta.Writer) error { {% macro props_map(tokens) %} map[string]string{ -{% for k,v in tokens %} +{%- for k,v in tokens -%} "{{k}}" : "{{v|replace({'"' : '\\"'})}}", -{%- endfor ~%} +{%- endfor -%} } {% endmacro %} {% macro struct_fields_names(o) %} []string{ -{% for f in get_all_fields(o) ~%} +{%- for f in get_all_fields(o) -%} "{{f.name}}", -{%- endfor ~%} +{%- endfor -%} } {% endmacro %} {% macro struct_fields_props(o) %} map[string]map[string]string{ -{% for f in get_all_fields(o) ~%} +{%- for f in get_all_fields(o) -%} "{{f.name|ucfirst}}" : {{_self.props_map(f.tokens)}}, -{%- endfor ~%} +{%- endfor -%} } {% endmacro %} @@ -192,8 +192,8 @@ self.fieldsMask = meta.FieldsMask{} return err } - if _cont_size < {{o.fields|length - count_optional(o.fields)}} { - _cont_size = {{o.fields|length - count_optional(o.fields)}} + if _cont_size < {{(o.fields|length) - count_optional(o.fields)}} { + _cont_size = {{(o.fields|length) - count_optional(o.fields)}} } {%- if o.parent ~%} @@ -373,13 +373,13 @@ func New{{o.name}}ByName(name string) ({{o.name}}, error) { {% endmacro %} {% macro enum_values_list(o) %} -{%- for v in o.values|sort ~%} +{%- for v in o.values|sort -%} {{v}}, {%- endfor ~%} {% endmacro %} {% macro enum_values_map(o) %} -{%- for k,v in o.values ~%} +{%- for k,v in o.values -%} "{{k}}" : {{v}}, {%- endfor ~%} {% endmacro %}