Modules/Doc: Add doc display per module

refs #4820
This commit is contained in:
Eric Lippmann 2014-02-03 15:39:53 +01:00
parent 75577cec51
commit 88e13c378d
8 changed files with 73 additions and 29 deletions

View File

@ -29,7 +29,7 @@ A component name consists of two parts: the namespace and the name of the compon
is named exactly like its JavaScript file, while the namespace is the name of the Icinga2-Web module that contains
the component. Each Icinga2-Web module can contain its own components in the folder *public/js*.
<module>/<component>
<module>/<component>
NOTE: The namespace used for modules defined in the Icinga2-Web core application is "app". In opposition to
@ -45,10 +45,10 @@ The full name for the component *modules/monitoring/public/js/someComponent.js*
"monitoring/someComponent"
The full component name for the component *public/js/icinga/components/datetime.js* in the Icinga2-Web
core application would:
The full component name for the component *public/js/icinga/components/datetime.js* in the Icinga2-Web core application
would:
"app/datetime"
"app/datetime"
## Creating a component

View File

@ -4,20 +4,16 @@
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Icinga;
use Icinga\Module\Doc\Parser as DocParser;
use Icinga\Web\Controller\ActionController;
use Icinga\Module\Doc\Controller as DocController;
class Doc_IndexController extends ActionController
class Doc_IndexController extends DocController
{
/**
* Display the application's documentation
*/
public function indexAction()
{
$parser = new DocParser();
list($html, $toc) = $parser->parseDirectory(Icinga::app()->getApplicationDir('/../doc'));
$this->view->html = $html;
$this->view->toc = $toc;
$this->populateViewFromDocDirectory(Icinga::app()->getApplicationDir('/../doc'));
}
}
// @codingStandardsIgnoreEnd

View File

@ -4,22 +4,26 @@
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Icinga;
use Icinga\Web\Controller\ActionController;
use Icinga\Module\Doc\Controller as DocController;
class Doc_ModuleController extends ActionController
class Doc_ModuleController extends DocController
{
/**
* Display module documentations index
*/
public function indexAction()
{
$this->view->enabledModules = Icinga::app()->getModuleManager()->listEnabledModules();
}
/**
* Display a module's documentation
*/
public function moduleAction()
public function viewAction()
{
$this->populateViewFromDocDirectory(
Icinga::app()->getModuleManager()->getModuleDir($this->getParam('name'), '/doc')
);
}
/**
@ -39,6 +43,7 @@ class Doc_ModuleController extends ActionController
// TODO(el): Throw a not found exception once the code has been moved to the moduleAction (see TODO above)
return parent::__call($methodName, $args);
}
$this->_helper->redirector->gotoSimpleAndExit('view', null, null, array('name' => $moduleName));
}
}
// @codingStandardsIgnoreEnd

View File

@ -1,14 +1,5 @@
<div class="row">
<div class="col-sm-12 col-xs-12 col-md-2 col-lg-2">
<ul class="nav nav-pills nav-stacked" role="navigation">
<?php foreach ($toc as $i): ?>
<li class="toc-h<?= $i['level'] ?>">
<a href="#<?= $i['fragment'] ?>"><?= $this->escape($i['heading']); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="col-sm-12 col-xs-12 col-md-10 col-lg-10">
<?= $html ?>
</div>
</div>
<h1>Icinga 2 Documentation</h1>
<?= $this->partial('module/view.phtml', 'doc', array(
'toc' => $toc,
'html' => $html
)); ?>

View File

@ -0,0 +1,6 @@
<h1>Module documentations</h1>
<ul>
<?php foreach ($enabledModules as $module): ?>
<li><a href="<?= $this->href('doc/module/view', array('name' => $module)); ?>"><?= $module ?></a></li>
<?php endforeach ?>
</ul>

View File

@ -0,0 +1,18 @@
<?php if ($html === null): ?>
<p>Module is not documented.</p>
<?php else: ?>
<div class="row">
<div class="col-sm-12 col-xs-12 col-md-2 col-lg-2">
<ul class="nav nav-pills nav-stacked" role="navigation">
<?php foreach ($toc as $i): ?>
<li class="toc-h<?= $i['level'] ?>">
<a href="#<?= $i['fragment'] ?>"><?= $this->escape($i['heading']); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="col-sm-12 col-xs-12 col-md-10 col-lg-10">
<?= $html ?>
</div>
</div>
<?php endif ?>

View File

@ -0,0 +1,28 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Doc;
use Icinga\Module\Doc\DocParser;
use Icinga\Web\Controller\ActionController;
class Controller extends ActionController
{
/**
* Set HTML and toc
*
* @param string $dir
*/
protected function populateViewFromDocDirectory($dir)
{
if (!@is_dir($dir)) {
$this->view->html = null;
} else {
$parser = new DocParser();
list($html, $toc) = $parser->parseDirectory($dir);
$this->view->html = $html;
$this->view->toc = $toc;
}
}
}

View File

@ -14,7 +14,7 @@ use \Parsedown;
/**
* Parser for documentation written in Markdown
*/
class Parser
class DocParser
{
/**
* Retrieve table of contents and HTML converted from all Markdown files in the given directory sorted by filename