Modules/doc: Replace Michelf/Markdown with Parsedown

refs #4820
This commit is contained in:
Eric Lippmann 2014-01-24 16:41:37 +01:00
parent af33599e19
commit 75577cec51
8 changed files with 76 additions and 72 deletions

View File

@ -266,8 +266,6 @@ class ActionController extends Zend_Controller_Action
return call_user_func_array(array($this, $deprecatedMethod), $params); return call_user_func_array(array($this, $deprecatedMethod), $params);
} }
parent::__call($name, $params); return parent::__call($name, $params);
return null;
} }
} }

View File

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

View File

@ -0,0 +1,44 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Icinga;
use Icinga\Web\Controller\ActionController;
class Doc_ModuleController extends ActionController
{
/**
* Display module documentations index
*/
public function indexAction()
{
}
/**
* Display a module's documentation
*/
public function moduleAction()
{
}
/**
* Provide run-time dispatching of module documentation
*
* @param string $methodName
* @param array $args
*
* @return mixed
*/
public function __call($methodName, $args)
{
// TODO(el): Setup routing to retrieve module name as param and point route to moduleAction
$moduleManager = Icinga::app()->getModuleManager();
$moduleName = substr($methodName, 0, -6); // Strip 'Action' suffix
if (!$moduleManager->hasEnabled($moduleName)) {
// TODO(el): Throw a not found exception once the code has been moved to the moduleAction (see TODO above)
return parent::__call($methodName, $args);
}
}
}
// @codingStandardsIgnoreEnd

View File

@ -1,52 +0,0 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Icinga;
use Icinga\Module\Doc\Parser as DocParser;
use Icinga\Web\Controller\ActionController;
class Doc_ViewController extends ActionController
{
public function init()
{
$this->_helper->viewRenderer->setRender('view');
}
/**
* Populate view
*
* @param string $dir
*/
private function populateView($dir)
{
$parser = new DocParser();
list($html, $toc) = $parser->parseDirectory($dir);
$this->view->html = $html;
$this->view->toc = $toc;
}
public function indexAction()
{
$this->populateView(Icinga::app()->getApplicationDir('/../doc'));
}
/**
* Provide run-time dispatching of module documentation
*
* @param string $methodName
* @param array $args
*/
public function __call($methodName, $args)
{
$moduleManager = Icinga::app()->getModuleManager();
$moduleName = substr($methodName, 0, -6); // Strip 'Action' suffix
if ($moduleManager->hasEnabled($moduleName)) {
$this->populateView($moduleManager->getModuleDir($moduleName, '/doc'));
} else {
parent::__call($methodName, $args);
}
}
}
// @codingStandardsIgnoreEnd

View File

@ -0,0 +1,14 @@
<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>

View File

@ -1,10 +0,0 @@
<div class="doc-toc pull-left">
<ul class="nav nav-stacked">
<?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>
<?= $html ?>

View File

@ -6,6 +6,9 @@ namespace Icinga\Module\Doc;
use \RecursiveFilterIterator; use \RecursiveFilterIterator;
/**
* Iterator over Markdown files recursively
*/
class MarkdownFileIterator extends RecursiveFilterIterator class MarkdownFileIterator extends RecursiveFilterIterator
{ {
/** /**

View File

@ -4,21 +4,20 @@
namespace Icinga\Module\Doc; namespace Icinga\Module\Doc;
require_once 'vendor/Michelf/Markdown.php'; require_once 'vendor/Parsedown/Parsedown.php';
require_once 'vendor/Michelf/MarkdownExtra.php';
use \RecursiveIteratorIterator; use \RecursiveIteratorIterator;
use \RecursiveDirectoryIterator; use \RecursiveDirectoryIterator;
use \Exception; use \Exception;
use Michelf\MarkdownExtra; use \Parsedown;
/** /**
* Markdown parser * Parser for documentation written in Markdown
*/ */
class Parser class Parser
{ {
/** /**
* Retrieve table of contents and HTML converted from all markdown files in the given directory sorted by filename * Retrieve table of contents and HTML converted from all Markdown files in the given directory sorted by filename
* *
* @param $dir * @param $dir
* *
@ -87,7 +86,7 @@ class Parser
} }
$fileObject->flock(LOCK_UN); $fileObject->flock(LOCK_UN);
} }
$html = MarkdownExtra::defaultTransform(implode('', $cat)); $html = Parsedown::instance()->parse(implode('', $cat));
return array($html, $toc); return array($html, $toc);
} }
} }