Render a tree out of the object representation.

Ticket T6
This commit is contained in:
Tim Schumacher 2013-11-26 21:33:45 +01:00
parent 5bc2dfdf71
commit 0453a6a662

View file

@ -38,7 +38,7 @@ class syntax_plugin_navigation extends DokuWiki_Syntax_Plugin {
} }
function connectTo ($mode) { function connectTo ($mode) {
$this->Lexer->addSpecialPattern('{{indexmenu_n>(\d+)}}',$mode,'plugin_navigation'); $this->Lexer->addSpecialPattern('{{indexmenu>.+?}}',$mode,'plugin_navigation');
$this->Lexer->addSpecialPattern ('\[Navigation\]', $mode, 'plugin_navigation'); $this->Lexer->addSpecialPattern ('\[Navigation\]', $mode, 'plugin_navigation');
} }
@ -70,15 +70,16 @@ class syntax_plugin_navigation extends DokuWiki_Syntax_Plugin {
} }
}); });
$content = '<ul>'; $root = $iter->getRoot();
$content = '';
$iter->all(function(DokuWikiNode $node) use (&$content){ if ($root instanceof DokuWikiNameSpace) {
if ($node->getName() != 'root') { $nodes = $root->getNodes();
$content .= '<li>' . $node->getFullID() . ':' . $node->getMetaData('sortorder') . '</li>'; if ($nodes->count() > 0) {
} $content .= '<ul>';
}); $content .= $this->RenderNodes($root);
$content .= '</ul>'; $content .= '</ul>';
}
}
// $data is what the function handle return'ed. // $data is what the function handle return'ed.
if ($mode == 'xhtml') { if ($mode == 'xhtml') {
@ -87,4 +88,17 @@ class syntax_plugin_navigation extends DokuWiki_Syntax_Plugin {
} }
return false; return false;
} }
private function RenderNodes(DokuWikiNameSpace $node) {
$output = '';
foreach ($node->getNodes() as $node) {
/** @var DokuWikiNode $node */
if ($node instanceof DokuWikiPage) {
$output .= '<li><a href="' . wl($node->getFullID()) . '">' . $node->getName() . '</a></li>';
} else {
$output .= '<li>' . $node->getName() . '<ul>' . $this->RenderNodes($node) . '</ul></li>';
}
}
return $output;
}
} }