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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Daux $daux
|
|
|
|
*/
|
|
|
|
public function __construct(Daux $daux)
|
|
|
|
{
|
2017-12-11 22:25:45 +01:00
|
|
|
$params = $daux->getParams();
|
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
$this->daux = $daux;
|
2017-12-11 22:25:45 +01:00
|
|
|
$this->templateRenderer = new Template($params);
|
|
|
|
$params->templateRenderer = $this->templateRenderer;
|
2015-11-06 22:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getContentTypes()
|
|
|
|
{
|
|
|
|
return [
|
2016-07-27 21:32:51 +02:00
|
|
|
'markdown' => new ContentType($this->daux->getParams()),
|
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');
|
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
$params = $this->daux->getParams();
|
2018-09-21 23:43:06 +02:00
|
|
|
if (is_null($destination)) {
|
|
|
|
$destination = $this->daux->local_base . DIRECTORY_SEPARATOR . 'static';
|
|
|
|
}
|
2015-11-06 22:44:34 +01:00
|
|
|
|
2018-09-21 23:43:06 +02:00
|
|
|
$this->runAction(
|
|
|
|
'Cleaning destination folder ...',
|
|
|
|
$width,
|
|
|
|
function() use ($destination, $params) {
|
|
|
|
$this->ensureEmptyDestination($destination);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'author' => $params['author'],
|
|
|
|
'title' => $params['title'],
|
|
|
|
'subject' => $params['tagline']
|
|
|
|
];
|
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,
|
|
|
|
function () use ($book, $current, $params) {
|
|
|
|
$contentType = $this->daux->getContentTypeHandler()->getType($current);
|
2017-12-11 22:25:45 +01:00
|
|
|
$content = ContentPage::fromFile($current, $params, $contentType);
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|