/** * Given a target (bundle name or single template), returns * an array of template references (mockups) related to this * target. In case of a bundle target, both bundle-level and * app-level mockup directories are searched. If a map.yml * file is present, templates referenced in that file are * returned. Otherwise, all the templates found are returned. * * @param string $target Either a bundle name or a template reference * @return array * @throws \Exception If no mockup directory is found */ public function collect($target) { $bundles = $this->kernel->getBundles(); $mockups = []; // look for bundle target if (array_key_exists($target, $bundles)) { $appDir = $this->kernel->getRootDir(); $appMockupDir = $appDir . '/Resources/' . $bundles[$target]->getName() . '/views/mockup'; $bundleMockupDir = $bundles[$target]->getPath() . '/Resources/views/mockup'; $lookupDirs = []; if (file_exists($appMockupDir)) { $lookupDirs[] = $appMockupDir; } if (file_exists($bundleMockupDir)) { $lookupDirs[] = $bundleMockupDir; } if (count($lookupDirs) === 0) { throw new \Exception("Bundle '{$bundles[$target]->getName()}' has no mockup directory"); } $mockups = $this->getTemplates($lookupDirs, $target); } else { // try with simple template // TODO: directory option should be added $mockups[] = Reference::fromTemplate($target); } return $mockups; }
private function makeMap(array $mockups, $targetDir) { $content = $this->twig->loadTemplate('HeVinciMockupBundle::index.html.twig')->render(['mockups' => $mockups]); $map = Reference::fromTemplate('fake::mockup/index.html.twig'); $this->writeFile($map, $content, $targetDir); return $map; }