Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $options = $input->getOptions();
     //Possible skeletons
     $dirGenerator = __DIR__ . '/../../../generator/';
     $dirBase = __DIR__ . '/../../../../../';
     $dirProject = $dirBase . '/project/';
     $skeleton = isset($options['skeleton']) ? $options['skeleton'] : 'empty';
     if (is_dir($dirProject)) {
         mkdir($dirProject);
     }
     $srcDir = $dirGenerator . 'skeleton/' . $skeleton;
     if (is_dir($srcDir)) {
         Util::recurse_copy($srcDir, $dirProject);
     } else {
         $output->write("Skeleton <info>{$skeleton}</info> does not exist in <info>" . $dirGenerator . "skeleton/'</info>" . PHP_EOL);
     }
     $appName = $skeleton == 'empty' ? 'myApp.php' : $skeleton . ".php";
     $srcApp = $dirGenerator . 'app/myApp.php';
     copy($srcApp, $dirBase . $appName);
 }
Exemple #2
0
 public function make()
 {
     $app = $this;
     $pages = array();
     if ($handle = opendir($app['twig.templates'])) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 $page = $app->parse($file);
                 //get the extension
                 preg_match('/\\.(.*)$/', $file, $matches);
                 if ($matches) {
                     $extension = $matches[1];
                 } else {
                     //TODO: throw unknown format exception
                 }
                 switch ($extension) {
                     case 'twig':
                         break;
                     case 'md':
                         $block = isset($page['block']) ? $page['block'] : 'content';
                         $layout = isset($page['layout']) ? $page['layout'] : 'layout.twig';
                         if ($layout != 'none') {
                             $newContent = '{% extends "' . $layout . '" %}';
                         }
                         $newContent .= '{% block ' . $block . ' %}';
                         $newContent .= $app['markdown']->transform($page->getContent());
                         $newContent .= '{% endblock %}';
                         $page->setContent($newContent);
                         break;
                     default:
                         //TODO: throw unknown format exception
                 }
                 $fileOutputName = preg_replace('/\\.' . $extension . '$/', '.html', $file);
                 $page['ifilename'] = $file;
                 $page['filename'] = $fileOutputName;
                 $page = $this->executeModifiers($page);
                 array_push($pages, $page);
             }
         }
     }
     if (file_exists($app['cache'] . '/pages') && ($handle = opendir($app['cache'] . '/pages'))) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 $page = $app->parse($file);
                 $fileOutputName = preg_replace('/\\.twig/', '.html', $file);
                 $page['ifilename'] = $file;
                 $page['filename'] = $fileOutputName;
                 $page = $this->executeModifiers($page);
                 array_push($pages, $page);
             }
         }
     }
     $this->executePostModifiers();
     foreach ($pages as $page) {
         $fh = fopen($app['output'] . '/' . $page['filename'], 'w');
         $page = $this->compile($page);
         fwrite($fh, $page->getRenderedContent());
         fclose($fh);
     }
     //finally, just copy static content
     Util::recurse_copy($app['static'], $app['output']);
 }