/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $project = new Project(getcwd()); if ($project->isValid()) { $books = $project->getBooks($input->getOption('locale')); if (count($books)) { $table = new Table($output); $table->setHeaders(['Name', 'Title', 'Pages', 'Position']); foreach ($books as $book) { $table->addRow([$book->getShortName(), $book->getTitle(), $book->getPages()->count(), $book->getPosition()]); } $table->render(); $output->writeln(''); if (count($books) === 1) { $output->writeln('1 book found'); } else { $output->writeln(count($books) . ' books found'); } } else { $output->writeln('0 books found'); } } else { $output->writeln('<error>This is not a valid Shade project</error>'); } }
/** * @param Project $project * @param string|null $locale */ private function renderEverything(Project &$project, $locale) { foreach ($project->getBooks($locale) as $book) { $book->renderBody(); foreach ($book->getPages() as $page) { $page->renderBody(); } } foreach ($project->getWhatsNewArticles($locale) as $article) { $article->renderBody(); } foreach ($project->getReleases($locale) as $release) { $release->renderBody(); } foreach ($project->getVideos($locale) as $video) { $video->renderBody(); } }
/** * Build books and book pages * * @param InputInterface $input * @param OutputInterface $output * @param Project $project * @param string $target_path * @param Theme $theme * @param string $locale * @return bool * @throws Exception * @throws \SmartyException */ public function buildBooks(InputInterface $input, OutputInterface $output, Project $project, $target_path, Theme $theme, $locale) { $books_path = $locale === $project->getDefaultLocale() ? "{$target_path}/books" : "{$target_path}/{$locale}/books"; $books_images_path = $locale === $project->getDefaultLocale() ? "{$target_path}/assets/images/books" : "{$target_path}/assets/images/{$locale}/books"; Shade::createDir($books_path, function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); Shade::createDir($books_images_path, function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); $books = $project->getBooks($locale); $this->skipBooks($input, $books); foreach ($books as $book) { $this->copyBookImages($project, $book, $target_path, $locale, $output); } $this->smarty->assign(['books' => $books, 'page_level' => 1, 'current_section' => 'books']); Shade::writeFile("{$books_path}/index.html", $this->smarty->fetch('books.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); foreach ($books as $book) { Shade::createDir("{$books_path}/" . $book->getShortName(), function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); $pages = $book->getPages(); $this->smarty->assign(['current_book' => $book, 'page_level' => 2, 'pages' => $pages, 'current_page' => $this->getCurrentPage($pages), 'sidebar_image' => '../../assets/images/books/' . $book->getShortName() . '/_cover_small.png']); Shade::writeFile("{$books_path}/" . $book->getShortName() . "/index.html", $this->smarty->fetch('book_page.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); foreach ($pages as $page) { $this->smarty->assign(['current_page' => $page]); Shade::writeFile("{$books_path}/" . $book->getShortName() . "/" . $page->getShortName() . ".html", $this->smarty->fetch('book_page.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); } } return true; }