parent
d446e0db2e
commit
16d5d65a05
|
@ -27,6 +27,6 @@ class Doc_IcingawebController extends DocController
|
|||
if ($chapterName === null) {
|
||||
throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
|
||||
}
|
||||
$this->renderChapter($chapterName, Icinga::app()->getApplicationDir('/../doc'));
|
||||
$this->populateChapter($chapterName, Icinga::app()->getApplicationDir('/../doc'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,5 @@ class Doc_IndexController extends DocController
|
|||
{
|
||||
public function indexAction()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ class Doc_ModuleController extends DocController
|
|||
throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
|
||||
}
|
||||
$moduleManager = Icinga::app()->getModuleManager();
|
||||
$this->renderChapter($chapterName, $moduleManager->getModuleDir($moduleName, '/doc'));
|
||||
$this->populateChapter($chapterName, $moduleManager->getModuleDir($moduleName, '/doc'));
|
||||
$this->view->moduleName = $moduleName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
$urlHelper = $this->getHelper('Url');
|
||||
$view = $this;
|
||||
?>
|
||||
<?= preg_replace_callback(
|
||||
'/<a\s+(?P<attribs>[^>]*?\s+)?href="#(?P<fragment>[^"]+)"/im',
|
||||
function($match) use ($toc, $urlHelper, $view) {
|
||||
if (($node = $toc->findNodeBy(function ($node) use ($match) {
|
||||
$section = $node->getValue();
|
||||
if (($section->id === null && $section->chapterName === $match['fragment'])
|
||||
|| $section->id === $match['fragment']
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}))) {
|
||||
$section = $node->getValue();
|
||||
$path = $urlHelper->url(
|
||||
array('chapterName' => $section->chapterName),
|
||||
'doc/icingaweb/chapter',
|
||||
false,
|
||||
false
|
||||
);
|
||||
$url = $view->url($path);
|
||||
if ($section->id) {
|
||||
$url->setAnchor($section->id);
|
||||
}
|
||||
return sprintf(
|
||||
'<a %s%shref="%s"',
|
||||
strlen($match['attribs']) ? trim($match['attribs']) . ' ' : '',
|
||||
$section->nofollow ? 'rel="nofollow" ' : '',
|
||||
$url->getAbsoluteUrl()
|
||||
);
|
||||
}
|
||||
return $match[0];
|
||||
},
|
||||
$chapterHtml
|
||||
); ?>
|
|
@ -1,15 +1,23 @@
|
|||
<div class="controls">
|
||||
<h1><?= $docName ?> documentation</h1>
|
||||
<h1><?= $docName ?> documentation</h1>
|
||||
</div>
|
||||
<div class="content" data-base-target="_next">
|
||||
<?php
|
||||
<?php
|
||||
$urlHelper = $this->getHelper('Url');
|
||||
$view = $this;
|
||||
?>
|
||||
<?= $tocRenderer->render(function ($section) use ($urlHelper, $view) {
|
||||
// Chapter name is not yet defined
|
||||
$path = $urlHelper->url(array('chapterName' => 'tbd'), 'doc/icingaweb/chapter', false, false);
|
||||
$url = $view->url($path)->setAnchor($section->id);
|
||||
return sprintf('<li><a href="%s">%s</a></li>', $url->getAbsoluteUrl(), $section->title);
|
||||
}); ?>
|
||||
?>
|
||||
<?= $tocRenderer->render(function ($node) use ($urlHelper, $view) {
|
||||
$section = $node->getValue();
|
||||
$path = $urlHelper->url(array('chapterName' => $section->chapterName), 'doc/icingaweb/chapter', false, false);
|
||||
$url = $view->url($path);
|
||||
if ($section->id) {
|
||||
$url->setAnchor($section->id);
|
||||
}
|
||||
return sprintf(
|
||||
'<li><a %shref="%s">%s</a></li>',
|
||||
$section->nofollow ? 'rel="nofollow" ' : '',
|
||||
$url->getAbsoluteUrl(),
|
||||
$section->title
|
||||
);
|
||||
}); ?>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<h1>Available documentations</h1>
|
||||
<ul>
|
||||
<li><a href="<?= $this->href('doc/icingaweb/toc'); ?>">Icinga Web 2</a></li>
|
||||
<li><a href="<?= $this->href('doc/module/'); ?>">Module documentations</a></li>
|
||||
<li><a href="<?= $this->href('doc/icingaweb/toc'); ?>">Icinga Web 2</a></li>
|
||||
<li><a href="<?= $this->href('doc/module/'); ?>">Module documentations</a></li>
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
$urlHelper = $this->getHelper('Url');
|
||||
$view = $this;
|
||||
?>
|
||||
<?= preg_replace_callback(
|
||||
'/<a\s+(?P<attribs>[^>]*?\s+)?href="#(?P<fragment>[^"]+)"/im',
|
||||
function($match) use ($toc, $moduleName, $urlHelper, $view) {
|
||||
if (($node = $toc->findNodeBy(function ($node) use ($match) {
|
||||
$section = $node->getValue();
|
||||
if (($section->id === null && $section->chapterName === $match['fragment'])
|
||||
|| $section->id === $match['fragment']
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}))) {
|
||||
$section = $node->getValue();
|
||||
$path = $urlHelper->url(
|
||||
array('moduleName' => $moduleName, 'chapterName' => $section->chapterName),
|
||||
'doc/module/chapter',
|
||||
false,
|
||||
false
|
||||
);
|
||||
$url = $view->url($path);
|
||||
if ($section->id) {
|
||||
$url->setAnchor($section->id);
|
||||
}
|
||||
return sprintf(
|
||||
'<a %s%shref="%s"',
|
||||
strlen($match['attribs']) ? trim($match['attribs']) . ' ' : '',
|
||||
$section->nofollow ? 'rel="nofollow" ' : '',
|
||||
$url->getAbsoluteUrl()
|
||||
);
|
||||
}
|
||||
return $match[0];
|
||||
},
|
||||
$chapterHtml
|
||||
); ?>
|
|
@ -1,10 +1,10 @@
|
|||
<h1>Module documentations</h1>
|
||||
<ul>
|
||||
<?php foreach ($enabledModules as $module): ?>
|
||||
<li>
|
||||
<a href="<?= $this->getHelper('Url')->url(array('moduleName' => $module), 'doc/module/toc', false, false); ?>">
|
||||
<?= $module ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php foreach ($enabledModules as $module): ?>
|
||||
<li>
|
||||
<a href="<?= $this->getHelper('Url')->url(array('moduleName' => $module), 'doc/module/toc', false, false); ?>">
|
||||
<?= $module ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
<div class="controls">
|
||||
<h1><?= $docName ?> documentation</h1>
|
||||
<h1><?= $docName ?> documentation</h1>
|
||||
</div>
|
||||
<div class="content" data-base-target="_next">
|
||||
<?php
|
||||
<?php
|
||||
$urlHelper = $this->getHelper('Url');
|
||||
$view = $this;
|
||||
?>
|
||||
<?= $tocRenderer->render(function ($section) use ($urlHelper, $view, $moduleName) {
|
||||
// Chapter name is not yet defined
|
||||
$path = $urlHelper->url(
|
||||
array('moduleName' => $moduleName, 'chapterName' => 'tbd'), 'doc/module/chapter', false, false
|
||||
);
|
||||
$url = $view->url($path)->setAnchor($section->id);
|
||||
return sprintf('<li><a href="%s">%s</a></li>', $url->getAbsoluteUrl(), $section->title);
|
||||
}); ?>
|
||||
?>
|
||||
<?= $tocRenderer->render(function ($node) use ($urlHelper, $view, $moduleName) {
|
||||
$section = $node->getValue();
|
||||
$path = $urlHelper->url(
|
||||
array('moduleName' => $moduleName, 'chapterName' => $section->chapterName), 'doc/module/chapter', false, false
|
||||
);
|
||||
$url = $view->url($path);
|
||||
if ($section->id) {
|
||||
$url->setAnchor($section->id);
|
||||
}
|
||||
return sprintf(
|
||||
'<li><a %shref="%s">%s</a></li>',
|
||||
$section->nofollow ? 'rel="nofollow" ' : '',
|
||||
$url->getAbsoluteUrl(),
|
||||
$section->title
|
||||
);
|
||||
}); ?>
|
||||
</div>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
<?= $chapterHtml ?>
|
|
@ -4,22 +4,22 @@
|
|||
|
||||
namespace Icinga\Module\Doc;
|
||||
|
||||
use Icinga\Data\Tree\NodeRenderer;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
|
||||
class DocController extends ActionController
|
||||
{
|
||||
/**
|
||||
* Render a chapter
|
||||
* Populate a chapter
|
||||
*
|
||||
* @param string $chapterName Name of the chapter
|
||||
* @param string $path Path to the documentation
|
||||
*/
|
||||
protected function renderChapter($chapterName, $path)
|
||||
protected function populateChapter($chapterName, $path)
|
||||
{
|
||||
$parser = new DocParser($path);
|
||||
list($docHtml, $docToc) = $parser->getDocAndToc();
|
||||
$this->view->chapterHtml = $docHtml;
|
||||
$this->_helper->viewRenderer('partials/chapter', null, true);
|
||||
$this->view->chapterHtml = $parser->getChapter($chapterName);
|
||||
$this->view->toc = $parser->getToc();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,8 +31,8 @@ class DocController extends ActionController
|
|||
protected function populateToc($path, $name)
|
||||
{
|
||||
$parser = new DocParser($path);
|
||||
list($docHtml, $tocRenderer) = $parser->getDocAndToc();
|
||||
$this->view->tocRenderer = $tocRenderer;
|
||||
$toc = $parser->getToc();
|
||||
$this->view->tocRenderer = new NodeRenderer($toc);
|
||||
$this->view->docName = $name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue