Skip to content

Fixed the generation of the "prev" option in JSON generator #76

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

Merged
merged 8 commits into from
Mar 19, 2021
Merged
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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"SymfonyDocsBuilder\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"SymfonyDocsBuilder\\Tests\\": "tests"
}
},
"require": {
"ext-json": "*",
"ext-curl": "*",
Expand Down
11 changes: 6 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 34 additions & 2 deletions src/BuildResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SymfonyDocsBuilder;

use Doctrine\RST\Builder;
use Doctrine\RST\Meta\Metas;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Filesystem\Filesystem;
use SymfonyDocsBuilder\BuildConfig;
Expand All @@ -14,11 +15,14 @@

class BuildResult
{
private $builder;
private $errors;
private $jsonResults = [];

public function __construct(array $errors)
public function __construct(Builder $builder)
{
$this->errors = $errors;
$this->builder = $builder;
$this->errors = $builder->getErrorManager()->getErrors();
}

public function appendError(string $errorMessage): void
Expand All @@ -40,4 +44,32 @@ public function getErrors(): array
{
return $this->errors;
}

public function getMetadata(): Metas
{
return $this->builder->getMetas();
}

/**
* Returns the "master document": the first file whose toctree is parsed.
*
* Unless customized, this is "index" (i.e. file index.rst).
*/
public function getMasterDocumentFilename(): string
{
return $this->builder->getIndexName();
}

/**
* Returns the JSON array data generated for each file, keyed by the source filename.
*/
public function getJsonResults(): array
{
return $this->jsonResults;
}

public function setJsonResults(array $jsonResults): void
{
$this->jsonResults = $jsonResults;
}
}
6 changes: 3 additions & 3 deletions src/DocBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function build(BuildConfig $config): BuildResult
$builder = new Builder(KernelFactory::createKernel($config));
$builder->build($config->getContentDir(), $config->getOutputDir());

$buildResult = new BuildResult($builder->getErrorManager()->getErrors());
$buildResult = new BuildResult($builder);

$missingFilesChecker = new MissingFilesChecker($config);
$missingFiles = $missingFilesChecker->getMissingFiles();
Expand All @@ -38,13 +38,13 @@ public function build(BuildConfig $config): BuildResult
$filesystem->dumpFile($config->getOutputDir().'/build_errors.txt', implode("\n", $buildResult->getErrors()));
}

$metas = $builder->getMetas();
$metas = $buildResult->getMetadata();
if ($config->getSubdirectoryToBuild()) {
$htmlForPdfGenerator = new HtmlForPdfGenerator($metas, $config);
$htmlForPdfGenerator->generateHtmlForPdf();
} else {
$jsonGenerator = new JsonGenerator($metas, $config);
$jsonGenerator->generateJson();
$buildResult->setJsonResults($jsonGenerator->generateJson($builder->getIndexName()));
}

return $buildResult;
Expand Down
Loading