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 @@ +
+ 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; -?> -
-[^>]*?\s+)?href="#(?P[^"]+)"/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( - 'nofollow ? 'rel="nofollow" ' : '', - $url->getAbsoluteUrl() - ); - } - return $match[0]; - }, - $chapterHtml -); ?> -
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 @@ -
-

documentation

-
-
- getHelper('Url'); - $view = $this; - ?> - 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

    +
    +

    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; -?> -
    -[^>]*?\s+)?href="#(?P[^"]+)"/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( - 'nofollow ? 'rel="nofollow" ' : '', - $url->getAbsoluteUrl() - ); - } - return $match[0]; - }, - $chapterHtml -); ?> -
    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

    +

    translate('Module documentations'); ?>