Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc/lib: Add DocTocHtmlRenderer class to render a toc to HTML
refs #4820
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |