Adding convenience codegen(..) function
This commit is contained in:
parent
dddf761b74
commit
33e2e5c3a3
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue