Example #1
0
 /** Show template choosing dialog */
 private function chooseTemplatesDialog()
 {
     CLI::write('What templates do you want to use?', 0, TRUE, TRUE, TRUE);
     CLI::write('Press Enter for default ones.', 1);
     CLI::write('Write templates name for specific ones.', 1);
     CLI::write('Getting list of available templates:', 1);
     $templates = ['Default'];
     foreach (\Nette\Utils\Finder::findFiles('TemplateLoader.php')->from(static::$settings->netteRoot) as $file) {
         foreach (\Bruha\Generator\Utils\File::getClassesFromPHPFile($file) as $class) {
             $templates[realpath($file) . '-' . mt_rand(1000, 9999)] = str_replace('Template', '', $class);
         }
     }
     foreach ($templates as $template) {
         CLI::write($template, 2);
     }
     CLI::write('Your choice: ', 1, TRUE, FALSE);
     $input = CLI::read(FALSE, $templates, function ($input) {
         CLI::write("Uknown choice '{$input}'. Try it again, please.", 2);
         CLI::write('Your choice: ', 1, TRUE, FALSE);
     });
     if (!$input || strtolower($input) === 'default') {
         CLI::write('Pressed Enter, using Default template.', 2);
         return;
     }
     static::$settings->template = dirname(mb_substr(array_search($input, $templates), 0, -5)) . "\\{$input}";
 }