Skip to content

Commit e320c48

Browse files
committed
Some renames
1 parent c00edbe commit e320c48

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/BuildConfig.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class BuildConfig
3030
private $subdirectoryToBuild;
3131
private $excludedPaths;
3232
private $fileFinder;
33-
private $isContentAString;
34-
private $disableJsonFileGeneration;
33+
// needed to know if we're building an entire directory of RST contents or just a single RST string
34+
private $contentIsString;
35+
// these are the *.fjson files generated by Sphinx and maintained for compatibility reasons
36+
private $generateJsonFiles;
3537

3638
public function __construct()
3739
{
@@ -40,8 +42,8 @@ public function __construct()
4042
$this->symfonyVersion = '4.4';
4143
$this->excludedPaths = [];
4244
$this->imagesPublicPrefix = '';
43-
$this->isContentAString = false;
44-
$this->disableJsonFileGeneration = false;
45+
$this->contentIsString = false;
46+
$this->generateJsonFiles = true;
4547
}
4648

4749
public function createFileFinder(): Finder
@@ -134,12 +136,12 @@ public function getImagesPublicPrefix(): string
134136

135137
public function generateJsonFiles(): bool
136138
{
137-
return !$this->disableJsonFileGeneration;
139+
return $this->generateJsonFiles;
138140
}
139141

140142
public function isContentAString(): bool
141143
{
142-
return $this->isContentAString;
144+
return $this->contentIsString;
143145
}
144146

145147
public function setSymfonyVersion(string $version): self
@@ -234,17 +236,21 @@ public function setExcludedPaths(array $excludedPaths)
234236
$this->excludedPaths = $excludedPaths;
235237
}
236238

237-
// needed to differentiate between building a dir of contents or just a string of contents
238-
public function setIsContentAString(bool $isString): self
239+
/*
240+
* Call this method when you're building a string of RST contents (e.g. the
241+
* contents of a single file) instead of the common case of building an
242+
* entire directory of RST files.
243+
*/
244+
public function setContentIsString(): self
239245
{
240-
$this->isContentAString = true;
246+
$this->contentIsString = true;
241247

242248
return $this;
243249
}
244250

245251
public function disableJsonFileGeneration(): self
246252
{
247-
$this->disableJsonFileGeneration = true;
253+
$this->generateJsonFiles = false;
248254

249255
return $this;
250256
}

src/DocBuilder.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,22 @@ public function build(BuildConfig $config): BuildResult
3939
$filesystem->dumpFile($config->getOutputDir().'/build_errors.txt', implode("\n", $buildResult->getErrors()));
4040
}
4141

42-
$metas = $buildResult->getMetadata();
43-
if ($config->getSubdirectoryToBuild()) {
44-
$htmlForPdfGenerator = new HtmlForPdfGenerator($metas, $config);
45-
$htmlForPdfGenerator->generateHtmlForPdf();
46-
} elseif ($config->generateJsonFiles()) {
47-
$jsonGenerator = new JsonGenerator($metas, $config);
48-
$buildResult->setJsonResults($jsonGenerator->generateJson($builder->getIndexName()));
49-
} elseif ($config->isContentAString()) {
42+
if ($config->isContentAString()) {
5043
$htmlFilePath = $config->getOutputDir().'/index.html';
5144
if (is_file($htmlFilePath)) {
5245
// generated HTML contents are a full HTML page, so we need to
5346
// extract the contents of the <body> tag
5447
$crawler = new Crawler(file_get_contents($htmlFilePath));
5548
$buildResult->setStringResult(trim($crawler->filter('body')->html()));
5649
}
50+
} elseif ($config->getSubdirectoryToBuild()) {
51+
$metas = $buildResult->getMetadata();
52+
$htmlForPdfGenerator = new HtmlForPdfGenerator($metas, $config);
53+
$htmlForPdfGenerator->generateHtmlForPdf();
54+
} elseif ($config->generateJsonFiles()) {
55+
$metas = $buildResult->getMetadata();
56+
$jsonGenerator = new JsonGenerator($metas, $config);
57+
$buildResult->setJsonResults($jsonGenerator->generateJson($builder->getIndexName()));
5758
}
5859

5960
return $buildResult;
@@ -62,7 +63,7 @@ public function build(BuildConfig $config): BuildResult
6263
public function buildString(string $contents): BuildResult
6364
{
6465
$filesystem = new Filesystem();
65-
$tmpDir = sys_get_temp_dir().'/rst_'.random_int(1, 100000000);
66+
$tmpDir = sys_get_temp_dir().'/doc_builder_build_string_'.random_int(1, 100000000);
6667
if ($filesystem->exists($tmpDir)) {
6768
$filesystem->remove($tmpDir);
6869
}
@@ -71,13 +72,16 @@ public function buildString(string $contents): BuildResult
7172
$filesystem->dumpFile($tmpDir.'/index.rst', $contents);
7273

7374
$buildConfig = (new BuildConfig())
74-
->setIsContentAString(true)
75+
->setContentIsString()
7576
->setContentDir($tmpDir)
7677
->setOutputDir($tmpDir.'/output')
7778
->disableBuildCache()
7879
->disableJsonFileGeneration()
7980
;
8081

81-
return $this->build($buildConfig);
82+
$buildResult = $this->build($buildConfig);
83+
$filesystem->remove($tmpDir);
84+
85+
return $buildResult;
8286
}
8387
}

0 commit comments

Comments
 (0)