private function generateRecursive(Directory $tree, Config $params, $base_url = '') { $final = ['title' => $this->prefix . $tree->getTitle()]; $params['base_url'] = $params['base_page'] = $base_url; $params['image'] = str_replace('<base_url>', $base_url, $params['image']); if ($base_url !== '') { $params['entry_page'] = $tree->getFirstPage(); } foreach ($tree->getEntries() as $key => $node) { if ($node instanceof Directory) { $final['children'][$this->prefix . $node->getTitle()] = $this->generateRecursive($node, $params, '../' . $base_url); } elseif ($node instanceof Content) { $params['request'] = $node->getUrl(); $contentType = $this->daux->getContentTypeHandler()->getType($node); $data = ['title' => $this->prefix . $node->getTitle(), 'file' => $node, 'page' => ContentPage::fromFile($node, $params, $contentType)]; // As the page is lazily generated // We do it now to fail fast in case of problem $data['page']->getContent(); if ($key == 'index.html') { $final['title'] = $this->prefix . $tree->getTitle(); $final['file'] = $node; $final['page'] = $data['page']; } else { $final['children'][$data['title']] = $data; } } } return $final; }
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width) { if ($input->getOption('processor')) { $daux->getParams()['processor'] = $input->getOption('processor'); } $class = $daux->getProcessorClass(); if (!empty($class)) { $daux->setProcessor(new $class($daux, $output, $width)); } }
/** * {@inheritdoc} */ public function generateAll(InputInterface $input, OutputInterface $output, $width) { $params = $this->daux->getParams(); $data = ['author' => $params['author'], 'title' => $params['title'], 'subject' => $params['tagline']]; $book = new Book($this->daux->tree, $data); $current = $this->daux->tree->getIndexPage(); while ($current) { $this->runAction('Generating ' . $current->getTitle(), $output, $width, function () use($book, $current, $params) { $contentType = $this->daux->getContentTypeHandler()->getType($current); $content = ContentPage::fromFile($current, $params, $contentType)->getContent(); $book->addPage($current, $content); }); $current = $current->getNext(); } $content = $book->generate(); file_put_contents($input->getOption('destination') . '/file.html', $content); }
/** * @param Entry $node * @param Config $params * @return \Todaymade\Daux\Format\Base\Page */ public function generateOne(Entry $node, Config $params) { if ($node instanceof Raw) { return new RawPage($node->getPath()); } $params['request'] = $node->getUrl(); return ContentPage::fromFile($node, $params, $this->daux->getContentTypeHandler()->getType($node)); }
/** * Serve the documentation * * @throws Exception */ public static function serve() { $daux = new Daux(Daux::LIVE_MODE); $daux->initializeConfiguration(); $class = $daux->getProcessorClass(); if (!empty($class)) { $daux->setProcessor(new $class($daux, new NullOutput(), 0)); } // Set this critical configuration // for the tree generation $daux->getParams()['index_key'] = 'index'; // Improve the tree with a processor $daux->generateTree(); $server = new static($daux); try { $page = $server->handle($_REQUEST); } catch (NotFoundException $e) { http_response_code(404); $page = new ErrorPage('An error occured', $e->getMessage(), $daux->getParams()); } if ($page instanceof RawPage) { header('Content-type: ' . MimeType::get($page->getFile())); // Transfer file in 1024 byte chunks to save memory usage. if ($fd = fopen($page->getFile(), 'rb')) { while (!feof($fd)) { echo fread($fd, 1024); } fclose($fd); } return; } header('Content-type: text/html; charset=utf-8'); echo $page->getContent(); }
protected function prepareDaux(InputInterface $input) { $daux = new Daux(Daux::STATIC_MODE); // Set the format if requested if ($input->hasOption('format') && $input->getOption('format')) { $daux->getParams()->setFormat($input->getOption('format')); } // Set the source directory if ($input->getOption('source')) { $daux->getParams()->setDocumentationDirectory($input->getOption('source')); } if ($input->getOption('themes')) { $daux->getParams()->setThemesDirectory($input->getOption('themes')); } $daux->initializeConfiguration($input->getOption('configuration')); if ($input->hasOption('delete') && $input->getOption('delete')) { $daux->getParams()['confluence']['delete'] = true; } return $daux; }