public function testToArray() { date_default_timezone_set('Europe/Zurich'); $path = TESTS_PATH . '/Fixtures/site/pages/pagedata.md'; $parser = new \Symfony\Component\Yaml\Parser(); $loader = new Herbie\Loader\PageLoader($path, $parser); $page = new Herbie\Page(); $page->load($loader); $array = ['layout' => 'layout.html', 'type' => 'my_type', 'title' => 'My Title', 'date' => '2013-12-24T00:00:00+01:00', 'abstract' => 'This is a short text.', 'keywords' => 'Keyword 1, Keyword 2, Keyword 3']; $this->assertSame($array, $page->toArray()); return $page; }
protected function addBlocksTag() { $this->add('blocks', function ($options) { $options = array_merge(['path' => DI::get('Page')->getDefaultBlocksPath(), 'sort' => '', 'shuffle' => 'false'], (array) $options); // collect pages $extensions = $this->config->get('pages.extensions', []); $path = $options['path']; $paths = [$path => DI::get('Alias')->get($path)]; $pageBuilder = new Herbie\Menu\Page\Builder($paths, $extensions); $collection = $pageBuilder->buildCollection(); if (!empty($options['sort'])) { list($field, $direction) = explode('|', $options['sort']); $collection = $collection->sort($field, $direction); } if ('true' == strtolower($options['shuffle'])) { $collection = $collection->shuffle(); } $twig = DI::get('Twig'); // store page $page = DI::get('Page'); $return = ''; foreach ($collection as $i => $item) { $block = Herbie\Page::create($item->path); DI::set('Page', $block); // self-contained blocks aka widgets if (!empty($block->layout) && file_exists($paths[$path] . '/.layouts/' . $block->layout)) { $block->layout = $path . '/.layouts/' . $block->layout; } if (empty($block->layout)) { $return .= $twig->renderPageSegment(0, $block); } else { $twig->getEnvironment()->getExtension('herbie')->setPage($block); $return .= $twig->render($block->layout, ['block' => $block]); } $return .= "\n"; } // restore page $twig->getEnvironment()->getExtension('herbie')->setPage($page); DI::set('Page', $page); return trim($return); }); }
protected function addBlocksTag() { $this->add('blocks', function ($options) { $options = array_merge(['path' => Herbie\DI::get('Page')->getDefaultBlocksPath(), 'sort' => '', 'shuffle' => 'false'], (array) $options); // collect pages $extensions = $this->config->get('pages.extensions', []); $path = $options['path']; $paths = [$path => Herbie\DI::get('Alias')->get($path)]; $pageBuilder = new Herbie\Menu\Page\Builder($paths, $extensions); $collection = $pageBuilder->buildCollection(); if (!empty($options['sort'])) { list($field, $direction) = explode('|', $options['sort']); $collection = $collection->sort($field, $direction); } if ('true' == strtolower($options['shuffle'])) { $collection = $collection->shuffle(); } $twig = Herbie\DI::get('Twig'); ob_start(); foreach ($collection as $i => $item) { $block = Herbie\Page::create($item->path); if (!empty($block->layout) && $block->layout == 'default.html') { $block->layout = false; } if (empty($block->layout)) { echo $twig->renderPageSegment(0, $block); } else { $twig->getEnvironment()->getExtension('herbie')->setPage($block); echo $twig->render($block->layout); } ob_flush(); } return ob_get_clean(); }); }