|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Ublaboo\Anabelle\Markdown\Macros; |
|
6
|
|
|
|
|
7
|
|
|
use Ublaboo\Anabelle\Console\Utils\Logger; |
|
8
|
|
|
use Ublaboo\Anabelle\Generator\Exception\DocuGeneratorException; |
|
9
|
|
|
use Ublaboo\Anabelle\Http\AuthCredentials; |
|
10
|
|
|
use Ublaboo\Anabelle\Markdown\DocuScope; |
|
11
|
|
|
use Ublaboo\Anabelle\Markdown\Parser; |
|
12
|
|
|
|
|
13
|
|
|
final class MacroSection implements IMacro |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var Parser |
|
18
|
|
|
*/ |
|
19
|
|
|
private $parser; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var AuthCredentials |
|
23
|
|
|
*/ |
|
24
|
|
|
private $authCredentials; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
Logger $logger, |
|
29
|
|
|
AuthCredentials $authCredentials, |
|
30
|
|
|
DocuScope $docuScope |
|
31
|
|
|
) { |
|
32
|
|
|
$this->authCredentials = $authCredentials; |
|
33
|
|
|
|
|
34
|
|
|
$this->parser = new Parser(false, $authCredentials, $logger, $docuScope); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @throws DocuGeneratorException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function runMacro( |
|
42
|
|
|
string $inputDirectory, |
|
43
|
|
|
string $outputDirectory, |
|
44
|
|
|
string & $content // Intentionally & |
|
45
|
|
|
): void |
|
46
|
|
|
{ |
|
47
|
|
|
$fileType = $this->authCredentials->getUser() ? 'php' : 'html'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Find "@@" sections and parse their child .md file |
|
51
|
|
|
* == normal section with json-rpc methods |
|
52
|
|
|
* |
|
53
|
|
|
* Find "@" sections and parse their child .md file |
|
54
|
|
|
* == home section, aditional description etc |
|
55
|
|
|
*/ |
|
56
|
|
|
$content = preg_replace_callback( |
|
57
|
|
|
'/^@@? (.+[^:]):(.+\.md)/m', |
|
58
|
|
|
function(array $input) use ($inputDirectory, $outputDirectory, $fileType): string { |
|
59
|
|
|
$inputFile = $inputDirectory . '/' . dirname($input[2]) . '/' . basename($input[2]); |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Output file is of type .(php|html) |
|
63
|
|
|
*/ |
|
64
|
|
|
$outputFile = preg_replace('/md$/', $fileType, $inputFile); |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Substitute input dir for output dir |
|
68
|
|
|
*/ |
|
69
|
|
|
$outputFile = str_replace($inputDirectory, $outputDirectory, $outputFile); |
|
70
|
|
|
|
|
71
|
|
|
$this->parser->parseFile($inputFile, $outputFile); |
|
72
|
|
|
|
|
73
|
|
|
return preg_replace('/md$/', $fileType, $input[0]); |
|
74
|
|
|
}, |
|
75
|
|
|
$content |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|