Files
luxtools-plugin/syntax/directory.php
luxick 490a483df1
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
Add base class for syntax handlers
2026-01-06 09:02:39 +01:00

58 lines
1.5 KiB
PHP

<?php
use dokuwiki\plugin\luxtools\Output;
use dokuwiki\plugin\luxtools\Path;
require_once(__DIR__ . '/AbstractSyntax.php');
/**
* LuxTools Plugin: Directory syntax.
*
* Lists the direct children (folders and files) of a given path.
* Always renders as a table.
*/
class syntax_plugin_luxtools_directory extends syntax_plugin_luxtools_abstract
{
/** @inheritdoc */
protected function getSyntaxKeyword(): string
{
return 'directory';
}
/** @inheritdoc */
protected function processPath(string $path): array
{
// Directory path (no glob/pattern)
$path = Path::cleanPath($path, true);
return ['path' => $path];
}
/** @inheritdoc */
protected function doRender(string $format, \Doku_Renderer $renderer, array $pathData, array $params): bool
{
$pathInfo = $this->getPathInfoSafe($pathData['path'], $renderer);
if ($pathInfo === false) {
return true;
}
$crawler = $this->createCrawler($params);
$items = $crawler->listDirectory(
$pathInfo['root'],
$pathInfo['local'],
$params['titlefile']
);
if ($items == []) {
$this->renderError($renderer, 'error_nomatch');
return true;
}
// Always render as table style
$params['style'] = 'table';
$output = new Output($renderer, $pathInfo['root'], $pathInfo['web'], $items);
$output->renderAsFlatTable($params);
return true;
}
}