2015-11-06 22:44:34 +01:00
|
|
|
<?php namespace Todaymade\Daux\Format\HTMLFile;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Todaymade\Daux\Console\RunAction;
|
|
|
|
use Todaymade\Daux\Daux;
|
2017-12-11 22:25:45 +01:00
|
|
|
use Todaymade\Daux\Format\HTML\Template;
|
2018-09-21 23:43:06 +02:00
|
|
|
use Todaymade\Daux\Format\HTML\HTMLUtils;
|
|
|
|
use Todaymade\Daux\Format\HTMLFile\ContentTypes\Markdown\ContentType;
|
2015-11-06 22:44:34 +01:00
|
|
|
|
|
|
|
class Generator implements \Todaymade\Daux\Format\Base\Generator
|
|
|
|
{
|
2018-09-21 23:43:06 +02:00
|
|
|
use RunAction, HTMLUtils;
|
2015-11-06 22:44:34 +01:00
|
|
|
|
|
|
|
/** @var Daux */
|
|
|
|
protected $daux;
|
|
|
|
|
2019-11-28 23:32:33 +01:00
|
|
|
/** @var Template */
|
|
|
|
protected $templateRenderer;
|
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
/**
|
|
|
|
* @param Daux $daux
|
|
|
|
*/
|
|
|
|
public function __construct(Daux $daux)
|
|
|
|
{
|
2019-12-05 21:25:58 +01:00
|
|
|
$config = $daux->getConfig();
|
2017-12-11 22:25:45 +01:00
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
$this->daux = $daux;
|
2019-12-05 21:25:58 +01:00
|
|
|
$this->templateRenderer = new Template($config);
|
|
|
|
$config->templateRenderer = $this->templateRenderer;
|
2015-11-06 22:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getContentTypes()
|
|
|
|
{
|
|
|
|
return [
|
2019-12-05 21:25:58 +01:00
|
|
|
'markdown' => new ContentType($this->daux->getConfig()),
|
2015-11-06 22:44:34 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function generateAll(InputInterface $input, OutputInterface $output, $width)
|
|
|
|
{
|
2018-09-21 23:43:06 +02:00
|
|
|
$destination = $input->getOption('destination');
|
|
|
|
|
2019-12-05 21:25:58 +01:00
|
|
|
$config = $this->daux->getConfig();
|
2018-09-21 23:43:06 +02:00
|
|
|
if (is_null($destination)) {
|
2019-12-07 11:22:40 +01:00
|
|
|
$destination = $config->getLocalBase() . DIRECTORY_SEPARATOR . 'static';
|
2018-09-21 23:43:06 +02:00
|
|
|
}
|
2015-11-06 22:44:34 +01:00
|
|
|
|
2018-09-21 23:43:06 +02:00
|
|
|
$this->runAction(
|
|
|
|
'Cleaning destination folder ...',
|
|
|
|
$width,
|
2020-04-22 21:55:53 +02:00
|
|
|
function () use ($destination) {
|
2018-09-21 23:43:06 +02:00
|
|
|
$this->ensureEmptyDestination($destination);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = [
|
2019-12-05 21:25:58 +01:00
|
|
|
'author' => $config->getAuthor(),
|
|
|
|
'title' => $config->getTitle(),
|
|
|
|
'subject' => $config->getTagline()
|
2018-09-21 23:43:06 +02:00
|
|
|
];
|
2015-11-06 22:44:34 +01:00
|
|
|
|
|
|
|
$book = new Book($this->daux->tree, $data);
|
|
|
|
|
|
|
|
$current = $this->daux->tree->getIndexPage();
|
|
|
|
while ($current) {
|
|
|
|
$this->runAction(
|
2016-07-27 21:32:51 +02:00
|
|
|
'Generating ' . $current->getTitle(),
|
2015-11-06 22:44:34 +01:00
|
|
|
$width,
|
2020-04-22 21:55:53 +02:00
|
|
|
function () use ($book, $current, $config) {
|
2015-11-06 22:44:34 +01:00
|
|
|
$contentType = $this->daux->getContentTypeHandler()->getType($current);
|
2019-12-05 21:25:58 +01:00
|
|
|
$content = ContentPage::fromFile($current, $config, $contentType);
|
2017-12-11 22:25:45 +01:00
|
|
|
$content->templateRenderer = $this->templateRenderer;
|
|
|
|
$content = $content->getContent();
|
2015-11-06 22:44:34 +01:00
|
|
|
$book->addPage($current, $content);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$current = $current->getNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = $book->generate();
|
|
|
|
file_put_contents($input->getOption('destination') . '/file.html', $content);
|
|
|
|
}
|
|
|
|
}
|