mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-21 12:54:26 +02:00
parent
d446e0db2e
commit
16d5d65a05
@ -27,6 +27,6 @@ class Doc_IcingawebController extends DocController
|
|||||||
if ($chapterName === null) {
|
if ($chapterName === null) {
|
||||||
throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
|
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()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ class Doc_ModuleController extends DocController
|
|||||||
throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
|
throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
|
||||||
}
|
}
|
||||||
$moduleManager = Icinga::app()->getModuleManager();
|
$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
|
||||||
|
); ?>
|
@ -6,10 +6,18 @@
|
|||||||
$urlHelper = $this->getHelper('Url');
|
$urlHelper = $this->getHelper('Url');
|
||||||
$view = $this;
|
$view = $this;
|
||||||
?>
|
?>
|
||||||
<?= $tocRenderer->render(function ($section) use ($urlHelper, $view) {
|
<?= $tocRenderer->render(function ($node) use ($urlHelper, $view) {
|
||||||
// Chapter name is not yet defined
|
$section = $node->getValue();
|
||||||
$path = $urlHelper->url(array('chapterName' => 'tbd'), 'doc/icingaweb/chapter', false, false);
|
$path = $urlHelper->url(array('chapterName' => $section->chapterName), 'doc/icingaweb/chapter', false, false);
|
||||||
$url = $view->url($path)->setAnchor($section->id);
|
$url = $view->url($path);
|
||||||
return sprintf('<li><a href="%s">%s</a></li>', $url->getAbsoluteUrl(), $section->title);
|
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>
|
</div>
|
||||||
|
38
modules/doc/application/views/scripts/module/chapter.phtml
Normal file
38
modules/doc/application/views/scripts/module/chapter.phtml
Normal file
@ -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
|
||||||
|
); ?>
|
@ -6,12 +6,20 @@
|
|||||||
$urlHelper = $this->getHelper('Url');
|
$urlHelper = $this->getHelper('Url');
|
||||||
$view = $this;
|
$view = $this;
|
||||||
?>
|
?>
|
||||||
<?= $tocRenderer->render(function ($section) use ($urlHelper, $view, $moduleName) {
|
<?= $tocRenderer->render(function ($node) use ($urlHelper, $view, $moduleName) {
|
||||||
// Chapter name is not yet defined
|
$section = $node->getValue();
|
||||||
$path = $urlHelper->url(
|
$path = $urlHelper->url(
|
||||||
array('moduleName' => $moduleName, 'chapterName' => 'tbd'), 'doc/module/chapter', false, false
|
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
|
||||||
);
|
);
|
||||||
$url = $view->url($path)->setAnchor($section->id);
|
|
||||||
return sprintf('<li><a href="%s">%s</a></li>', $url->getAbsoluteUrl(), $section->title);
|
|
||||||
}); ?>
|
}); ?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<?= $chapterHtml ?>
|
|
@ -4,22 +4,22 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Doc;
|
namespace Icinga\Module\Doc;
|
||||||
|
|
||||||
|
use Icinga\Data\Tree\NodeRenderer;
|
||||||
use Icinga\Web\Controller\ActionController;
|
use Icinga\Web\Controller\ActionController;
|
||||||
|
|
||||||
class DocController extends ActionController
|
class DocController extends ActionController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Render a chapter
|
* Populate a chapter
|
||||||
*
|
*
|
||||||
* @param string $chapterName Name of the chapter
|
* @param string $chapterName Name of the chapter
|
||||||
* @param string $path Path to the documentation
|
* @param string $path Path to the documentation
|
||||||
*/
|
*/
|
||||||
protected function renderChapter($chapterName, $path)
|
protected function populateChapter($chapterName, $path)
|
||||||
{
|
{
|
||||||
$parser = new DocParser($path);
|
$parser = new DocParser($path);
|
||||||
list($docHtml, $docToc) = $parser->getDocAndToc();
|
$this->view->chapterHtml = $parser->getChapter($chapterName);
|
||||||
$this->view->chapterHtml = $docHtml;
|
$this->view->toc = $parser->getToc();
|
||||||
$this->_helper->viewRenderer('partials/chapter', null, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,8 +31,8 @@ class DocController extends ActionController
|
|||||||
protected function populateToc($path, $name)
|
protected function populateToc($path, $name)
|
||||||
{
|
{
|
||||||
$parser = new DocParser($path);
|
$parser = new DocParser($path);
|
||||||
list($docHtml, $tocRenderer) = $parser->getDocAndToc();
|
$toc = $parser->getToc();
|
||||||
$this->view->tocRenderer = $tocRenderer;
|
$this->view->tocRenderer = new NodeRenderer($toc);
|
||||||
$this->view->docName = $name;
|
$this->view->docName = $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user