diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 9890345..7dbd1c7 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -4,6 +4,22 @@ namespace metagen_go; use Exception; use Twig\{TwigTest, TwigFilter, TwigFunction}; +function codegen(?string $cache_dir, \mtgMetaInfo $meta, array $options = []) : string +{ + $twig = get_twig(); + + if(!empty($cache_dir)) + $twig->setCache($cache_dir); + + $twig->addGlobal('meta', $meta); + + $options['meta'] = $meta; + if(isset($options['package'])) + $options['package'] = 'autogen'; + + return $twig->render('codegen_bundle.twig', $options); +} + function get_twig(array $inc_path = []): \Twig\Environment { array_unshift($inc_path, __DIR__ . "/../tpl/"); @@ -501,4 +517,4 @@ function table_json_fields(\mtgMetaStruct $struct): array function json_field_name(\mtgMetaStruct $struct): string { return $struct->getName() . 'JsonValues'; -} \ No newline at end of file +}