/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { ini_set('date.timezone', 'UTC'); $project = new Project(getcwd()); if ($project->isValid()) { Shade::initSmarty($project, Shade::getBuildTheme($project->getDefaultBuildTheme())); $this->renderEverything($project, $input->getOption('locale')); $todo_notes = Shade::getTodo(); if (count($todo_notes)) { $table = new Table($output); $table->setHeaders(['Message', 'File']); $path_len = strlen(rtrim($project->getPath(), '/')); foreach ($todo_notes as $todo_note) { $table->addRow([$todo_note['message'], substr($todo_note['file'], $path_len + 1)]); } $table->render(); $output->writeln(''); if (count($todo_notes) === 1) { $output->writeln('1 todo note found'); } else { $output->writeln(count($todo_notes) . ' todo notes found'); } } else { $output->writeln('0 todo notes found'); } } else { $output->writeln('<error>This is not a valid Shade project</error>'); } }
/** * Return page slug * * @return string */ public function getSlug() { if ($this->slug === null) { $slug = $this->getProperty('slug'); if (empty($slug)) { $this->slug = Shade::slug($this->getTitle()); } else { $this->slug = $slug; } } return $this->slug; }
/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $project = new Project(getcwd()); if ($project->isValid()) { $table = new Table($output); $table->setHeaders(['Plugin', 'Enabled?']); foreach (Shade::getPlugins($project) as $plugin) { $is_enabled = $plugin->isEnabled(); if ($is_enabled === true) { $is_enabled = 'Yes'; } elseif ($is_enabled === false) { $is_enabled = ''; } $table->addRow([$plugin->getName(), $is_enabled]); } $table->render(); } else { $output->writeln('<error>This is not a valid Shade project</error>'); } }
/** * @param Project $project */ function __construct(Project &$project) { $this->project = $project; $this->finders = ['findBookDirs' => function ($books_path) { $dirs = []; if (is_dir($books_path)) { foreach (new DirectoryIterator($books_path) as $dir) { if (!$dir->isDot() && $dir->isDir()) { $dirs[] = $dir->getPathname(); } } } return $dirs; }, 'findBookPageFiles' => function ($pages_path) { $files = []; if (is_dir($pages_path)) { foreach (new DirectoryIterator($pages_path) as $file) { if ($file->isFile() && $file->getExtension() == 'md') { $files[] = $file->getPathname(); } } sort($files); } return $files; }, 'findVideoFiles' => function ($videos_path) { $files = []; if (is_dir($videos_path)) { foreach (new DirectoryIterator($videos_path) as $file) { if ($file->isFile() && $file->getExtension() == 'md') { $files[] = $file->getPathname(); } } sort($files); } return $files; }, 'findReleaseFiles' => function ($releases_path) { $files = []; if (is_dir($releases_path)) { foreach (new DirectoryIterator($releases_path) as $file) { if ($file->isFile() && $file->getExtension() == 'md') { $version_number = substr($file->getFilename(), 0, strlen($file->getFilename()) - 3); if (Shade::isValidVersionNumber($version_number)) { $files[$version_number] = $file->getPathname(); } } } uksort($files, function ($a, $b) { return version_compare($b, $a); }); } return $files; }, 'findWhatsNewFiles' => function ($whats_new_articles_path) { $files = []; if (is_dir($whats_new_articles_path)) { foreach (new DirectoryIterator($whats_new_articles_path) as $version_dir) { if (!$version_dir->isDot() && $version_dir->isDir() && Shade::isValidVersionNumber($version_dir->getFilename())) { $version_num = $version_dir->getFilename(); foreach (new DirectoryIterator($version_dir->getPathname()) as $file) { if ($file->isFile() && $file->getExtension() == 'md') { $files[$version_num][] = $file->getPathname(); } } } } if (count($files)) { ksort($files); foreach ($files as $version_num => $version_articles) { sort($files[$version_num]); } } } return $files; }]; }
/** * Render security block in release notes * * Note: This block is available only in release notes! * * @param array $params * @param string $content * @param Smarty $smarty * @param boolean $repeat * @return string|void * @throws ParamRequiredError * @throws Exception */ public static function block_security($params, $content, &$smarty, &$repeat) { if ($repeat) { return; } if (self::$current_element instanceof Release) { return '<p>Security:</p>' . Shade::markdownToHtml(trim($content)); } else { throw new Exception('added block is available for release notes only'); } }
/** * Return page slug * * @return string */ public function getSlug() { if ($this->slug === null) { $this->slug = ''; // str_replace('.', '-', $this->version_number) . '-'; $slug = $this->getProperty('slug'); if (empty($slug)) { $this->slug .= Shade::slug($this->getTitle()); } else { $this->slug .= $slug; } } return $this->slug; }
/** * Build videos * * @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 buildVideos(InputInterface $input, OutputInterface $output, Project $project, $target_path, Theme $theme, $locale) { $videos_path = $locale === $project->getDefaultLocale() ? "{$target_path}/videos" : "{$target_path}/{$locale}/videos"; Shade::createDir($videos_path, function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); if (is_dir($project->getFinder()->getVideosPath($locale) . '/images')) { $video_images_path = $locale === $project->getDefaultLocale() ? "{$target_path}/assets/images/videos" : "{$target_path}/assets/images/{$locale}/videos"; Shade::createDir($video_images_path, function ($path) use(&$output) { $output->writeln("Directory '{$path}' created"); }); Shade::copyDir($project->getFinder()->getVideosPath($locale) . '/images', $video_images_path, null, function ($path) use(&$output) { $output->writeln("{$path} copied"); }); } $videos = $project->getVideos(); if (!$videos->count()) { return true; // Skip video section rendering } $video_groups = $project->getVideoGroups(); $this->smarty->assign(['video_groups' => $video_groups, 'videos' => $videos, 'page_level' => 1, 'video_player' => $project->getVideoPlayer(), 'current_video' => $this->getCurrentVideo($video_groups, $videos), 'current_section' => 'videos']); Shade::writeFile("{$videos_path}/index.html", $this->smarty->fetch('videos.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); foreach ($videos as $video) { $this->smarty->assign(['current_video' => $video]); Shade::writeFile("{$videos_path}/" . $video->getSlug() . ".html", $this->smarty->fetch('videos.tpl'), function ($path) use(&$output) { $output->writeln("File '{$path}' created"); }); } return true; }
/** * Return array of video groups * * @return array */ public function getVideoGroups() { if ($this->video_groups === false) { $this->video_groups = $this->getConfigurationOption('video_groups'); if (!is_array($this->video_groups)) { $this->video_groups = [Video::GETTING_STARTED => Shade::lang('Getting Started')]; } } return $this->video_groups; }
/** * Load property value * * @param string $name * @param string $value */ private function loadProperty($name, $value) { $this->properties[Shade::underscore(str_replace(' ', '', $name))] = $value; }
/** * Clear all files and subfolders from $path * * @param string $path * @param callable|null $on_item_deleted * @param bool $is_subpath */ public static function clearDir($path, $on_item_deleted = null, $is_subpath = false) { if (is_link($path)) { // Don't follow links } elseif (is_file($path)) { if (unlink($path)) { if ($on_item_deleted) { call_user_func($on_item_deleted, $path); } } } elseif (is_dir($path)) { foreach (glob(rtrim($path, '/') . '/*') as $index => $subdir_path) { Shade::clearDir($subdir_path, $on_item_deleted, true); } if ($is_subpath && rmdir($path)) { if ($on_item_deleted) { call_user_func($on_item_deleted, $path); } } } }