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) 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/'; $tmpDir = __DIR__ . '/../../../../tmp/cache_twig/';
$loader = new Twig_Loader_Filesystem($tplDir); $loader = new Twig_Loader_Filesystem($tplDir);
@@ -45,6 +53,7 @@ class module_console_systemTemplateGenerator extends Command
'cache' => $tmpDir, 'cache' => $tmpDir,
'auto_reload' => true 'auto_reload' => true
)); ));
$twig->addExtension(new Twig_Extensions_Extension_I18n()); $twig->addExtension(new Twig_Extensions_Extension_I18n());
/** /**
@@ -83,18 +92,12 @@ class module_console_systemTemplateGenerator extends Command
$twig->addFilter('geoname_name_from_id', new Twig_Filter_Function('geonames::name_from_id')); $twig->addFilter('geoname_name_from_id', new Twig_Filter_Function('geonames::name_from_id'));
$n_ok = $n_error = 0; $finder = new Symfony\Component\Finder\Finder();
foreach ($finder->files()->in(array($tplDir)) as $file)
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
{ {
if (strpos($file, '/.svn/') !== false)
continue;
if (substr($file->getFilename(), 0, 1) === '.')
continue;
try try
{ {
$twig->loadTemplate(str_replace($tplDir, '', $file)); $twig->loadTemplate(str_replace($tplDir, '', $file->getPathname()));
$output->writeln('' . $file . ''); $output->writeln('' . $file . '');
$n_ok ++; $n_ok ++;
} }
@@ -104,6 +107,7 @@ class module_console_systemTemplateGenerator extends Command
$n_error ++; $n_error ++;
} }
} }
}
$output->writeln(""); $output->writeln("");
$output->write(sprintf('%d templates generated. ', $n_ok)); $output->write(sprintf('%d templates generated. ', $n_ok));