Exemplo n.º 1
0
 /**
  * Do same stuff than Twig_Loader_Filesystem::exists() plus check if the file is
  * readable.
  *
  * @see  Twig_Loader_Filesystem::exists()
  */
 public function exists($name)
 {
     $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
     $exists = parent::exists($name);
     $readable = false;
     if (true === $exists) {
         $readable = is_readable($this->cache[$name]);
     }
     return $readable;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function exists($template)
 {
     if (parent::exists($template)) {
         return true;
     }
     // same logic as findTemplate below for the fallback
     try {
         $this->cache[(string) $template] = $this->locator->locate($this->parser->parse($template));
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Get a fully qualified path to a given template.
  * @param string $file Filename of the template to find in referenced templates directories.
  * @param string $namespace Namespace of a specific set of templates directories.
  * @return string The full pathname to the template or 'false' if not found.
  */
 public function getTemplatePathname($file, $namespace = false)
 {
     $pathname = false;
     if ($this->_loader->exists($file)) {
         $paths = StringUtils::emptyOrSpaces($namespace) ? $this->_loader->getPaths() : $this->_loader->getPaths(trim($namespace));
         foreach ($paths as $path) {
             $tmp_pathname = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($file, DIRECTORY_SEPARATOR);
             if (file_exists($tmp_pathname)) {
                 $pathname = $tmp_pathname;
                 break;
             }
         }
     }
     return $pathname;
 }
 /**
  * Test if the breadcrumb is functionnal.
  *
  * @cover BreadcrumbExtension::getTemplateName()
  * @cover BreadcrumbExtension::breadcrumbRender()
  * @cover BreadcrumbExtension::breadcrumbDisplay()
  */
 public function testFunctionnal()
 {
     $service = new BreadcrumbService();
     $extension = new BreadcrumbExtension($this->environment, $service);
     // Test default
     $template = $extension->getTemplateName();
     $this->assertEquals('bs_breadcrumb/breadcrumb.html.twig', $template);
     $this->assertTrue($this->filesystemLoader->exists($template));
     ob_start();
     $extension->breadcrumbDisplay();
     $display = ob_get_contents();
     ob_end_clean();
     $html = $extension->breadcrumbRender();
     $this->assertTrue(is_string($html));
     $this->assertGreaterThan(20, strlen($html));
     $this->assertEquals($display, $html);
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $container = $dom->firstChild;
     $this->assertEquals('div', $container->nodeName);
     $this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $container->childNodes->length);
     $row = $container->firstChild;
     $this->assertEquals('div', $row->nodeName);
     $this->assertEquals('row', $row->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $row->childNodes->length);
     $breadcrumb = $row->firstChild;
     $this->assertEquals('ol', $breadcrumb->nodeName);
     $this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(0, $breadcrumb->childNodes->length);
     // Test content
     $data_test = array(array('Page 1 ' . uniqid(), '/', 'glyphicon-home'), array('Page 2 ' . uniqid(), 'bootstrap-bundle-test-route', null), array('Page 3 ' . uniqid(), null, null));
     foreach ($data_test as $attrs) {
         $link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
         $service->pushLink($link);
     }
     $html = $extension->breadcrumbRender();
     $dom->loadXML($html);
     $breadcrumb = $dom->firstChild->firstChild->firstChild;
     $this->assertEquals('ol', $breadcrumb->nodeName);
     $this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(3, $breadcrumb->childNodes->length);
     foreach ($breadcrumb->childNodes as $k => $node) {
         $this->assertEquals($data_test[$k][0], $node->nodeValue);
     }
     $this->assertEquals('a', $breadcrumb->childNodes->item(0)->firstChild->nodeName);
     $this->assertEquals('a', $breadcrumb->childNodes->item(1)->firstChild->nodeName);
     $this->assertEquals('#text', $breadcrumb->childNodes->item(2)->firstChild->nodeName);
     $this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($data_test[1][1], $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals('i', $breadcrumb->childNodes->item(0)->firstChild->firstChild->nodeName);
     $this->assertEquals('#text', $breadcrumb->childNodes->item(1)->firstChild->firstChild->nodeName);
     $this->assertEquals('glyphicon ' . $data_test[0][2], $breadcrumb->childNodes->item(0)->firstChild->firstChild->attributes->getNamedItem('class')->nodeValue);
     // Test with the url generator
     $service = new BreadcrumbService($this->urlGenerator);
     $extension = new BreadcrumbExtension($this->environment, $service);
     foreach ($data_test as $attrs) {
         $link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
         $service->pushLink($link);
     }
     $html = $extension->breadcrumbRender();
     $dom->loadXML($html);
     $breadcrumb = $dom->firstChild->firstChild->firstChild;
     $this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($this->urlGenerator->generate($data_test[1][1]), $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
 }
Exemplo n.º 5
0
 /**
  * Modification view opencart
  * @param       $template
  * @param array $data
  * @return string
  */
 public function view($template, $data = array())
 {
     //se o twig for desativado
     if (!Util::getConfig('enable_twig')) {
         return $this->viewRaw($template, $data);
     }
     \Twig_Autoloader::register();
     $paths = [];
     //pega o nome do template atual
     $current_theme = Util::getConfig('config_template');
     //remove theme paths
     $view = str_replace(['default/template/', $current_theme . '/template/'], '', $template);
     //check vqmod view
     $vqmod_template = Vqmod::modCheck(DIR_TEMPLATE . $current_theme . '/' . $view);
     if (strpos($vqmod_template, DIR_VQMOD_CACHE) !== false) {
         $paths[] = DIR_VQMOD_CACHE;
         $view = str_replace(DIR_VQMOD_CACHE, '', $vqmod_template);
     } else {
         if (Util::getConfig('is_admin')) {
             $paths[] = DIR_TEMPLATE;
         } else {
             //load theme view
             if (is_dir(DIR_TEMPLATE . $current_theme . '/template/')) {
                 $paths[] = DIR_TEMPLATE . $current_theme . '/template/';
             }
             //load theme default
             if (is_dir(DIR_TEMPLATE . Util::getConfig('theme_default') . '/template/')) {
                 $paths[] = DIR_TEMPLATE . Util::getConfig('theme_default') . '/template/';
             }
         }
     }
     //Get all extensions
     $extensions = Extension::getAll();
     if ($extensions) {
         //load extension view
         if (Util::getConfig('is_admin')) {
             foreach (Util::getConfig('admin_extensions_paths') as $path_extension) {
                 $extensions_path = glob(DIR_ROOT . '/' . Util::getConfig('extension_path') . '/*/*/' . $path_extension . '/view/template/', GLOB_ONLYDIR);
                 if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
                     $paths = array_merge($paths, $extensions_path);
                 }
             }
         } else {
             $extensions_path = glob(DIR_ROOT . '/' . Util::getConfig('extension_path') . '/*/*/' . Util::getConfig('theme_path') . '/template/', GLOB_ONLYDIR);
             if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
                 foreach ($extensions_path as $item) {
                     if (file_exists($item . $view)) {
                         $template = $view;
                         $paths = array_merge($paths, $extensions_path);
                     }
                 }
             }
         }
     }
     $fileSystem = new \Twig_Loader_Filesystem($paths);
     $cache = false;
     if (Util::getConfig('twig_cache')) {
         $cache = DIR_STORAGE . '/' . Util::getConfig('twig_cache');
     }
     $twig = new \Twig_Environment($fileSystem, array('autoescape' => Util::getConfig('twig_autoescape'), 'cache' => $cache, 'debug' => Util::getConfig('twig_debug')));
     $twig->addExtension(new \Twig_Extension_Debug());
     $twig->addExtension(new Ecommerce(Util::getRegistry()));
     Util::getRegistry()->set('twig', $twig);
     extract($data);
     ob_start();
     if ($fileSystem->exists(str_replace('.tpl', '', $view) . '.twig', $data)) {
         $output = Util::getRegistry()->get('twig')->render(str_replace('.tpl', '', $view) . '.twig', $data);
     } else {
         if ($fileSystem->exists($view, $data)) {
             $output = Util::getRegistry()->get('twig')->render($view, $data);
         } else {
             trigger_error('Error: Could not load template ' . $template . '!');
             exit;
         }
     }
     eval(' ?>' . $output);
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  *
  * The name parameter might also be a TemplateReferenceInterface.
  */
 public function exists($name)
 {
     return parent::exists((string) $name);
 }
Exemplo n.º 7
0
 /**
  * @param string $name
  *
  * @return bool
  */
 public function exists($name)
 {
     $name = $this->getName($name);
     return parent::exists($name);
 }
Exemplo n.º 8
0
 public function exists($name)
 {
     return $this->loader->exists($this->getName($name));
 }
Exemplo n.º 9
0
 public function view($template, $data = array())
 {
     Twig_Autoloader::register();
     $paths = [];
     //pega o nome do template atual
     $template_name = $this->registry->get('config')->get('config_template');
     //fix se ta sentando tema default
     if (strpos($template, 'default/template/') !== false) {
         $template = str_replace('default/template/', $template_name . '/template/', $template);
     }
     //check vqmod view
     $vqmod_template = VQMod::modCheck(DIR_TEMPLATE . $template);
     if (strpos($vqmod_template, DIR_VQMOD_CACHE) !== false) {
         $paths[] = DIR_VQMOD_CACHE;
         $template = str_replace(DIR_VQMOD_CACHE, '', $vqmod_template);
     } else {
         //load theme view
         if (is_dir(DIR_TEMPLATE . $template_name . '/template')) {
             $paths[] = DIR_TEMPLATE . $template_name . '/template';
         }
         if (is_dir(DIR_TEMPLATE . 'default/template')) {
             $paths[] = DIR_TEMPLATE . 'default/template';
         }
         //load others view
         $paths[] = DIR_TEMPLATE;
         //load extension view
         if (IS_ADMIN) {
             $extensions_path = glob(DIR_ROOT . '/extensions/*/app/' . CATALOG_OR_ADMIN . '/view/template/', GLOB_ONLYDIR);
             if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
                 $paths = array_merge($paths, $extensions_path);
             }
         } else {
             $template_extension = str_replace($template_name . '/template/', '', $template);
             $extensions_path = glob(DIR_ROOT . '/extensions/*/theme/template/', GLOB_ONLYDIR);
             if ($extensions_path && is_array($extensions_path) && count($extensions_path)) {
                 foreach ($extensions_path as $item) {
                     if (file_exists($item . $template_extension)) {
                         $template = $template_extension;
                         $paths = array_merge($paths, $extensions_path);
                     }
                 }
             }
         }
     }
     $fileSystem = new Twig_Loader_Filesystem($paths);
     $loader = new Twig_Loader_Chain([$fileSystem]);
     $cache = false;
     if (defined('TWIG_CACHE')) {
         $cache = TWIG_CACHE;
     }
     $twig = new Twig_Environment($fileSystem, array('autoescape' => false, 'cache' => $cache, 'debug' => true));
     $twig->addExtension(new Twig_Extension_Debug());
     $twig->addExtension(new \Newcart\System\TwigExtensions\Ecommerce($this->registry));
     $this->registry->set('twig', $twig);
     extract($data);
     ob_start();
     // First Step - Render Twig Native Templates
     if ($fileSystem->exists(str_replace('.tpl', '', $template) . '.twig', $data)) {
         $output = $this->registry->get('twig')->render(str_replace('.tpl', '', $template) . '.twig', $data);
     } else {
         $output = $this->registry->get('twig')->render($template, $data);
     }
     // Second Step - IF template has PHP Syntax, then execute
     eval(' ?>' . $output);
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
 /**
  * Test is the navbar is functionnal.
  *
  * @cover NavbarExtension::navbarRender()
  * @cover NavbarExtension::navbarDisplay()
  */
 public function testOutput()
 {
     $container = new NavbarService();
     $extension = new NavbarExtension($this->environment, $container, $this->configuration);
     // Test default
     $template = $extension->getTemplateName();
     $this->assertEquals('bs_navbar/navbar.html.twig', $template);
     $this->assertTrue($this->filesystemLoader->exists($template));
     ob_start();
     $extension->navbarDisplay();
     $display = ob_get_contents();
     ob_end_clean();
     $html = $extension->navbarRender();
     $this->assertTrue(is_string($html));
     $this->assertGreaterThan(20, strlen($html));
     $this->assertEquals($display, $html);
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $navbar = $dom->firstChild;
     $this->assertEquals('nav', $navbar->nodeName);
     $this->assertEquals('navbar navbar-fixed-top', $navbar->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $navbar->childNodes->length);
     $container = $navbar->firstChild;
     $this->assertEquals('div', $container->nodeName);
     $this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(2, $container->childNodes->length);
     $header = $container->firstChild;
     $this->assertEquals('div', $header->nodeName);
     $this->assertEquals('navbar-header', $header->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(2, $header->childNodes->length);
     $collapse = $container->childNodes->item(1);
     $this->assertEquals('div', $collapse->nodeName);
     $this->assertEquals('collapse navbar-collapse', $collapse->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals('neimheadh-bootstrap-navbar-collapse', $collapse->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals(1, $collapse->childNodes->length);
     $menus = $collapse->firstChild;
     $this->assertEquals('ul', $menus->nodeName);
     $this->assertEquals('nav navbar-nav navbar-right', $menus->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals('neimheadh-bootstrap-nav', $menus->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals(0, $menus->childNodes->length);
     $button = $header->firstChild;
     $this->assertEquals('button', $button->nodeName);
     $this->assertEquals('button', $button->attributes->getNamedItem('type')->nodeValue);
     $this->assertEquals('navbar-toggle collapsed', $button->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals('collapse', $button->attributes->getNamedItem('data-toggle')->nodeValue);
     $this->assertEquals('#' . $collapse->attributes->getNamedItem('id')->nodeValue, $button->attributes->getNamedItem('data-target')->nodeValue);
     $this->assertEquals('false', $button->attributes->getNamedItem('aria-expanded')->nodeValue);
     $this->assertEquals(4, $button->childNodes->length);
     foreach ($button->childNodes as $i => $node) {
         $this->assertEquals('span', $node->nodeName);
         $this->assertEquals($i == 0 ? 'sr-only' : 'icon-bar', $node->attributes->getNamedItem('class')->nodeValue);
         if ($i == 0) {
             $this->assertEquals('Navigation', $node->nodeValue);
         }
     }
     // Test config
     $configuration = $this->getConfigurationExample('navbar.config1.yml');
     $configuration = $configuration['neimheadh_bootstrap']['navbar'];
     $container = new NavbarService();
     $extension = new NavbarExtension($this->environment, $container, $configuration);
     // The templates will not be good
     $error = false;
     try {
         $extension->navbarRender();
     } catch (\Twig_Error_Loader $e) {
         $error = true;
     }
     $this->assertTrue($error);
     $configuration['template'] = 'bs_navbar/navbar.html.twig';
     $extension->setConfiguration($configuration);
     $error = false;
     try {
         $extension->navbarRender();
     } catch (\Twig_Error_Loader $e) {
         $error = true;
     }
     $this->assertTrue($error);
     $configuration['header']['template'] = 'bs_navbar/navbar-header.html.twig';
     $extension->setConfiguration($configuration);
     $error = false;
     try {
         $extension->navbarRender();
     } catch (\Twig_Error_Loader $e) {
         $error = true;
     }
     $this->assertTrue($error);
     $configuration['menu']['_list']['template'] = 'bs_navbar/navbar-menu.html.twig';
     $extension->setConfiguration($configuration);
     $html = $extension->navbarRender();
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $navbar = $dom->firstChild;
     $container = $navbar->firstChild;
     $header = $container->firstChild;
     $collapse = $container->childNodes->item(1);
     $menus = $collapse->firstChild;
     $button = $header->firstChild;
     $this->assertEquals($configuration['class'] . ' ' . $configuration['position_class'] . ' ' . $configuration['custom_class'], $navbar->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['container']['class'], $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['header']['class'], $header->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['header']['title'], $header->childNodes->item(1)->nodeValue);
     $this->assertEquals($configuration['header']['link'], $header->childNodes->item(1)->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($configuration['menu']['_container']['id'], $collapse->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals('#' . $configuration['menu']['_container']['id'], $button->attributes->getNamedItem('data-target')->nodeValue);
     $this->assertEquals($configuration['menu']['_container']['class'], $collapse->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['menu']['_list']['id'], $menus->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals($configuration['menu']['_list']['class'], $menus->attributes->getNamedItem('class')->nodeValue);
     // Test menus
     $menus_cfg = $configuration['menu']['_menus'][0]['content'];
     $this->assertEquals(4, $menus->childNodes->length);
     foreach ($menus->childNodes as $i => $menu) {
         $this->assertEquals('li', $menu->nodeName);
         $this->assertEquals($configuration['menu']['_list']['children']['class'], $menu->attributes->getNamedItem('class')->nodeValue);
         $this->assertEquals($configuration['menu']['_list']['children']['role'], $menu->attributes->getNamedItem('role')->nodeValue);
         switch ($i) {
             case 3:
                 $i++;
             case 0:
                 $this->assertEquals(2, $menu->childNodes->length);
                 $this->assertEquals('a', $menu->firstChild->nodeName);
                 $this->assertEquals('ul', $menu->childNodes->item(1)->nodeName);
                 $this->assertEquals('dropdown-menu', $menu->childNodes->item(1)->attributes->getNamedItem('class')->nodeValue);
                 $this->assertEquals(1, $menu->childNodes->item(1)->childNodes->length);
                 $this->assertEquals('li', $menu->childNodes->item(1)->firstChild->nodeName);
                 $this->assertEquals($configuration['menu']['_list']['children']['class'], $menu->childNodes->item(1)->firstChild->attributes->getNamedItem('class')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['children']['role'], $menu->childNodes->item(1)->firstChild->attributes->getNamedItem('role')->nodeValue);
                 $this->assertEquals(1, $menu->childNodes->item(1)->firstChild->childNodes->length);
                 $this->assertEquals('a', $menu->childNodes->item(1)->firstChild->firstChild->nodeName);
                 $this->assertEquals($menus_cfg[$i == 4 ? 5 : 2]['title'], $menu->childNodes->item(1)->firstChild->firstChild->nodeValue);
                 $this->assertEquals($menus_cfg[$i == 4 ? 5 : 2]['route'], $menu->childNodes->item(1)->firstChild->firstChild->attributes->getNamedItem('href')->nodeValue);
                 $this->assertEquals(2, $menu->firstChild->childNodes->length);
                 $this->assertEquals('#text', $menu->firstChild->firstChild->nodeName);
                 $this->assertEquals('span', $menu->firstChild->childNodes->item(1)->nodeName);
                 $this->assertEquals($menus_cfg[$i]['title'], trim($menu->firstChild->firstChild->nodeValue));
                 $this->assertEquals($i == 4 ? '#' : $menus_cfg[$i]['route'], $menu->firstChild->attributes->getNamedItem('href')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['class'], $menu->firstChild->attributes->getNamedItem('class')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['data_toggle'], $menu->firstChild->attributes->getNamedItem('data-toggle')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['role'], $menu->firstChild->attributes->getNamedItem('role')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['aria']['haspopup'], $menu->firstChild->attributes->getNamedItem('aria-haspopup')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['aria']['expanded'], $menu->firstChild->attributes->getNamedItem('aria-expanded')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['caret']['class'], $menu->firstChild->childNodes->item(1)->attributes->getNamedItem('class')->nodeValue);
                 break;
             case 2:
                 $i++;
             case 1:
                 $this->assertEquals(1, $menu->childNodes->length);
                 $this->assertEquals('a', $menu->firstChild->nodeName);
                 $this->assertEquals($menus_cfg[$i]['title'], $menu->firstChild->nodeValue);
                 $this->assertEquals($menus_cfg[$i]['route'], $menu->firstChild->attributes->getNamedItem('href')->nodeValue);
                 break;
         }
     }
 }
Exemplo n.º 11
0
Arquivo: Blog.php Projeto: ospii/oblog
 /**
  * Generate HTML from source + templates and sitemap.xml into output directory.
  *
  * @return bool
  */
 public function generateStaticPosts()
 {
     if ($this->sourcePath === null || $this->templatePath === null || $this->outputPath === null) {
         throw new \InvalidArgumentException('Check paths');
     }
     $sourceFiles = array();
     foreach (glob($this->sourcePath . '/*.md') as $mdFile) {
         $sourceFiles[] = $mdFile;
     }
     if (count($sourceFiles) === 0) {
         throw new \LengthException('No Markdown files found to crunch.');
     }
     /**
      * Source files prefixed with running number => goodness
      * '1-first-post.md','2-second-post.md' etc.
      */
     natsort($sourceFiles);
     $sourceFiles = array_reverse($sourceFiles);
     $lastPostKey = false;
     $postFilenames = $links = $posts = array();
     foreach ($sourceFiles as $key => $mdFile) {
         $post = new Post($mdFile);
         if ($post->isPublic()) {
             $links[] = array('url' => $post->getHtmlFilename(), 'title' => $post->getTitle());
         }
         if ($lastPostKey === false && $post->isPublic()) {
             $lastPostKey = $key;
         }
         if (array_search($post->getHtmlFilename(), $postFilenames) !== false) {
             throw new \LogicException('Titles resulting in identical filenames found "' . $post->getTitle() . '"');
         }
         $postFilenames[] = $post->getHtmlFilename();
         $posts[$key] = $post;
     }
     foreach (glob($this->outputPath . '/*.html') as $htmlFile) {
         unlink($htmlFile);
     }
     $twigLoader = new \Twig_Loader_Filesystem($this->templatePath);
     $twig = new \Twig_Environment($twigLoader);
     $siteMapUrls = array();
     /* @var $post \Oblog\Post */
     foreach ($posts as $key => $post) {
         $postHtml = $twig->render('post.html', array('title' => $post->getTitle(), 'modifiedAt' => $post->getModifiedAt(), 'post' => $post->getHtml(), 'filename' => $post->getHtmlFilename()));
         $pageVariables = array('article' => $postHtml, 'links' => $links, 'title' => $post->getTitle(), 'baseUrl' => $this->baseUrl, 'filename' => $post->getHtmlFilename());
         if ($key == $lastPostKey) {
             $pageVariables['canonical'] = $this->baseUrl . '/' . $post->getHtmlFilename();
         }
         $pageHtml = $twig->render('page.html', $pageVariables);
         $outputFilename = $post->getHtmlFilename();
         file_put_contents($this->outputPath . '/' . $outputFilename, $pageHtml);
         touch($this->outputPath . '/' . $outputFilename, $post->getModifiedAt());
         if ($key == $lastPostKey) {
             file_put_contents($this->outputPath . '/index.html', $pageHtml);
         }
         if ($post->isPublic()) {
             $siteMapUrls[] = array('loc' => $this->baseUrl . '/' . $outputFilename, 'priority' => 0.5, 'lastmod' => date('Y-m-d', $post->getModifiedAt()), 'title' => $post->getTitle(), 'updated' => date('c', $post->getModifiedAt()));
         } else {
             echo PHP_EOL . 'DRAFT at ' . $this->baseUrl . '/' . $outputFilename;
         }
     }
     $feedUrls = $siteMapUrls;
     if ($lastPostKey !== false) {
         $siteMapUrls[] = array('loc' => $this->baseUrl . '/', 'priority' => '1', 'lastmod' => date('Y-m-d', $posts[$lastPostKey]->getModifiedAt()), 'changefreq' => 'daily');
     }
     if ($twigLoader->exists('sitemap.xml')) {
         $sitemapXml = $twig->render('sitemap.xml', array('urls' => $siteMapUrls));
         $path = $this->outputPath . '/sitemap.xml';
         file_put_contents($path, $sitemapXml);
         echo PHP_EOL . "Sitemap generated to " . $path . ' ' . $this->baseUrl . '/' . basename($path);
     }
     if ($twigLoader->exists('atom.xml')) {
         $atomFeed = $twig->render('atom.xml', array('urls' => $feedUrls, 'name' => $this->name, 'author' => $this->author, 'baseUrl' => $this->baseUrl));
         $path = $this->outputPath . '/atom.xml';
         file_put_contents($path, $atomFeed);
         echo PHP_EOL . "Atom feed generated to " . $path . ' ' . $this->baseUrl . '/' . basename($path);
     }
     if ($twigLoader->exists('rss.xml')) {
         $atomFeed = $twig->render('rss.xml', array('urls' => $feedUrls, 'name' => $this->name, 'author' => $this->author, 'baseUrl' => $this->baseUrl, 'description' => $this->description));
         $path = $this->outputPath . '/rss.xml';
         file_put_contents($path, $atomFeed);
         echo PHP_EOL . "RSS feed generated to " . $path . ' ' . $this->baseUrl . '/' . basename($path);
     }
     return true;
 }