parent
5c52e447f5
commit
127e4f444f
|
@ -30,7 +30,12 @@ class Doc_IcingawebController extends DocController
|
||||||
404
|
404
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->renderChapter(Icinga::app()->getApplicationDir('/../doc'), $chapterId, 'doc/icingaweb/chapter');
|
$this->renderChapter(
|
||||||
|
Icinga::app()->getApplicationDir('/../doc'),
|
||||||
|
$chapterId,
|
||||||
|
'doc/icingaweb/toc',
|
||||||
|
'doc/icingaweb/chapter'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -102,6 +102,7 @@ class Doc_ModuleController extends DocController
|
||||||
$this->renderChapter(
|
$this->renderChapter(
|
||||||
$moduleManager->getModuleDir($moduleName, '/doc'),
|
$moduleManager->getModuleDir($moduleName, '/doc'),
|
||||||
$chapterId,
|
$chapterId,
|
||||||
|
$this->_helper->url->url(array('moduleName' => $moduleName), 'doc/module/toc'),
|
||||||
'doc/module/chapter',
|
'doc/module/chapter',
|
||||||
array('moduleName' => $moduleName)
|
array('moduleName' => $moduleName)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<h1><?= $this->translate(sprintf('%s Documentation', ucfirst($docName))); ?></h1>
|
<h1><?= $this->translate(sprintf('%s Documentation', ucfirst($docName))); ?></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="content toc" data-base-target="_next">
|
<div class="content toc">
|
||||||
<?= $tocRenderer->render($this, $this->getHelper('Url')); ?>
|
<?= $tocRenderer->render($this, $this->getHelper('Url')); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,15 +13,17 @@ class DocController extends ModuleActionController
|
||||||
*
|
*
|
||||||
* @param string $path Path to the documentation
|
* @param string $path Path to the documentation
|
||||||
* @param string $chapterId ID of the chapter
|
* @param string $chapterId ID of the chapter
|
||||||
|
* @param string $tocUrl
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $urlParams
|
* @param array $urlParams
|
||||||
*/
|
*/
|
||||||
protected function renderChapter($path, $chapterId, $url, array $urlParams = array())
|
protected function renderChapter($path, $chapterId, $tocUrl, $url, array $urlParams = array())
|
||||||
{
|
{
|
||||||
$parser = new DocParser($path);
|
$parser = new DocParser($path);
|
||||||
$this->view->sectionRenderer = new SectionRenderer(
|
$this->view->sectionRenderer = new SectionRenderer(
|
||||||
$parser->getDocTree(),
|
$parser->getDocTree(),
|
||||||
SectionRenderer::decodeUrlParam($chapterId),
|
SectionRenderer::decodeUrlParam($chapterId),
|
||||||
|
$tocUrl,
|
||||||
$url,
|
$url,
|
||||||
$urlParams
|
$urlParams
|
||||||
);
|
);
|
||||||
|
@ -60,6 +62,7 @@ class DocController extends ModuleActionController
|
||||||
$this->view->sectionRenderer = new SectionRenderer(
|
$this->view->sectionRenderer = new SectionRenderer(
|
||||||
$docTree,
|
$docTree,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
$url,
|
$url,
|
||||||
$urlParams
|
$urlParams
|
||||||
);
|
);
|
||||||
|
|
|
@ -87,6 +87,8 @@ class SectionRenderer extends Renderer
|
||||||
*/
|
*/
|
||||||
protected $docTree;
|
protected $docTree;
|
||||||
|
|
||||||
|
protected $tocUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL to replace links with
|
* The URL to replace links with
|
||||||
*
|
*
|
||||||
|
@ -120,12 +122,13 @@ class SectionRenderer extends Renderer
|
||||||
*
|
*
|
||||||
* @param DocTree $docTree The documentation tree
|
* @param DocTree $docTree The documentation tree
|
||||||
* @param string|null $chapterId If not null, the chapter ID to filter for
|
* @param string|null $chapterId If not null, the chapter ID to filter for
|
||||||
|
* @param string $tocUrl
|
||||||
* @param string $url The URL to replace links with
|
* @param string $url The URL to replace links with
|
||||||
* @param array $urlParams Additional URL parameters
|
* @param array $urlParams Additional URL parameters
|
||||||
*
|
*
|
||||||
* @throws ChapterNotFoundException If the chapter to filter for was not found
|
* @throws ChapterNotFoundException If the chapter to filter for was not found
|
||||||
*/
|
*/
|
||||||
public function __construct(DocTree $docTree, $chapterId, $url, array $urlParams)
|
public function __construct(DocTree $docTree, $chapterId, $tocUrl, $url, array $urlParams)
|
||||||
{
|
{
|
||||||
if ($chapterId !== null) {
|
if ($chapterId !== null) {
|
||||||
$filter = new SectionFilterIterator($docTree, $chapterId);
|
$filter = new SectionFilterIterator($docTree, $chapterId);
|
||||||
|
@ -142,6 +145,7 @@ class SectionRenderer extends Renderer
|
||||||
parent::__construct($docTree, RecursiveIteratorIterator::SELF_FIRST);
|
parent::__construct($docTree, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
}
|
}
|
||||||
$this->docTree = $docTree;
|
$this->docTree = $docTree;
|
||||||
|
$this->tocUrl = $tocUrl;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->urlParams = array_map(array($this, 'encodeUrlParam'), $urlParams);
|
$this->urlParams = array_map(array($this, 'encodeUrlParam'), $urlParams);
|
||||||
$this->parsedown = Parsedown::instance();
|
$this->parsedown = Parsedown::instance();
|
||||||
|
@ -182,9 +186,11 @@ class SectionRenderer extends Renderer
|
||||||
*
|
*
|
||||||
* @param View $view
|
* @param View $view
|
||||||
* @param Zend_View_Helper_Url $zendUrlHelper
|
* @param Zend_View_Helper_Url $zendUrlHelper
|
||||||
|
* @param bool $renderNavigation
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function render(View $view, Zend_View_Helper_Url $zendUrlHelper)
|
public function render(View $view, Zend_View_Helper_Url $zendUrlHelper, $renderNavigation = true)
|
||||||
{
|
{
|
||||||
$callback = new Callback($this->docTree, $view, $zendUrlHelper, $this->url, $this->urlParams);
|
$callback = new Callback($this->docTree, $view, $zendUrlHelper, $this->url, $this->urlParams);
|
||||||
$content = array();
|
$content = array();
|
||||||
|
@ -192,7 +198,7 @@ class SectionRenderer extends Renderer
|
||||||
$section = $node->getValue();
|
$section = $node->getValue();
|
||||||
/* @var $section \Icinga\Module\Doc\Section */
|
/* @var $section \Icinga\Module\Doc\Section */
|
||||||
$content[] = sprintf(
|
$content[] = sprintf(
|
||||||
'<a name="%1$s"></a> <h%2$d>%3$s</h%2$d>',
|
'<a name="%1$s"></a><h%2$d>%3$s</h%2$d>',
|
||||||
Renderer::encodeAnchor($section->getId()),
|
Renderer::encodeAnchor($section->getId()),
|
||||||
$section->getLevel(),
|
$section->getLevel(),
|
||||||
$view->escape($section->getTitle())
|
$view->escape($section->getTitle())
|
||||||
|
@ -213,6 +219,73 @@ class SectionRenderer extends Renderer
|
||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if ($renderNavigation) {
|
||||||
|
foreach ($this->docTree as $chapter) {
|
||||||
|
if ($chapter->getValue()->getId() === $section->getChapterId()) {
|
||||||
|
$content[] = '<ul class="navigation">';
|
||||||
|
$this->docTree->prev();
|
||||||
|
$prev = $this->docTree->current();
|
||||||
|
if ($prev !== null) {
|
||||||
|
$prev = $prev->getValue();
|
||||||
|
$path = $zendUrlHelper->url(
|
||||||
|
array_merge(
|
||||||
|
$this->urlParams,
|
||||||
|
array(
|
||||||
|
'chapterId' => $this->encodeUrlParam($prev->getChapterId())
|
||||||
|
)
|
||||||
|
),
|
||||||
|
$this->url,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
$url = $view->url($path);
|
||||||
|
$url->setAnchor($this->encodeAnchor($prev->getId()));
|
||||||
|
$content[] = sprintf(
|
||||||
|
'<li><a %shref="%s">%s</a></li>',
|
||||||
|
$prev->isNoFollow() ? 'rel="nofollow" ' : '',
|
||||||
|
$url->getAbsoluteUrl(),
|
||||||
|
$view->escape($prev->getTitle())
|
||||||
|
);
|
||||||
|
$this->docTree->next();
|
||||||
|
$this->docTree->next();
|
||||||
|
} else {
|
||||||
|
$this->docTree->rewind();
|
||||||
|
$this->docTree->next();
|
||||||
|
}
|
||||||
|
$url = $view->url($this->tocUrl);
|
||||||
|
$content[] = sprintf(
|
||||||
|
'<li><a href="%s">%s</a></li>',
|
||||||
|
$url->getAbsoluteUrl(),
|
||||||
|
mt('doc', 'Index')
|
||||||
|
);
|
||||||
|
$next = $this->docTree->current();
|
||||||
|
if ($next !== null) {
|
||||||
|
$next = $next->getValue();
|
||||||
|
$path = $zendUrlHelper->url(
|
||||||
|
array_merge(
|
||||||
|
$this->urlParams,
|
||||||
|
array(
|
||||||
|
'chapterId' => $this->encodeUrlParam($next->getChapterId())
|
||||||
|
)
|
||||||
|
),
|
||||||
|
$this->url,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
$url = $view->url($path);
|
||||||
|
$url->setAnchor($this->encodeAnchor($next->getId()));
|
||||||
|
$content[] = sprintf(
|
||||||
|
'<li><a %shref="%s">%s</a></li>',
|
||||||
|
$next->isNoFollow() ? 'rel="nofollow" ' : '',
|
||||||
|
$url->getAbsoluteUrl(),
|
||||||
|
$view->escape($next->getTitle())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$content[] = '</ul>';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return implode("\n", $content);
|
return implode("\n", $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use Zend_View_Helper_Url;
|
||||||
use Icinga\Web\View;
|
use Icinga\Web\View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* toc renderer
|
* TOC renderer
|
||||||
*/
|
*/
|
||||||
class TocRenderer extends Renderer
|
class TocRenderer extends Renderer
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,3 +31,22 @@ code {
|
||||||
pre > code {
|
pre > code {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.chapter > ul.navigation {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.4em;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #888;
|
||||||
|
|
||||||
|
li {
|
||||||
|
list-style: none;
|
||||||
|
display: inline;
|
||||||
|
margin: 0.2em;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue