diff --git a/modules/doc/application/controllers/IcingawebController.php b/modules/doc/application/controllers/IcingawebController.php
index 092de4025..813439169 100644
--- a/modules/doc/application/controllers/IcingawebController.php
+++ b/modules/doc/application/controllers/IcingawebController.php
@@ -9,11 +9,11 @@ use Icinga\Module\Doc\DocController;
class Doc_IcingawebController extends DocController
{
/**
- * View toc of Icinga Web 2's documentation
+ * View the toc of Icinga Web 2's documentation
*/
public function tocAction()
{
- $this->populateToc(Icinga::app()->getApplicationDir('/../doc'), 'Icinga Web 2');
+ $this->renderToc(Icinga::app()->getApplicationDir('/../doc'), 'Icinga Web 2', 'doc/icingaweb/chapter');
}
/**
@@ -25,8 +25,19 @@ class Doc_IcingawebController extends DocController
{
$chapterName = $this->getParam('chapterName');
if ($chapterName === null) {
- throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
+ throw new Zend_Controller_Action_Exception(
+ $this->translate('Missing parameter \'chapterName\''),
+ 404
+ );
}
- $this->populateChapter($chapterName, Icinga::app()->getApplicationDir('/../doc'));
+ $this->renderChapter(Icinga::app()->getApplicationDir('/../doc'), $chapterName, 'doc/icingaweb/chapter');
+ }
+
+ /**
+ * View Icinga Web 2's documentation as PDF
+ */
+ public function pdfAction()
+ {
+ $this->renderPdf(Icinga::app()->getApplicationDir('/../doc'), 'Icinga Web 2', 'doc/icingaweb/chapter');
}
}
diff --git a/modules/doc/application/controllers/IndexController.php b/modules/doc/application/controllers/IndexController.php
index 63b5e8cdf..c83cfabab 100644
--- a/modules/doc/application/controllers/IndexController.php
+++ b/modules/doc/application/controllers/IndexController.php
@@ -6,7 +6,5 @@ use Icinga\Module\Doc\DocController;
class Doc_IndexController extends DocController
{
- public function indexAction()
- {
- }
+ public function indexAction() {}
}
diff --git a/modules/doc/application/controllers/ModuleController.php b/modules/doc/application/controllers/ModuleController.php
index 2ce1b1e73..b04a56400 100644
--- a/modules/doc/application/controllers/ModuleController.php
+++ b/modules/doc/application/controllers/ModuleController.php
@@ -30,24 +30,36 @@ class Doc_ModuleController extends DocController
*
* @param $moduleName
*
- * @throws Zend_Controller_Action_Exception
+ * @throws Zend_Controller_Action_Exception If the required parameter 'moduleName' is empty or either if the
+ * given module is neither installed nor enabled
*/
protected function assertModuleEnabled($moduleName)
{
- if ($moduleName === null) {
- throw new Zend_Controller_Action_Exception('Missing parameter "moduleName"', 404);
+ if (empty($moduleName)) {
+ throw new Zend_Controller_Action_Exception(
+ $this->translate('Missing parameter \'moduleName\''),
+ 404
+ );
}
$moduleManager = Icinga::app()->getModuleManager();
if (! $moduleManager->hasInstalled($moduleName)) {
- throw new Zend_Controller_Action_Exception('Module ' . $moduleName . ' is not installed', 404);
+ throw new Zend_Controller_Action_Exception(
+ $this->translate('Module') . ' \'' . $moduleName . '\' ' . $this->translate('is not installed'),
+ 404
+ );
}
if (! $moduleManager->hasEnabled($moduleName)) {
- throw new Zend_Controller_Action_Exception('Module ' . $moduleName. ' is not enabled', 404);
+ throw new Zend_Controller_Action_Exception(
+ $this->translate('Module') . ' \'' . $moduleName . '\' ' . $this->translate('is not enabled'),
+ 404
+ );
}
}
/**
- * View toc of a module's documentation
+ * View the toc of a module's documentation
+ *
+ * @see assertModuleEnabled()
*/
public function tocAction()
{
@@ -55,7 +67,12 @@ class Doc_ModuleController extends DocController
$this->assertModuleEnabled($moduleName);
$moduleManager = Icinga::app()->getModuleManager();
try {
- $this->populateToc($moduleManager->getModuleDir($moduleName, '/doc'), $moduleName);
+ $this->renderToc(
+ $moduleManager->getModuleDir($moduleName, '/doc'),
+ $moduleName,
+ 'doc/module/chapter',
+ array('moduleName' => $moduleName)
+ );
} catch (DocException $e) {
throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
}
@@ -65,22 +82,50 @@ class Doc_ModuleController extends DocController
/**
* View a chapter of a module's documentation
*
- * @throws Zend_Controller_Action_Exception
+ * @throws Zend_Controller_Action_Exception If the required parameter 'chapterName' is missing or if an error in
+ * the documentation module's library occurs
+ * @see assertModuleEnabled()
*/
public function chapterAction()
{
$moduleName = $this->getParam('moduleName');
$this->assertModuleEnabled($moduleName);
- $chapterName = $this->getParam('chapterName');
- if ($chapterName === null) {
- throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
+ $chapterTitle = $this->getParam('chapterName');
+ if ($chapterTitle === null) {
+ throw new Zend_Controller_Action_Exception(
+ $this->translate('Missing parameter \'chapterName\''),
+ 404
+ );
}
$moduleManager = Icinga::app()->getModuleManager();
try {
- $this->populateChapter($chapterName, $moduleManager->getModuleDir($moduleName, '/doc'));
+ $this->renderChapter(
+ $moduleManager->getModuleDir($moduleName, '/doc'),
+ $chapterTitle,
+ 'doc/module/chapter',
+ array('moduleName' => $moduleName)
+ );
} catch (DocException $e) {
throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
}
$this->view->moduleName = $moduleName;
}
+
+ /**
+ * View a module's documentation as PDF
+ *
+ * @see assertModuleEnabled()
+ */
+ public function pdfAction()
+ {
+ $moduleName = $this->getParam('moduleName');
+ $this->assertModuleEnabled($moduleName);
+ $moduleManager = Icinga::app()->getModuleManager();
+ $this->renderPdf(
+ $moduleManager->getModuleDir($moduleName, '/doc'),
+ $moduleName,
+ 'doc/module/chapter',
+ array('moduleName' => $moduleName)
+ );
+ }
}
diff --git a/modules/doc/application/views/scripts/chapter.phtml b/modules/doc/application/views/scripts/chapter.phtml
new file mode 100644
index 000000000..7657d69fb
--- /dev/null
+++ b/modules/doc/application/views/scripts/chapter.phtml
@@ -0,0 +1,3 @@
+
+ = $sectionRenderer->render($this, $this->getHelper('Url')); ?>
+
diff --git a/modules/doc/application/views/scripts/icingaweb/chapter.phtml b/modules/doc/application/views/scripts/icingaweb/chapter.phtml
deleted file mode 100644
index 2ab744ebd..000000000
--- a/modules/doc/application/views/scripts/icingaweb/chapter.phtml
+++ /dev/null
@@ -1,40 +0,0 @@
-getHelper('Url');
-$view = $this;
-?>
-
diff --git a/modules/doc/application/views/scripts/icingaweb/toc.phtml b/modules/doc/application/views/scripts/icingaweb/toc.phtml
deleted file mode 100644
index bf91ffc77..000000000
--- a/modules/doc/application/views/scripts/icingaweb/toc.phtml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
= $docName ?> documentation
-
-
- getHelper('Url');
- $view = $this;
- ?>
- = $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(
- '
%s',
- $section->nofollow ? 'rel="nofollow" ' : '',
- $url->getAbsoluteUrl(),
- $section->title
- );
- }); ?>
-
diff --git a/modules/doc/application/views/scripts/index/index.phtml b/modules/doc/application/views/scripts/index/index.phtml
index 3cebdca69..e4218bee2 100644
--- a/modules/doc/application/views/scripts/index/index.phtml
+++ b/modules/doc/application/views/scripts/index/index.phtml
@@ -1,5 +1,6 @@
-Available documentations
+
+= $this->translate('Available documentations'); ?>
diff --git a/modules/doc/application/views/scripts/module/chapter.phtml b/modules/doc/application/views/scripts/module/chapter.phtml
deleted file mode 100644
index 3a809209f..000000000
--- a/modules/doc/application/views/scripts/module/chapter.phtml
+++ /dev/null
@@ -1,40 +0,0 @@
-getHelper('Url');
-$view = $this;
-?>
-
diff --git a/modules/doc/application/views/scripts/module/index.phtml b/modules/doc/application/views/scripts/module/index.phtml
index 0755748c7..cc184016f 100644
--- a/modules/doc/application/views/scripts/module/index.phtml
+++ b/modules/doc/application/views/scripts/module/index.phtml
@@ -1,4 +1,4 @@
-Module documentations
+= $this->translate('Module documentations'); ?>
-
diff --git a/modules/doc/application/views/scripts/module/toc.phtml b/modules/doc/application/views/scripts/module/toc.phtml
deleted file mode 100644
index ec33c507c..000000000
--- a/modules/doc/application/views/scripts/module/toc.phtml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
= $docName ?> documentation
-
-
- getHelper('Url');
- $view = $this;
- ?>
- = $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(
- '
- %s
',
- $section->nofollow ? 'rel="nofollow" ' : '',
- $url->getAbsoluteUrl(),
- $section->title
- );
- }); ?>
-
diff --git a/modules/doc/application/views/scripts/pdf.phtml b/modules/doc/application/views/scripts/pdf.phtml
new file mode 100644
index 000000000..72d77f3c0
--- /dev/null
+++ b/modules/doc/application/views/scripts/pdf.phtml
@@ -0,0 +1,7 @@
+= $docName ?> = $this->translate('Documentation'); ?>
+
+ = $tocRenderer->render($this, $this->getHelper('Url')); ?>
+
+
+ = $sectionRenderer->render($this, $this->getHelper('Url')); ?>
+
diff --git a/modules/doc/application/views/scripts/toc.phtml b/modules/doc/application/views/scripts/toc.phtml
new file mode 100644
index 000000000..8ffe2820d
--- /dev/null
+++ b/modules/doc/application/views/scripts/toc.phtml
@@ -0,0 +1,6 @@
+
+
= $docName ?> = $this->translate('Documentation'); ?>
+
+
+ = $tocRenderer->render($this, $this->getHelper('Url')); ?>
+
diff --git a/modules/doc/library/Doc/DocController.php b/modules/doc/library/Doc/DocController.php
index 88fd7476e..de2a7bac9 100644
--- a/modules/doc/library/Doc/DocController.php
+++ b/modules/doc/library/Doc/DocController.php
@@ -4,35 +4,67 @@
namespace Icinga\Module\Doc;
-use Icinga\Data\Tree\NodeRenderer;
use Icinga\Web\Controller\ModuleActionController;
class DocController extends ModuleActionController
{
/**
- * Populate a chapter
+ * Render a chapter
*
- * @param string $chapterName Name of the chapter
- * @param string $path Path to the documentation
+ * @param string $path Path to the documentation
+ * @param string $chapterTitle Title of the chapter
+ * @param string $url
+ * @param array $urlParams
*/
- protected function populateChapter($chapterName, $path)
+ protected function renderChapter($path, $chapterTitle, $url, array $urlParams = array())
{
$parser = new DocParser($path);
- $this->view->chapterHtml = $parser->getChapter($chapterName);
- $this->view->toc = $parser->getToc();
+ $this->view->sectionRenderer = new SectionRenderer(
+ $parser->getDocTree(),
+ SectionRenderer::decodeUrlParam($chapterTitle),
+ $url,
+ $urlParams
+ );
+ $this->_helper->viewRenderer('chapter', null, true);
}
/**
- * Populate toc
+ * Render a toc
*
- * @param string $path Path to the documentation
- * @param string $name Name of the documentation
+ * @param string $path Path to the documentation
+ * @param string $name Name of the documentation
+ * @param string $url
+ * @param array $urlParams
*/
- protected function populateToc($path, $name)
+ protected function renderToc($path, $name, $url, array $urlParams = array())
{
$parser = new DocParser($path);
- $toc = $parser->getToc();
- $this->view->tocRenderer = new NodeRenderer($toc);
+ $this->view->tocRenderer = new TocRenderer($parser->getDocTree(), $url, $urlParams);
$this->view->docName = $name;
+ $this->_helper->viewRenderer('toc', null, true);
+ }
+
+ /**
+ * Render a pdf
+ *
+ * @param string $path Path to the documentation
+ * @param string $name Name of the documentation
+ * @param string $url
+ * @param array $urlParams
+ */
+ protected function renderPdf($path, $name, $url, array $urlParams = array())
+ {
+ $parser = new DocParser($path);
+ $docTree = $parser->getDocTree();
+ $this->view->tocRenderer = new TocRenderer($docTree, $url, $urlParams);
+ $this->view->sectionRenderer = new SectionRenderer(
+ $docTree,
+ null,
+ $url,
+ $urlParams
+ );
+ $this->view->docName = $name;
+ $this->_helper->viewRenderer('pdf', null, true);
+ $this->_request->setParam('format', 'pdf');
}
}