From 5965638e2322764258d236e27a93dd11a23e045a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 10 Feb 2015 17:07:24 +0100 Subject: [PATCH] doc/lib: Open toc links in the next container refs #6630 --- modules/doc/library/Doc/TocRenderer.php | 74 ++++++++++++------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/modules/doc/library/Doc/TocRenderer.php b/modules/doc/library/Doc/TocRenderer.php index 69ab7ac02..cfa18fad0 100644 --- a/modules/doc/library/Doc/TocRenderer.php +++ b/modules/doc/library/Doc/TocRenderer.php @@ -3,88 +3,81 @@ namespace Icinga\Module\Doc; -use RecursiveIteratorIterator; -use Zend_View_Helper_Url; use Icinga\Web\View; +use Icinga\Data\Tree\TreeNodeIterator; +use RecursiveIteratorIterator; /** * TOC renderer + * + * @method TreeNodeIterator getInnerIterator() { + * {@inheritdoc} + * } */ class TocRenderer extends Renderer { /** - * The URL to replace links with + * Content to render * - * @var string - */ - protected $url; - - /** - * Additional URL parameters - * - * @var array - */ - protected $urlParams; - - /** - * Content - * - * @var array + * @type array */ protected $content = array(); /** * Create a new toc renderer * - * @param DocTree $docTree The documentation tree - * @param string $url The URL to replace links with - * @param array $urlParams Additional URL parameters + * @param TreeNodeIterator $iterator */ - public function __construct(DocTree $docTree, $url, array $urlParams) + public function __construct(TreeNodeIterator $iterator) { - parent::__construct($docTree, RecursiveIteratorIterator::SELF_FIRST); - $this->url = $url; - $this->urlParams = array_map(array($this, 'encodeUrlParam'), $urlParams); + parent::__construct($iterator, RecursiveIteratorIterator::SELF_FIRST); } + /** + * {@inheritdoc} + */ public function beginIteration() { $this->content[] = ''; } + /** + * {@inheritdoc} + */ public function beginChildren() { $this->content[] = ''; + $this->content[] = ''; } /** - * Render the toc - * - * @param View $view - * @param Zend_View_Helper_Url $zendUrlHelper - * - * @return string + * {@inheritdoc} */ - public function render(View $view, Zend_View_Helper_Url $zendUrlHelper) + public function render() { - foreach ($this as $node) { - $section = $node->getValue(); - /* @var $section \Icinga\Module\Doc\Section */ + $view = $this->getView(); + $zendUrlHelper = $view->getHelper('Url'); + foreach ($this as $section) { $path = $zendUrlHelper->url( array_merge( $this->urlParams, array( - 'chapterId' => $this->encodeUrlParam($section->getChapterId()) + 'chapter' => $this->encodeUrlParam($section->getChapter()->getId()) ) ), $this->url, @@ -92,14 +85,15 @@ class TocRenderer extends Renderer false ); $url = $view->url($path); + /** @type \Icinga\Web\Url $url */ $url->setAnchor($this->encodeAnchor($section->getId())); $this->content[] = sprintf( - '
  • %s', - $section->isNoFollow() ? 'rel="nofollow" ' : '', + '
  • %s', + $section->getNoFollow() ? 'rel="nofollow" ' : '', $url->getAbsoluteUrl(), $view->escape($section->getTitle()) ); - if (! $this->getInnerIterator()->current()->hasChildren()) { + if (! $section->hasChildren()) { $this->content[] = '
  • '; } }