doc/lib: Add DocTocHtmlRenderer class to render a toc to HTML

refs #4820
This commit is contained in:
Eric Lippmann 2014-05-28 17:15:43 +02:00
parent d2936d0338
commit f0b6a3557e
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}
namespace Icinga\Module\Doc;
use RecursiveIteratorIterator;
class DocTocHtmlRenderer extends RecursiveIteratorIterator
{
protected $html = array();
public function __construct(DocToc $toc)
{
parent::__construct($toc, RecursiveIteratorIterator::SELF_FIRST);
}
public function beginIteration()
{
$this->html[] = '<ul>';
}
public function endIteration()
{
$this->html[] = '</ul>';
}
public function beginChildren()
{
$this->html[] = '<ul>';
}
public function endChildren()
{
$this->html[] = '</ul>';
}
public function render($callback)
{
foreach ($this as $node) {
$this->html[] = $callback($node->getValue());
}
return implode("\n", $this->html);
}
}