Example #1
0
 public function render(Project $project, $callback = null, $force = false)
 {
     $this->twig->setCache($cacheDir = $project->getCacheDir() . '/twig');
     if ($force) {
         $project->flushDir($cacheDir);
     }
     $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('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;
 }