public function __invoke(Project $project) { foreach ($project->getFiles() as $file) { $fileMetadata = $file->getMetadata(); $fileMetadata['currentFile'] = $file->relativeFilename; } }
/** * @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()); } }
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); } }
/** * Add images to the given project. * * @param Project $project */ public function __invoke(Project $project) { $files = $project->sourceFiles(); $files->name('*.gif')->name('*.png')->name('*.jpg'); $project->watchlist->watchFiles($files); foreach ($files as $file) { /** @var SplFileInfo $file */ $project->addFile(new LazyFile($file->getPathname(), $file->getRelativePathname())); } }
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); } }
public function __invoke(Project $project) { $files = $project->sourceFiles(); $files->name('*.md'); foreach ($files as $file) { /** @var SplFileInfo $file */ $content = file_get_contents($file->getPathname()); $project->addFile(new MarkdownFile($file->getRelativePathname(), $content)); } $project->watchlist->watchFiles($files); }
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); } }
public function __invoke(Project $project) { foreach ($project->getFiles() as $file) { $targetFilename = $project->targetDirectory . '/' . $file->relativeFilename; if ($this->filesystem->exists($targetFilename)) { $this->logger->info("Skipping '{file}' because a file with the same name already exists", ['file' => $file->relativeFilename]); continue; } $this->logger->debug('Writing {file}', ['file' => $targetFilename]); $this->filesystem->dumpFile($targetFilename, $file->getContent()); } }
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); } } }
public function __invoke(Project $project) { if (!$project->metadata['template.directory']) { return; } $files = new Finder(); $files->files()->in($project->metadata['template.directory'])->ignoreDotFiles(false)->notName('*.twig')->notName('*.md')->notName('couscous.yml'); $project->watchlist->watchFiles($files); foreach ($files as $file) { /** @var SplFileInfo $file */ $project->addFile(new LazyFile($file->getPathname(), $file->getRelativePathname())); } }
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; }
public function __invoke(Project $project) { if (isset($project->metadata['cname'])) { $project->addFile(new CnameFile('CNAME', $project->metadata['cname'])); } }