json tag generation changed
This commit is contained in:
parent
dc6132f30b
commit
dddf761b74
|
@ -150,12 +150,7 @@ function add_twig_filters(\Twig\Environment $twig)
|
|||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'alias',
|
||||
function(\mtgMetaField $field): string {
|
||||
if ($field->hasToken('alias')) {
|
||||
return $field->getToken('alias');
|
||||
}
|
||||
return $field->getName();
|
||||
}
|
||||
fn(\mtgMetaField $field): string => get_field_alias_or_name($field)
|
||||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'fname',
|
||||
|
@ -314,6 +309,21 @@ function add_twig_filters(\Twig\Environment $twig)
|
|||
return $fields;
|
||||
}
|
||||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'json_tag',
|
||||
function(\mtgMetaField $field): string {
|
||||
$tag = get_field_alias_or_name($field);
|
||||
return $tag.',string';
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
function get_field_alias_or_name(\mtgMetaField $field): string
|
||||
{
|
||||
if ($field->hasToken('alias')) {
|
||||
return $field->getToken('alias');
|
||||
}
|
||||
return $field->getName();
|
||||
}
|
||||
|
||||
function add_twig_functions(\Twig\Environment $twig)
|
||||
|
|
|
@ -8,7 +8,7 @@ type {{ s.name }} struct {
|
|||
{% endif %}
|
||||
|
||||
{% for f in raw_fields %}
|
||||
{{ f|fname }} {{ f.type|go_type(f.tokens) }} `json:"{{ f|alias }}" msgpack:"{{ f|alias }}"`
|
||||
{{ f|fname }} {{ f.type|go_type(f.tokens) }} `json:"{{ f|json_tag }}" msgpack:"{{ f|alias }}"`
|
||||
{% endfor %}
|
||||
|
||||
{% if json_fields|length > 0 %}
|
||||
|
@ -44,7 +44,7 @@ type {{ s.name }} struct {
|
|||
{% if json_fields|length > 0 %}
|
||||
type {{ json_fields_type }} struct{
|
||||
{%~ for f in json_fields %}
|
||||
{{ f|fname }} {{ f.type|go_type }} `json:"{{ f|alias }}" msgpack:"{{ f|alias }}"`
|
||||
{{ f|fname }} {{ f.type|go_type }} `json:"{{ f|json_tag }}" msgpack:"{{ f|alias }}"`
|
||||
{%~ endfor %}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue