Fix template generator

This commit is contained in:
Romain Neutron
2012-04-13 16:33:51 +02:00
parent 45a4af8f1b
commit adddfa18c3

View File

@@ -36,7 +36,15 @@ class module_console_systemTemplateGenerator extends Command
public function execute(InputInterface $input, OutputInterface $output)
{
$tplDir = __DIR__ . '/../../../../templates/';
$tplDirs = array(
realpath(__DIR__ . '/../../../../templates/web/'),
realpath(__DIR__ . '/../../../../templates/mobile/')
);
$n_ok = $n_error = 0;
foreach ($tplDirs as $tplDir)
{
$tmpDir = __DIR__ . '/../../../../tmp/cache_twig/';
$loader = new Twig_Loader_Filesystem($tplDir);
@@ -45,6 +53,7 @@ class module_console_systemTemplateGenerator extends Command
'cache' => $tmpDir,
'auto_reload' => true
));
$twig->addExtension(new Twig_Extensions_Extension_I18n());
/**
@@ -83,25 +92,20 @@ class module_console_systemTemplateGenerator extends Command
$twig->addFilter('geoname_name_from_id', new Twig_Filter_Function('geonames::name_from_id'));
$n_ok = $n_error = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
$finder = new Symfony\Component\Finder\Finder();
foreach ($finder->files()->in(array($tplDir)) as $file)
{
if (strpos($file, '/.svn/') !== false)
continue;
if (substr($file->getFilename(), 0, 1) === '.')
continue;
try
{
$twig->loadTemplate(str_replace($tplDir, '', $file));
$twig->loadTemplate(str_replace($tplDir, '', $file->getPathname()));
$output->writeln('' . $file . '');
$n_ok++;
$n_ok ++;
}
catch (Exception $e)
{
$output->writeln('<error>' . $e->getMessage() . '</error>');
$n_error++;
$n_error ++;
}
}
}