support for insider codegen
This commit is contained in:
parent
0b3f87a6ed
commit
63297519da
|
@ -4,7 +4,7 @@ namespace metagen_go;
|
|||
use Exception;
|
||||
use Twig\{TwigTest, TwigFilter, TwigFunction};
|
||||
|
||||
function get_twig(array $inc_path = [])
|
||||
function get_twig(array $inc_path = []): \Twig\Environment
|
||||
{
|
||||
array_unshift($inc_path, __DIR__ . "/../tpl/");
|
||||
$loader = new \Twig\Loader\FilesystemLoader($inc_path);
|
||||
|
@ -165,6 +165,10 @@ function add_twig_filters(\Twig\Environment $twig)
|
|||
'varname',
|
||||
fn(\mtgMetaField $field): string => lcfirst(snake2camel($field->getName()))
|
||||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'tname',
|
||||
fn(\mtgMetaField $field): string => $field->getType() instanceof \mtgArrType ? $field->getType()->getValue()->getName() : $field->getType()->getName()
|
||||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'builtin_type_suffix',
|
||||
fn (\mtgBuiltinType $type): string => builtin_type_method_suffix($type),
|
||||
|
@ -173,6 +177,33 @@ function add_twig_filters(\Twig\Environment $twig)
|
|||
'default_val',
|
||||
fn(\mtgMetaField $field) => default_value($field)
|
||||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'fields',
|
||||
function (\mtgMetaField $field): array {
|
||||
$type = $field->getType();
|
||||
if($type instanceof \mtgArrType)
|
||||
{
|
||||
$type = $type->getValue();
|
||||
}
|
||||
return $type->getFields();
|
||||
}
|
||||
));
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'pk_fields',
|
||||
function (\mtgMetaField $field): array {
|
||||
$type = $field->getType();
|
||||
if($type instanceof \mtgArrType)
|
||||
{
|
||||
$type = $type->getValue();
|
||||
}
|
||||
$pkey = explode(',', $type->getToken('table_pkey'));
|
||||
$fields = [];
|
||||
foreach ($pkey as $fieldName) {
|
||||
$fields[] = $type->getField($fieldName);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
));
|
||||
|
||||
$twig->addFilter(new TwigFilter(
|
||||
'rpc_invert',
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
type {{ s.name }} struct {
|
||||
{%~ for f in pkey %}
|
||||
{{ f|fname }} {{ f.type|go_type }} `json:"{{ f|alias }}" msgpack:"{{ f|alias }}"`
|
||||
{{ f|fname }} {{ f.type|go_type }} `json:"{{ f|alias }},string" msgpack:"{{ f|alias }}"`
|
||||
{%~ endfor %}
|
||||
|
||||
{{ json_fields_type }}
|
||||
|
@ -51,7 +51,7 @@ type {{ s.name }} struct {
|
|||
|
||||
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|alias }},string" msgpack:"{{ f|alias }}"`
|
||||
{%~ endfor %}
|
||||
|
||||
changedFields meta.ChangedFields
|
||||
|
@ -847,7 +847,7 @@ type {{ s.name }} struct {
|
|||
{% endif %}
|
||||
|
||||
{% for f in s.fields %}
|
||||
{{ f|fname }} {{ f.type|go_type }} `json:"{{ f|alias }}" msgpack:"{{ f|alias }}"`
|
||||
{{ f|fname }} {{ f.type|go_type }} `json:"{{ f|alias }},string" msgpack:"{{ f|alias }}"`
|
||||
{% endfor %}
|
||||
|
||||
{% if has_token(s, 'bitfields') %}
|
||||
|
|
Loading…
Reference in New Issue