Add a more advanced processor system

This commit is contained in:
Stéphane Goetz 2015-07-17 18:34:00 +02:00 committed by Stéphane Goetz
parent 8dd3c1d6f8
commit e7afd9aa28
7 changed files with 95 additions and 11 deletions

View File

@ -20,6 +20,9 @@
"symfony/finder": "~2.7"
},
"autoload": {
"psr-4": {"Todaymade\\Daux\\": "libs/"}
"psr-4": {
"Todaymade\\Daux\\Extension\\": "daux/",
"Todaymade\\Daux\\": "libs/"
}
}
}

BIN
daux.phar

Binary file not shown.

View File

@ -66,13 +66,7 @@ class Compiler
}
// Composer autoload
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/autoload.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_classmap.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_files.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_psr4.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_real.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/ClassLoader.php'));
$this->addComposer($phar);
$this->addBinary($phar);
// Stubs
@ -99,6 +93,20 @@ class Compiler
$phar->addFromString($path, $content);
}
private function addComposer($phar)
{
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/autoload.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_classmap.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_files.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_real.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/ClassLoader.php'));
$content = file_get_contents(__DIR__ . '/../vendor/composer/autoload_psr4.php');
$content = str_replace('$baseDir . \'/daux\'', 'PHAR_DIR . \'/daux\'', $content);
$phar->addFromString('vendor/composer/autoload_psr4.php', $content);
}
private function addBinary($phar)
{
$content = file_get_contents(__DIR__ . '/../generate.php');

View File

@ -1,5 +1,6 @@
<?php namespace Todaymade\Daux;
use Symfony\Component\Console\Output\NullOutput;
use Todaymade\Daux\Tree\Builder;
class Daux
@ -12,6 +13,11 @@ class Daux
public $internal_base;
private $docs_path;
/**
* @var Processor
*/
protected $processor;
/**
* @var Tree\Entry
*/
@ -152,4 +158,24 @@ class Daux
return $this->options;
}
/**
* @return Processor
*/
public function getProcessor()
{
if (!$this->processor) {
$this->processor = new Processor($this, new NullOutput(), 0);
}
return $this->processor;
}
/**
* @param Processor $processor
*/
public function setProcessor(Processor $processor)
{
$this->processor = $processor;
}
}

View File

@ -18,6 +18,9 @@ class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter
$this->extendEnvironment($environment);
//TODO :: finish
//$daux->getProcessor()->extendCommonMarkEnvironment($environment);
$this->docParser = new DocParser($environment);
$this->htmlRenderer = new HtmlRenderer($environment);
}

View File

@ -33,11 +33,17 @@ class Command extends SymfonyCommand
$processor = $input->getOption('processor');
if (!empty($processor) && $processor != 'none') {
if (file_exists($processor)) {
include $processor;
}
$class = "\\Todaymade\\Daux\\Extension\\" . $processor;
if (class_exists($class)) {
$daux->setProcessor(new $class($daux, $output, $width));
} else if (file_exists($processor)) {
include $processor;
}
}
// Improve the tree with a processor
$daux->getProcessor()->manipulateTree($daux->tree);
switch(strtolower($input->getOption('format'))) {
case 'confluence':
(new ConfluenceGenerator())->generate($daux, $output, $width);

38
libs/Processor.php Normal file
View File

@ -0,0 +1,38 @@
<?php namespace Todaymade\Daux;
use League\CommonMark\Environment;
use Symfony\Component\Console\Output\OutputInterface;
use Todaymade\Daux\Tree\Directory;
class Processor
{
/**
* @var Daux
*/
protected $daux;
/**
* @var OutputInterface
*/
protected $output;
/**
* @var integer
*/
protected $width;
public function __construct(Daux $daux, OutputInterface $output, $width)
{
$this->daux = $daux;
$this->output = $output;
$this->width = $width;
}
public function manipulateTree(Directory $root)
{
}
public function extendCommonMarkEnvironment(Environment $environment)
{
}
}