Example #1
0
 public function render(Project $project, $callback = null)
 {
     $this->twig->setCache($project->getCacheDir() . '/twig');
     $diff = $this->getDiff($project);
     if ($diff->isEmpty()) {
         return $diff;
     }
     $this->steps = count($diff->getModifiedClasses()) + count($diff->getModifiedNamespaces()) + count($this->getTheme($project)->getTemplates('global')) + 1;
     $this->step = 0;
     $this->theme = $this->getTheme($project);
     $dirs = $this->theme->getTemplateDirs();
     // add parent directory to be able to extends the same template as the current one but in the parent theme
     foreach ($dirs as $dir) {
         $dirs[] = dirname($dir);
     }
     $this->twig->getLoader()->setPaths(array_unique($dirs));
     $this->twig->addGlobal('has_namespaces', $project->hasNamespaces());
     $this->twig->addGlobal('page_layout', 'layout/page.twig');
     $this->twig->addGlobal('project', $project);
     $this->renderStaticTemplates($project, $callback);
     $this->renderGlobalTemplates($project, $callback);
     $this->renderNamespaceTemplates($diff->getModifiedNamespaces(), $project, $callback);
     $this->renderClassTemplates($diff->getModifiedClasses(), $project, $callback);
     // cleanup
     foreach ($diff->getRemovedClasses() as $class) {
         foreach ($this->theme->getTemplates('class') as $target) {
             $this->filesystem->remove(sprintf($target, str_replace('\\', '/', $class)));
         }
     }
     $diff->save();
     return $diff;
 }
 protected function getStoreDir(Project $project)
 {
     $dir = $project->getCacheDir() . '/store';
     if (!is_dir($dir)) {
         $filesystem = new Filesystem();
         $filesystem->mkdir($dir);
     }
     return $dir;
 }