public function onDocuments(CarewEvent $event) { $document = new Document(); $document->setLayout('index.atom.twig')->setPath('feed/atom.xml')->setFilePath('feed/atom'); $documents = $event->getSubject(); $documents[$document->getFilePath()] = $document; $event->setSubject($documents); $globals = $event['globals']; $globals->documents = array_replace($globals->documents, $documents); }
public function onDocuments(CarewEvent $event) { $documents = $event->getSubject(); $globals = $event['globals']; foreach ($globals->tags as $tagName => $documentList) { $documentList = array_filter($documentList, function (Document $document) { return $document->isTypePost(); }); $document = new Document(); $document->setLayout('index.atom.twig')->setPath(sprintf('tags/%s/feed/atom.xml', $this->inflector->urlize($tagName)))->setFilePath(sprintf('tags/%s/feed/atom', $tagName))->setVar('post', $documentList); $documents[$document->getFilePath()] = $document; } $event->setSubject($documents); $globals->documents = array_replace($globals->documents, $documents); }
public function onDocuments(CarewEvent $event) { $documents = $event->getSubject(); $globals = $event['globals']; $tags = array(); foreach ($globals->tags as $tagName => $documentList) { $tagDocument = new Document(); $tagDocument->setLayout('default.html.twig')->setBody('{{ render_documents(carew.documents) }}')->setPath(sprintf('tags/%s.html', $this->inflector->urlize($tagName)))->setTitle('Tag #' . $tagName)->setFilePath('tags/' . $tagName)->setNavigations(array('tags', 'sub-tags'))->setVar('documents', $documentList); $documents[$tagDocument->getFilePath()] = $tagDocument; $tags[$tagDocument->getFilePath()] = $tagDocument; } $tagsDocument = new Document(); $tagsDocument->setLayout('default.html.twig')->setBody('{{ render_documents(carew.tags) }}')->setPath('tags/index.html')->setTitle('Tags')->setFilePath('tags')->setNavigations('tags')->setVar('tags', $tags); $documents[$tagsDocument->getFilePath()] = $tagsDocument; $globals->documents = array_replace($globals->documents, $documents); $event->setSubject($documents); }
public function setUp() { $this->container = new \Pimple(); $this->extension = new CarewExtension($this->container); $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array(__DIR__ . '/fixtures/theme1', __DIR__ . '/fixtures/theme2', __DIR__ . '/../../Twig/Resources/layouts'))); $documents = array(); for ($i = 1; $i <= 20; ++$i) { $document = new Document(); $document->setTitle('Doc #' . $i); $document->setTags('Tag #' . $i % 5); $document->setFilePath('pages/page-' . $i); $document->setPath('pages/page-' . $i . '.html'); $documents[$document->getFilePath()] = $document; } $processor = new Processor(); $this->globals = $processor->processGlobals($documents); $this->documents = $documents; $this->twig->addGlobal('carew', $this->globals); $this->twig->addExtension($this->extension); }