Skip to content

Commit bebf3af

Browse files
authored
Merge pull request #15 from weaverryan/build-system-updates
Various build system updates
2 parents 09e7d45 + b4f5b18 commit bebf3af

17 files changed

+84
-37
lines changed

_build/src/Command/ParseDoc.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\RST\Event\PreBuildRenderEvent;
99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Helper\ProgressBar;
11+
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Input\InputOption;
1314
use Symfony\Component\Console\Output\OutputInterface;
@@ -54,9 +55,8 @@ protected function configure()
5455
parent::configure();
5556

5657
$this
57-
->addOption('source-dir', null, InputOption::VALUE_REQUIRED, 'RST files Source directory', __DIR__.'/../../..')
58-
->addOption('html-output-dir', null, InputOption::VALUE_REQUIRED, 'HTML files output directory', __DIR__.'/../../html')
59-
->addOption('json-output-dir', null, InputOption::VALUE_REQUIRED, 'JSON files output directory', __DIR__.'/../../json')
58+
->addArgument('source-dir', null, InputArgument::REQUIRED, 'RST files Source directory')
59+
->addArgument('output-dir', null, InputArgument::OPTIONAL, 'HTML files output directory')
6060
->addOption('parse-only', null, InputOption::VALUE_OPTIONAL, 'Parse only given directory for PDF (directory relative from source-dir)', null);
6161
}
6262

@@ -65,17 +65,18 @@ protected function initialize(InputInterface $input, OutputInterface $output)
6565
$this->io = new SymfonyStyle($input, $output);
6666
$this->output = $output;
6767

68-
$this->sourceDir = rtrim($this->getRealAbsolutePath($input->getOption('source-dir')), '/');
68+
$this->sourceDir = rtrim($this->getRealAbsolutePath($input->getArgument('source-dir')), '/');
6969
if (!$this->filesystem->exists($this->sourceDir)) {
7070
throw new \InvalidArgumentException(sprintf('RST source directory "%s" does not exist', $this->sourceDir));
7171
}
7272

73-
$this->htmlOutputDir = rtrim($this->getRealAbsolutePath($input->getOption('html-output-dir')), '/');
73+
$outputDir = $input->getArgument('output-dir') ?? $this->sourceDir . '/html';
74+
$this->htmlOutputDir = rtrim($this->getRealAbsolutePath($outputDir), '/');
7475
if ($this->filesystem->exists($this->htmlOutputDir)) {
7576
$this->filesystem->remove($this->htmlOutputDir);
7677
}
7778

78-
$this->jsonOutputDir = $this->getRealAbsolutePath($input->getOption('json-output-dir'));
79+
$this->jsonOutputDir = $this->getRealAbsolutePath($outputDir.'/json');
7980
if ($this->filesystem->exists($this->jsonOutputDir)) {
8081
$this->filesystem->remove($this->jsonOutputDir);
8182
}
@@ -106,7 +107,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
106107

107108
protected function execute(InputInterface $input, OutputInterface $output)
108109
{
109-
$this->finder->in($input->getOption('source-dir'))
110+
$this->finder->in($input->getArgument('source-dir'))
110111
->exclude(['_build', '.github', '.platform', '_images'])
111112
->notName('*.rst.inc')
112113
->name('*.rst');

_build/src/Directive/AbstractAdmonitionDirective.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final public function processSub(Parser $parser, ?Node $document, string $variab
2727
[
2828
'name' => $this->name,
2929
'text' => $this->text,
30+
'class' => null,
3031
]
3132
);
3233

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace SymfonyDocs\Directive;
4+
5+
use Doctrine\RST\Directives\SubDirective;
6+
use Doctrine\RST\Nodes\Node;
7+
use Doctrine\RST\Parser;
8+
9+
class AdmonitionDirective extends SubDirective
10+
{
11+
public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node
12+
{
13+
$wrapperDiv = $parser->renderTemplate(
14+
'directives/admonition.html.twig',
15+
[
16+
// a bit strange, but on the old markup we literally
17+
// had a class of 'admonition-"
18+
'name' => '',
19+
'text' => $data,
20+
'class' => isset($options['class']) ? $options['class'] : null,
21+
]
22+
);
23+
24+
return $parser->getNodeFactory()->createWrapperNode($document, $wrapperDiv, '</div></div>');
25+
}
26+
27+
public function getName(): string
28+
{
29+
return 'admonition';
30+
}
31+
}

_build/src/KernelFactory.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
use Doctrine\RST\Configuration;
66
use Doctrine\RST\Kernel;
77
use SymfonyDocs\Directive as SymfonyDirectives;
8-
use SymfonyDocs\Reference as SymfonyRefernces;
8+
use SymfonyDocs\Reference as SymfonyReferences;
99

1010
/**
1111
* Class KernelFactory
1212
*/
1313
final class KernelFactory
1414
{
15-
public static function createKernel(?string $parseOnly): Kernel
15+
public static function createKernel(string $parseOnlyPath = null): Kernel
1616
{
1717
$configuration = new Configuration();
1818
$configuration->setCustomTemplateDirs([__DIR__.'/Templates']);
@@ -24,16 +24,16 @@ public static function createKernel(?string $parseOnly): Kernel
2424
)
2525
);
2626

27-
if ($parseOnly) {
27+
if ($parseOnlyPath) {
2828
$configuration->setBaseUrl(
2929
sprintf(
3030
SymfonyDocConfiguration::getSymfonyDocUrl(),
3131
SymfonyDocConfiguration::getVersion()
3232
)
3333
);
3434
$configuration->setBaseUrlEnabledCallable(
35-
static function (string $path) use ($parseOnly) : bool {
36-
return strpos($path, $parseOnly) !== 0;
35+
static function (string $path) use ($parseOnlyPath) : bool {
36+
return strpos($path, $parseOnlyPath) !== 0;
3737
}
3838
);
3939
}
@@ -48,6 +48,7 @@ static function (string $path) use ($parseOnly) : bool {
4848
private static function getDirectives(): array
4949
{
5050
return [
51+
new SymfonyDirectives\AdmonitionDirective(),
5152
new SymfonyDirectives\CautionDirective(),
5253
new SymfonyDirectives\ClassDirective(),
5354
new SymfonyDirectives\CodeBlockDirective(),
@@ -66,14 +67,14 @@ private static function getDirectives(): array
6667
private static function getReferences(): array
6768
{
6869
return [
69-
new SymfonyRefernces\DocReference(),
70-
new SymfonyRefernces\RefReference(),
71-
new SymfonyRefernces\ClassReference(),
72-
new SymfonyRefernces\MethodReference(),
73-
new SymfonyRefernces\NamespaceReference(),
74-
new SymfonyRefernces\PhpFunctionReference(),
75-
new SymfonyRefernces\PhpMethodReference(),
76-
new SymfonyRefernces\PhpClassReference(),
70+
new SymfonyReferences\DocReference(),
71+
new SymfonyReferences\RefReference(),
72+
new SymfonyReferences\ClassReference(),
73+
new SymfonyReferences\MethodReference(),
74+
new SymfonyReferences\NamespaceReference(),
75+
new SymfonyReferences\PhpFunctionReference(),
76+
new SymfonyReferences\PhpMethodReference(),
77+
new SymfonyReferences\PhpClassReference(),
7778
];
7879
}
7980
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<div class="admonition-{{ name }} admonition-wrapper">
2-
<div class="{{ name }}"></div>
1+
<div class="admonition-wrapper{{ class ? (' '~class) : '' }}">
32
<div class="admonition admonition-{{ name }}">
43
<p class="admonition-title">{{ text }}</p>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="admonition-wrapper"><div class="sidebar"></div><div class="admonition admonition-sidebar"><p class="sidebar-title">{{ title|raw }}</p>
1+
<div class="admonition-wrapper"><div class="admonition admonition-sidebar"><p class="sidebar-title">{{ title|raw }}</p>

_build/tests/IntegrationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public function parserUnitBlockProvider()
144144
'blockName' => 'directives/note',
145145
];
146146

147+
yield 'admonition' => [
148+
'blockName' => 'directives/admonition',
149+
];
150+
147151
yield 'note-code-block-nested' => [
148152
'blockName' => 'directives/note-code-block-nested',
149153
];
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<div class="admonition-wrapper screencast_class">
8+
<div class="admonition admonition-">
9+
<p class="admonition-title">Screencast</p>
10+
<p>Do you prefer video tutorials? Check out the the screencasts.</p>
11+
</div>
12+
</div>
13+
</body>
14+
</html>

_build/tests/fixtures/expected/blocks/directives/best-practice.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="admonition-best-practice admonition-wrapper">
8-
<div class="best-practice"></div>
7+
<div class="admonition-wrapper">
98
<div class="admonition admonition-best-practice">
109
<p class="admonition-title">Best Practice</p>
1110
<p>Use the bcrypt encoder for hashing your users' passwords.</p>

_build/tests/fixtures/expected/blocks/directives/caution.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="admonition-caution admonition-wrapper">
8-
<div class="caution"></div>
7+
<div class="admonition-wrapper">
98
<div class="admonition admonition-caution">
109
<p class="admonition-title">Caution</p>
1110
<p>Using too many sidebars or caution directives can be distracting!</p>

_build/tests/fixtures/expected/blocks/directives/note-code-block-nested.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="admonition-note admonition-wrapper">
8-
<div class="note"></div>
7+
<div class="admonition-wrapper">
98
<div class="admonition admonition-note">
109
<p class="admonition-title">Note</p>
1110
<p>test</p>

_build/tests/fixtures/expected/blocks/directives/note.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="admonition-note admonition-wrapper">
8-
<div class="note"></div>
7+
<div class="admonition-wrapper">
98
<div class="admonition admonition-note">
109
<p class="admonition-title">Note</p>
1110
<p>Sometimes we add notes. But not too often because they interrupt the flow.</p>

_build/tests/fixtures/expected/blocks/directives/seealso.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="admonition-seealso admonition-wrapper">
8-
<div class="seealso"></div>
7+
<div class="admonition-wrapper">
98
<div class="admonition admonition-seealso">
109
<p class="admonition-title">See also</p>
1110
<p>Also check out the homepage</p>

_build/tests/fixtures/expected/blocks/directives/sidebar-code-block-nested.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</head>
66
<body>
77
<div class="admonition-wrapper">
8-
<div class="sidebar"></div>
98
<div class="admonition admonition-sidebar">
109
<p class="sidebar-title">The sidebar's title</p>
1110
<p>some text before code block</p>

_build/tests/fixtures/expected/blocks/directives/sidebar.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</head>
66
<body>
77
<div class="admonition-wrapper">
8-
<div class="sidebar"></div>
98
<div class="admonition admonition-sidebar">
109
<p class="sidebar-title">The sidebar's title</p>
1110
<p>some text inside sidebar</p>

_build/tests/fixtures/expected/blocks/directives/tip.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="admonition-tip admonition-wrapper">
8-
<div class="tip"></div>
7+
<div class="admonition-wrapper">
98
<div class="admonition admonition-tip">
109
<p class="admonition-title">Tip</p>
1110
<p>This is a little tip about something! We an also talk about specific</p>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. admonition:: Screencast
2+
:class: screencast_class
3+
4+
Do you prefer video tutorials? Check out the the screencasts.

0 commit comments

Comments
 (0)