comparison Resources/CodeGeneration/template.in.ts.j2 @ 628:84af39146e76 am-dev

CodeGeneration: support default values
author Alain Mazy <alain@mazy.be>
date Wed, 08 May 2019 16:32:57 +0200
parents 17106b29ed6d
children
comparison
equal deleted inserted replaced
627:b7fd0471281c 628:84af39146e76
70 } 70 }
71 {%endfor%} 71 {%endfor%}
72 72
73 73
74 {% for struct in structs%}export class {{struct['name']}} { 74 {% for struct in structs%}export class {{struct['name']}} {
75 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} {{key}}:{{CanonToTs(struct['fields'][key])}}; 75 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} {{key}}:{{CanonToTs(struct['fields'][key]['type'])}};
76 {% endfor %}{% endif %}{% endif %} 76 {% endfor %}{% endif %}{% endif %}
77 constructor() { 77 constructor() {
78 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%}{% if NeedsTsConstruction(enums,CanonToTs(struct['fields'][key])) %} this.{{key}} = new {{CanonToTs(struct['fields'][key])}}(); 78 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%}{% if NeedsTsConstruction(enums,CanonToTs(struct['fields'][key]['type'])) %} this.{{key}} = new {{CanonToTs(struct['fields'][key]['type'])}}();
79 {% endif %}
80 {% if struct['fields'][key]['defaultValue'] %} this.{{key}} = {{DefaultValueToTs(enums,struct['fields'][key])}};
79 {% endif %}{% endfor %}{% endif %}{% endif %} } 81 {% endif %}{% endfor %}{% endif %}{% endif %} }
80 82
81 public StoneSerialize(): string { 83 public StoneSerialize(): string {
82 let container: object = {}; 84 let container: object = {};
83 container['type'] = '{{rootName}}.{{struct['name']}}'; 85 container['type'] = '{{rootName}}.{{struct['name']}}';