Skip to content

Commit

Permalink
Removing basePath, cleaning up config and adding deprecated directive
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed May 3, 2019
1 parent bf55411 commit fe19252
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 150 deletions.
4 changes: 4 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ use SymfonyDocsBuilder\Application;
$input = new ArgvInput();
$version = $input->getParameterOption(['--symfony-version'], false === getenv('SYMFONY_VERSION') ? 'master' : getenv('SYMFONY_VERSION'));

if (!$version) {
throw new \Exception('Please pass a --symfony-version= flag or set a SYMFONY_VERSION environment variable to 4.0, master, etc.');
}

$application = new Application($version);
$application->run($input);
6 changes: 0 additions & 6 deletions conf.json

This file was deleted.

13 changes: 5 additions & 8 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public function __construct(string $symfonyVersion)
{
$this->application = new BaseApplication();

$configuration = $this->getSymfonyDocConfiguration($basePath = getcwd());
$configuration = [
'symfony_api_url' => "https://api.symfony.com/%s",
'php_doc_url' => "https://secure.php.net/manual/en",
'symfony_doc_url' => "https://symfony.com/doc/%s",
];
$this->buildContext = new BuildContext(
$basePath,
$symfonyVersion,
sprintf($configuration['symfony_api_url'], $symfonyVersion),
$configuration['php_doc_url'],
Expand All @@ -38,13 +41,7 @@ public function run(InputInterface $input): int
);
$this->application->getDefinition()->addOption($inputOption);
$this->application->add(new BuildDocsCommand($this->buildContext));
$this->application->add(new CheckUrlsCommand($this->buildContext));

return $this->application->run($input);
}

private function getSymfonyDocConfiguration(string $basePath): array
{
return json_decode(file_get_contents(sprintf('%s/conf.json', $basePath)), true);
}
}
13 changes: 5 additions & 8 deletions src/BuildContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class BuildContext
{
private $basePath;
private $symfonyVersion;
private $symfonyApiUrl;
private $phpDocUrl;
Expand All @@ -17,13 +16,11 @@ class BuildContext
private $disableCache = false;

public function __construct(
string $basePath,
string $symfonyVersion,
string $symfonyApiUrl,
string $phpDocUrl,
string $symfonyDocUrl
) {
$this->basePath = $basePath;
$this->symfonyVersion = $symfonyVersion;
$this->symfonyApiUrl = $symfonyApiUrl;
$this->phpDocUrl = $phpDocUrl;
Expand All @@ -39,11 +36,6 @@ public function initializeRuntimeConfig(string $sourceDir, string $outputDir, ?s
$this->runtimeInitialized = true;
}

public function getBasePath(): string
{
return $this->basePath;
}

public function getSymfonyVersion(): string
{
return $this->symfonyVersion;
Expand Down Expand Up @@ -92,6 +84,11 @@ public function getDisableCache(): bool
return $this->disableCache;
}

public function getCacheDir(): string
{
return $this->getSourceDir().'/.cache';
}

private function checkThatRuntimeConfigIsInitialized()
{
if (false === $this->runtimeInitialized) {
Expand Down
71 changes: 0 additions & 71 deletions src/Command/CheckUrlsCommand.php

This file was deleted.

27 changes: 27 additions & 0 deletions src/Directive/DeprecatedDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace SymfonyDocsBuilder\Directive;

use Doctrine\RST\Directives\SubDirective;
use Doctrine\RST\Nodes\Node;
use Doctrine\RST\Parser;

class DeprecatedDirective extends SubDirective
{
public function getName(): string
{
return 'deprecated';
}

public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node
{
$wrapperDiv = $parser->renderTemplate(
'directives/deprecated.html.twig',
[
'version' => $data,
]
);

return $parser->getNodeFactory()->createWrapperNode($document, $wrapperDiv, '</div></div>');
}
}
5 changes: 3 additions & 2 deletions src/KernelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ final class KernelFactory
public static function createKernel(BuildContext $buildContext, ?UrlChecker $urlChecker = null): Kernel
{
$configuration = new RSTParserConfiguration();
$configuration->setCustomTemplateDirs([sprintf('%s/src/Templates', $buildContext->getBasePath())]);
$configuration->setCacheDir(sprintf('%s/var/cache', $buildContext->getBasePath()));
$configuration->setCustomTemplateDirs([__DIR__.'/Templates']);
$configuration->setCacheDir(sprintf('%s/var/cache', $buildContext->getCacheDir()));
$configuration->abortOnError(false);

if ($buildContext->getDisableCache()) {
Expand Down Expand Up @@ -55,6 +55,7 @@ private static function getDirectives(): array
new SymfonyDirectives\CautionDirective(),
new SymfonyDirectives\CodeBlockDirective(),
new SymfonyDirectives\ConfigurationBlockDirective(),
new SymfonyDirectives\DeprecatedDirective(),
new SymfonyDirectives\IndexDirective(),
new SymfonyDirectives\RoleDirective(),
new SymfonyDirectives\NoteDirective(),
Expand Down
1 change: 1 addition & 0 deletions src/Templates/default/html/directives/deprecated.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="deprecated"><div><span class="versionmodified">Deprecated since version {{ version }}: </span>
11 changes: 5 additions & 6 deletions tests/Command/BuildDocsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BuildDocsCommandTest extends TestCase
public function testBuildDocsFoo()
{
$buildContext = $this->createBuildContext();
$outputDir = sprintf('%s/tests/_output', $buildContext->getBasePath());
$outputDir = __DIR__.'/../_output';

$filesystem = new Filesystem();
$filesystem->remove($outputDir);
Expand All @@ -24,7 +24,7 @@ public function testBuildDocsFoo()
$output = $this->executeCommand(
$buildContext,
[
'source-dir' => sprintf('%s/tests/fixtures/source/main', $buildContext->getBasePath()),
'source-dir' => __DIR__.'/../tests/fixtures/source/main',
'output-dir' => $outputDir,
]
);
Expand All @@ -36,7 +36,7 @@ public function testBuildDocsFoo()
$output = $this->executeCommand(
$buildContext,
[
'source-dir' => sprintf('%s/tests/fixtures/source/main', $buildContext->getBasePath()),
'source-dir' => __DIR__.'/../tests/fixtures/source/main',
'output-dir' => $outputDir,
]
);
Expand All @@ -46,7 +46,7 @@ public function testBuildDocsFoo()
public function testBuildDocsForPdf()
{
$buildContext = $this->createBuildContext();
$outputDir = sprintf('%s/tests/_output', $buildContext->getBasePath());
$outputDir = __DIR__.'/../_output';

$fs = new Filesystem();
if ($fs->exists($outputDir)) {
Expand All @@ -56,7 +56,7 @@ public function testBuildDocsForPdf()
$output = $this->executeCommand(
$buildContext,
[
'source-dir' => sprintf('%s/tests/fixtures/source/build-pdf', $buildContext->getBasePath()),
'source-dir' => __DIR__.'/../fixtures/source/build-pdf',
'output-dir' => $outputDir,
'--parse-sub-path' => 'book',
]
Expand Down Expand Up @@ -93,7 +93,6 @@ private function executeCommand(BuildContext $buildContext, array $input): strin
private function createBuildContext(): BuildContext
{
$buildContext = new BuildContext(
realpath(__DIR__.'/../..'),
'4.0',
'https://api.symfony.com/4.0',
'https://secure.php.net/manual/en',
Expand Down
49 changes: 0 additions & 49 deletions tests/Command/CheckUrlsCommandTest.php

This file was deleted.

0 comments on commit fe19252

Please sign in to comment.