mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 06:14:25 +02:00
parent
52de56fb65
commit
5965638e23
@ -3,88 +3,81 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Doc;
|
namespace Icinga\Module\Doc;
|
||||||
|
|
||||||
use RecursiveIteratorIterator;
|
|
||||||
use Zend_View_Helper_Url;
|
|
||||||
use Icinga\Web\View;
|
use Icinga\Web\View;
|
||||||
|
use Icinga\Data\Tree\TreeNodeIterator;
|
||||||
|
use RecursiveIteratorIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TOC renderer
|
* TOC renderer
|
||||||
|
*
|
||||||
|
* @method TreeNodeIterator getInnerIterator() {
|
||||||
|
* {@inheritdoc}
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
class TocRenderer extends Renderer
|
class TocRenderer extends Renderer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The URL to replace links with
|
* Content to render
|
||||||
*
|
*
|
||||||
* @var string
|
* @type array
|
||||||
*/
|
|
||||||
protected $url;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional URL parameters
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $urlParams;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Content
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
*/
|
||||||
protected $content = array();
|
protected $content = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new toc renderer
|
* Create a new toc renderer
|
||||||
*
|
*
|
||||||
* @param DocTree $docTree The documentation tree
|
* @param TreeNodeIterator $iterator
|
||||||
* @param string $url The URL to replace links with
|
|
||||||
* @param array $urlParams Additional URL parameters
|
|
||||||
*/
|
*/
|
||||||
public function __construct(DocTree $docTree, $url, array $urlParams)
|
public function __construct(TreeNodeIterator $iterator)
|
||||||
{
|
{
|
||||||
parent::__construct($docTree, RecursiveIteratorIterator::SELF_FIRST);
|
parent::__construct($iterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
$this->url = $url;
|
|
||||||
$this->urlParams = array_map(array($this, 'encodeUrlParam'), $urlParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function beginIteration()
|
public function beginIteration()
|
||||||
{
|
{
|
||||||
$this->content[] = '<nav><ul>';
|
$this->content[] = '<nav><ul>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function endIteration()
|
public function endIteration()
|
||||||
{
|
{
|
||||||
$this->content[] = '</ul></nav>';
|
$this->content[] = '</ul></nav>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function beginChildren()
|
public function beginChildren()
|
||||||
{
|
{
|
||||||
$this->content[] = '<ul>';
|
$this->content[] = '<ul>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function endChildren()
|
public function endChildren()
|
||||||
{
|
{
|
||||||
$this->content[] = '</ul></li>';
|
$this->content[] = '</ul>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the toc
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param View $view
|
|
||||||
* @param Zend_View_Helper_Url $zendUrlHelper
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function render(View $view, Zend_View_Helper_Url $zendUrlHelper)
|
public function render()
|
||||||
{
|
{
|
||||||
foreach ($this as $node) {
|
$view = $this->getView();
|
||||||
$section = $node->getValue();
|
$zendUrlHelper = $view->getHelper('Url');
|
||||||
/* @var $section \Icinga\Module\Doc\Section */
|
foreach ($this as $section) {
|
||||||
$path = $zendUrlHelper->url(
|
$path = $zendUrlHelper->url(
|
||||||
array_merge(
|
array_merge(
|
||||||
$this->urlParams,
|
$this->urlParams,
|
||||||
array(
|
array(
|
||||||
'chapterId' => $this->encodeUrlParam($section->getChapterId())
|
'chapter' => $this->encodeUrlParam($section->getChapter()->getId())
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
$this->url,
|
$this->url,
|
||||||
@ -92,14 +85,15 @@ class TocRenderer extends Renderer
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
$url = $view->url($path);
|
$url = $view->url($path);
|
||||||
|
/** @type \Icinga\Web\Url $url */
|
||||||
$url->setAnchor($this->encodeAnchor($section->getId()));
|
$url->setAnchor($this->encodeAnchor($section->getId()));
|
||||||
$this->content[] = sprintf(
|
$this->content[] = sprintf(
|
||||||
'<li><a %shref="%s">%s</a>',
|
'<li><a data-base-target="_next" %shref="%s">%s</a>',
|
||||||
$section->isNoFollow() ? 'rel="nofollow" ' : '',
|
$section->getNoFollow() ? 'rel="nofollow" ' : '',
|
||||||
$url->getAbsoluteUrl(),
|
$url->getAbsoluteUrl(),
|
||||||
$view->escape($section->getTitle())
|
$view->escape($section->getTitle())
|
||||||
);
|
);
|
||||||
if (! $this->getInnerIterator()->current()->hasChildren()) {
|
if (! $section->hasChildren()) {
|
||||||
$this->content[] = '</li>';
|
$this->content[] = '</li>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user