Skip to content

Commit

Permalink
doc/lib: Add DocTocHtmlRenderer class to render a toc to HTML
Browse files Browse the repository at this point in the history
refs #4820
  • Loading branch information
lippserd committed May 28, 2014
1 parent d2936d0 commit f0b6a35
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions modules/doc/library/Doc/DocTocHtmlRenderer.php
@@ -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);
}
}

0 comments on commit f0b6a35

Please sign in to comment.