Transform the server to be able to use the Generator
Cette révision appartient à :
Parent
d531de86cf
révision
932fab5a84
@ -6,5 +6,16 @@ use Todaymade\Daux\Daux;
|
||||
|
||||
interface Generator
|
||||
{
|
||||
public function generate(Daux $daux, InputInterface $input, OutputInterface $output, $width);
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
public function __construct(Daux $daux);
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @param integer $width
|
||||
* @return mixed
|
||||
*/
|
||||
public function generateAll(InputInterface $input, OutputInterface $output, $width);
|
||||
}
|
||||
|
@ -13,32 +13,38 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
{
|
||||
use RunAction;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* @var CommonMarkConverter
|
||||
*/
|
||||
/** @var CommonMarkConverter */
|
||||
protected $converter;
|
||||
|
||||
public function generate(Daux $daux, InputInterface $input, OutputInterface $output, $width)
|
||||
/** @var Daux */
|
||||
protected $daux;
|
||||
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$params = $daux->getParams();
|
||||
$this->daux = $daux;
|
||||
$this->converter = new CommonMarkConverter(['daux' => $this->daux->getParams()]);
|
||||
}
|
||||
|
||||
public function generateAll(InputInterface $input, OutputInterface $output, $width)
|
||||
{
|
||||
$params = $this->daux->getParams();
|
||||
|
||||
$confluence = $params['confluence'];
|
||||
$this->prefix = trim($confluence['prefix']) . " ";
|
||||
|
||||
$this->converter = new CommonMarkConverter(['daux' => $params]);
|
||||
|
||||
$tree = $this->runAction(
|
||||
"Generating Tree ...",
|
||||
$output,
|
||||
$width,
|
||||
function() use ($daux, $params) {
|
||||
$tree = $this->generateRecursive($daux->tree, $params);
|
||||
$tree['title'] = $this->prefix . $daux->getParams()['title'];
|
||||
function() use ($params) {
|
||||
$tree = $this->generateRecursive($this->daux->tree, $params);
|
||||
$tree['title'] = $this->prefix . $params['title'];
|
||||
|
||||
return $tree;
|
||||
}
|
||||
@ -70,7 +76,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
);
|
||||
} elseif ($node instanceof Content) {
|
||||
$params['request'] = $node->getUrl();
|
||||
$params['file_uri'] = $node->getName();
|
||||
|
||||
$data = [
|
||||
'title' => $this->prefix . $node->getTitle(),
|
||||
|
@ -8,40 +8,50 @@ use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter;
|
||||
use Todaymade\Daux\Format\Base\RunAction;
|
||||
use Todaymade\Daux\Generator\Helper;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
use Todaymade\Daux\Tree\Raw;
|
||||
|
||||
class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
{
|
||||
use RunAction;
|
||||
|
||||
/**
|
||||
* @var CommonMarkConverter
|
||||
*/
|
||||
/** @var CommonMarkConverter */
|
||||
protected $converter;
|
||||
|
||||
public function generate(Daux $daux, InputInterface $input, OutputInterface $output, $width)
|
||||
/** @var Daux */
|
||||
protected $daux;
|
||||
|
||||
/**
|
||||
* @param Daux $daux
|
||||
*/
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
$this->converter = new CommonMarkConverter(['daux' => $this->daux->getParams()]);
|
||||
}
|
||||
|
||||
public function generateAll(InputInterface $input, OutputInterface $output, $width)
|
||||
{
|
||||
$destination = $input->getOption('destination');
|
||||
|
||||
$params = $daux->getParams();
|
||||
$params = $this->daux->getParams();
|
||||
if (is_null($destination)) {
|
||||
$destination = $daux->local_base . DS . 'static';
|
||||
$destination = $this->daux->local_base . DS . 'static';
|
||||
}
|
||||
|
||||
$this->converter = new CommonMarkConverter(['daux' => $params]);
|
||||
|
||||
$this->runAction(
|
||||
"Copying Static assets ...",
|
||||
$output,
|
||||
$width,
|
||||
function() use ($destination, $daux) {
|
||||
Helper::copyAssets($destination, $daux->local_base);
|
||||
function () use ($destination) {
|
||||
Helper::copyAssets($destination, $this->daux->local_base);
|
||||
}
|
||||
);
|
||||
|
||||
$output->writeLn("Generating ...");
|
||||
$this->generateRecursive($daux->tree, $destination, $params, $output, $width);
|
||||
$this->generateRecursive($this->daux->tree, $destination, $params, $output, $width);
|
||||
}
|
||||
|
||||
private function rebaseConfig(Config $config, $base_url)
|
||||
@ -84,29 +94,32 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator
|
||||
|
||||
// Rebase configuration again as $params is a shared object
|
||||
$this->rebaseConfig($params, $base_url);
|
||||
} elseif ($node instanceof Content) {
|
||||
$this->runAction(
|
||||
"- " . $node->getUrl(),
|
||||
$output,
|
||||
$width,
|
||||
function() use ($node, $output_dir, $key, $params) {
|
||||
$params['request'] = $node->getUrl();
|
||||
$params['file_uri'] = $node->getName();
|
||||
|
||||
$page = MarkdownPage::fromFile($node, $params, $this->converter);
|
||||
file_put_contents($output_dir . DS . $key, $page->getContent());
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$this->runAction(
|
||||
"- " . $node->getUrl(),
|
||||
$output,
|
||||
$width,
|
||||
function() use ($node, $output_dir, $key) {
|
||||
copy($node->getPath(), $output_dir . DS . $key);
|
||||
function () use ($node, $output_dir, $key, $params) {
|
||||
if (!$node instanceof Content) {
|
||||
copy($node->getPath(), $output_dir . DS . $key);
|
||||
return;
|
||||
}
|
||||
|
||||
$generated = $this->generateOne($node, $params);
|
||||
file_put_contents($output_dir . DS . $key, $generated->getContent());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function generateOne(Entry $node, $params)
|
||||
{
|
||||
if ($node instanceof Raw) {
|
||||
return new RawPage($node->getPath());
|
||||
}
|
||||
|
||||
$params['request'] = $node->getUrl();
|
||||
return MarkdownPage::fromFile($node, $params, $this->converter);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,6 @@ class Command extends SymfonyCommand
|
||||
throw new \RuntimeException("the class '$class' does not implement the '$interface' interface");
|
||||
}
|
||||
|
||||
(new $class())->generate($daux, $input, $output, $width);
|
||||
(new $class($daux))->generateAll($input, $output, $width);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,8 @@
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception;
|
||||
use Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter;
|
||||
use Todaymade\Daux\Format\HTML\MarkdownPage;
|
||||
use Todaymade\Daux\Format\HTML\Generator;
|
||||
use Todaymade\Daux\Format\HTML\RawPage;
|
||||
use Todaymade\Daux\Tree\Raw;
|
||||
|
||||
class Server
|
||||
{
|
||||
@ -123,18 +121,9 @@ class Server
|
||||
throw new NotFoundException('The Page you requested is yet to be made. Try again later.');
|
||||
}
|
||||
|
||||
if ($file instanceof Raw) {
|
||||
return new RawPage($file->getPath());
|
||||
}
|
||||
|
||||
$params = $this->params;
|
||||
|
||||
$params['request'] = $request;
|
||||
$params['file_uri'] = $file->getUri();
|
||||
if ($request !== 'index') {
|
||||
$params['entry_page'] = $file->getFirstPage();
|
||||
}
|
||||
return MarkdownPage::fromFile($file, $params, new CommonMarkConverter(['daux' => $params]));
|
||||
// TODO :: make it possible to replace the generator in live code
|
||||
$generator = new Generator($this->daux);
|
||||
return $generator->generateOne($file, $this->params);
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
|
Chargement…
Référencer dans un nouveau ticket
Block a user