Skip to content

Use doctrine/rst-parser 0.6 #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": ">=7.4",
"ext-json": "*",
"ext-curl": "*",
"doctrine/rst-parser": "^0.5",
"doctrine/rst-parser": "^0.6@dev",
"scrivo/highlight.php": "^9.12.0",
"symfony/filesystem": "^5.2 || ^6.0",
"symfony/finder": "^5.2 || ^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/BuildResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Builder $builder)
{
$this->builder = $builder;
$this->errors = [];
foreach ($builder->getErrorManager()->getErrors() as $error) {
foreach ($builder->getConfiguration()->getErrorManager()->getErrors() as $error) {
$this->errors[] = $error->asString();
}
}
Expand Down
92 changes: 92 additions & 0 deletions src/BuilderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Docs Builder package.
* (c) Ryan Weaver <ryan@symfonycasts.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SymfonyDocsBuilder;

use Doctrine\Common\EventManager;
use Doctrine\RST\Builder;
use Doctrine\RST\Configuration as RSTParserConfiguration;
use Doctrine\RST\Event\PostBuildRenderEvent;
use Doctrine\RST\Event\PreNodeRenderEvent;
use Doctrine\RST\Event\PreParseDocumentEvent;
use SymfonyDocsBuilder\Listener\AssetsCopyListener;
use Doctrine\RST\ErrorManager;
use SymfonyDocsBuilder\Listener\CopyImagesListener;
use SymfonyDocsBuilder\Listener\AdmonitionListener;
use SymfonyDocsBuilder\CI\UrlChecker;
use SymfonyDocsBuilder\Twig\AssetsExtension;
use SymfonyDocsBuilder\Twig\TocExtension;
use SymfonyDocsBuilder\Twig\UrlExtension;
use function Symfony\Component\String\u;

final class BuilderFactory
{
public static function createBuilder(BuildConfig $buildConfig, ?UrlChecker $urlChecker = null): Builder
{
$configuration = new RSTParserConfiguration();
// needed to avoid outputting parser errors on the console output or the webpage contents
$configuration->silentOnError(true);
$configuration->setCustomTemplateDirs([__DIR__.'/Templates']);
$configuration->setTheme($buildConfig->getTheme());
$configuration->setCacheDir(sprintf('%s/var/cache', $buildConfig->getCacheDir()));
$configuration->abortOnError(false);

if (!$buildConfig->isBuildCacheEnabled()) {
$configuration->setUseCachedMetas(false);
}

$configuration->addFormat(
new SymfonyHTMLFormat(
$buildConfig,
$configuration->getTemplateRenderer(),
$configuration->getFormat(),
$urlChecker
)
);

if ($parseSubPath = $buildConfig->getSubdirectoryToBuild()) {
$configuration->setBaseUrl($buildConfig->getSymfonyDocUrl());
$configuration->setBaseUrlEnabledCallable(
static function (string $path) use ($parseSubPath): bool {
return u($path)->containsAny($parseSubPath);
}
);
}

$eventManager = $configuration->getEventManager();
$eventManager->addEventListener(
PreParseDocumentEvent::PRE_PARSE_DOCUMENT,
new AdmonitionListener()
);

$eventManager->addEventListener(
PreNodeRenderEvent::PRE_NODE_RENDER,
new CopyImagesListener($buildConfig, $configuration->getErrorManager())
);

if (!$buildConfig->getSubdirectoryToBuild()) {
$eventManager->addEventListener(
[PostBuildRenderEvent::POST_BUILD_RENDER],
new AssetsCopyListener($buildConfig->getOutputDir())
);
}

$twig = $configuration->getTemplateEngine();
$twig->addExtension(new AssetsExtension());
$twig->addExtension(new TocExtension());
$twig->addExtension(new UrlExtension());

$builder = new Builder($configuration);
$builder->setScannerFinder($buildConfig->createFileFinder());

return $builder;
}
}
8 changes: 3 additions & 5 deletions src/Command/BuildDocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\RST\Builder;
use Doctrine\RST\Configuration;
use Doctrine\RST\Meta\Metas;
use SymfonyDocsBuilder\BuilderFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -27,7 +28,6 @@
use SymfonyDocsBuilder\ConfigFileParser;
use SymfonyDocsBuilder\Generator\HtmlForPdfGenerator;
use SymfonyDocsBuilder\Generator\JsonGenerator;
use SymfonyDocsBuilder\KernelFactory;
use SymfonyDocsBuilder\Listener\BuildProgressListener;

class BuildDocsCommand extends Command
Expand Down Expand Up @@ -140,9 +140,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)

protected function execute(InputInterface $input, OutputInterface $output): int
{
$builder = new Builder(
KernelFactory::createKernel($this->buildConfig, $this->urlChecker ?? null)
);
$builder = BuilderFactory::createBuilder($this->buildConfig, $this->urlChecker ?? null);

$configuration = $builder->getConfiguration();
$configuration->setOutputFormat($input->getOption('error-output-format'));
Expand All @@ -153,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->buildConfig->getOutputDir()
);

$buildErrors = $builder->getErrorManager()->getErrors();
$buildErrors = $configuration->getErrorManager()->getErrors();

$missingFiles = $this->missingFilesChecker->getMissingFiles();
foreach ($missingFiles as $missingFile) {
Expand Down
52 changes: 0 additions & 52 deletions src/Directive/AbstractAdmonitionDirective.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/Directive/AdmonitionDirective.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Directive/AttentionDirective.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Directive/BestPracticeDirective.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Directive/CautionDirective.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Directive/DangerDirective.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Directive/DeprecatedDirective.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Directive/ErrorDirective.php

This file was deleted.

Loading