예제 #1
0
 /**
  * @param Project $project
  */
 public function __invoke(Project $project)
 {
     /** @var HtmlFile[] $htmlFiles */
     $htmlFiles = $project->findFilesByType('Couscous\\Module\\Template\\Model\\HtmlFile');
     foreach ($htmlFiles as $htmlFile) {
         $htmlFile->content = $this->render($htmlFile->getContent());
     }
 }
예제 #2
0
 public function __invoke(Project $project)
 {
     /** @var MarkdownFile[] $markdownFiles */
     $markdownFiles = $project->findFilesByType('Couscous\\Module\\Markdown\\Model\\MarkdownFile');
     foreach ($markdownFiles as $markdownFile) {
         $htmlFile = $this->renderFile($markdownFile);
         $project->replaceFile($markdownFile, $htmlFile);
     }
 }
예제 #3
0
 public function __invoke(Project $project)
 {
     /** @var MarkdownFile[] $markdownFiles */
     $markdownFiles = $project->findFilesByType('Couscous\\Module\\Markdown\\Model\\MarkdownFile');
     foreach ($markdownFiles as $file) {
         $pattern = self::MARKDOWN_LINK_REGEX;
         $callback = [$this, 'replaceFilename'];
         $subject = $file->content;
         $file->content = preg_replace_callback($pattern, $callback, $subject);
     }
 }
예제 #4
0
 public function __invoke(Project $project)
 {
     /** @var MarkdownFile[] $markdownFiles */
     $markdownFiles = $project->findFilesByType('Couscous\\Module\\Markdown\\Model\\MarkdownFile');
     foreach ($markdownFiles as $markdownFile) {
         $project->removeFile($markdownFile);
         $this->renameFileExtension($markdownFile);
         $this->renameReadme($markdownFile, $project);
         $this->renameFilename($markdownFile);
         $project->addFile($markdownFile);
     }
 }
예제 #5
0
 public function __invoke(Project $project)
 {
     /** @var MarkdownFile[] $markdownFiles */
     $markdownFiles = $project->findFilesByType('Couscous\\Module\\Markdown\\Model\\MarkdownFile');
     foreach ($markdownFiles as $file) {
         $document = $this->markdownParser->parse($file->getContent());
         $metadataValues = $document->getYAML();
         if (is_array($metadataValues)) {
             $file->getMetadata()->setMany($metadataValues);
         }
     }
 }
예제 #6
0
 public function __invoke(Project $project)
 {
     if (!$project->metadata['template.directory']) {
         return;
     }
     $twig = $this->createTwig($project->metadata['template.directory']);
     /** @var HtmlFile[] $htmlFiles */
     $htmlFiles = $project->findFilesByType('Couscous\\Module\\Template\\Model\\HtmlFile');
     foreach ($htmlFiles as $file) {
         $fileMetadata = $file->getMetadata();
         $layout = isset($fileMetadata['layout']) ? $fileMetadata['layout'] . '.twig' : self::DEFAULT_LAYOUT_NAME;
         $context = array_merge($project->metadata->toArray(), $fileMetadata->toArray(), ['content' => $file->content]);
         try {
             $file->content = $twig->render($layout, $context);
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('There was an error while rendering the file "%s" with the layout "%s": %s', $file->relativeFilename, $layout, $e->getMessage()), 0, $e);
         }
     }
 }
 public function __invoke(Project $project)
 {
     /** @var HtmlFile[] $htmlFiles */
     $htmlFiles = $project->findFilesByType('Couscous\\Module\\Template\\Model\\HtmlFile');
     $pageList = [];
     $pageTree = [];
     foreach ($htmlFiles as $file) {
         $pageList[] = $file->relativeFilename;
         $path = dirname($file->relativeFilename);
         $filename = basename($file->relativeFilename);
         if ($path === '.') {
             $path = [];
         } else {
             $path = explode(DIRECTORY_SEPARATOR, $path);
         }
         $this->setValue($pageTree, $path, $filename);
     }
     // Sort
     natsort($pageList);
     $this->sortRecursively($pageTree);
     $project->metadata['pageList'] = $pageList;
     $project->metadata['pageTree'] = $pageTree;
 }