Skip to content

Commit

Permalink
Fix URL links being incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
Numynum committed Aug 30, 2024
1 parent b16fb48 commit 107eca9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bin/annotate
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $fileList = [];
if (is_file($inputDir) && (str_ends_with($inputDir, '.lua') || str_ends_with($inputDir, '.xml'))) {
$fileList[$inputDir] = pathinfo($inputDir, PATHINFO_EXTENSION);
} elseif (is_dir($inputDir)) {
$inputDir = rtrim($inputDir, '/');
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($inputDir));
$iterator->rewind();
/** @var $iterator RecursiveDirectoryIterator */
Expand All @@ -62,7 +63,7 @@ foreach ($fileList as $filePath => $extension) {
if ('xml' === $extension) {
$xmlFileParser->parse($filePath);
} elseif ('lua' === $extension) {
$luaFileParser->parse($filePath, $linkPrefix);
$luaFileParser->parse($filePath, $inputDir, $linkPrefix);
}
$progressBar->advance();
}
Expand Down
6 changes: 5 additions & 1 deletion src/LuaFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ class LuaFileParser
/** @var array<string, array<string, string> [filename => [function name => function data]] */
private array $functions = [];

public function parse(string $filename, ?string $linkPrefix): void
public function parse(string $filename, string $prefixToStrip, ?string $linkPrefix): void
{
$fileContents = file_get_contents($filename);
if (str_starts_with($filename, $prefixToStrip)) {
$linkFilename = substr($filename, strlen($prefixToStrip));
$linkPrefix = $linkPrefix ? str_replace('//', '/', $linkPrefix . '/' . $linkFilename) : null;
}

$mixins = $this->extractMixins($fileContents, $linkPrefix);
$functions = $this->extractFunctions($fileContents, $mixins, $linkPrefix);
Expand Down
2 changes: 1 addition & 1 deletion src/XmlFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function writeAnnotationsToFile(string $filename, string $outDir, string

if (str_starts_with($filename, $prefixToStrip)) {
$filename = substr($filename, strlen($prefixToStrip));
$linkPrefix = $linkPrefix ? ($linkPrefix . '/' . $filename) : null;
$linkPrefix = $linkPrefix ? str_replace('//', '/', $linkPrefix . '/' . $filename) : null;
}
$targetFile = $outDir . '/' . $filename . '.annotated.lua';
if (!is_dir(dirname($targetFile))) {
Expand Down

0 comments on commit 107eca9

Please sign in to comment.