2015-05-21 17:39:11 +02:00
|
|
|
<?php namespace Todaymade\Daux\Format\HTML;
|
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2015-05-21 17:39:11 +02:00
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
use Todaymade\Daux\DauxHelper;
|
2015-07-14 22:06:01 +02:00
|
|
|
use Todaymade\Daux\Format\Base\RunAction;
|
2015-05-21 17:39:11 +02:00
|
|
|
use Todaymade\Daux\Generator\Helper;
|
|
|
|
use Todaymade\Daux\Tree\Directory;
|
|
|
|
use Todaymade\Daux\Tree\Content;
|
|
|
|
|
|
|
|
class Generator
|
|
|
|
{
|
2015-07-14 22:06:01 +02:00
|
|
|
use RunAction;
|
|
|
|
|
|
|
|
public function generate(Daux $daux, $destination, OutputInterface $output, $width)
|
2015-05-21 17:39:11 +02:00
|
|
|
{
|
|
|
|
$params = $daux->getParams();
|
|
|
|
if (is_null($destination)) {
|
|
|
|
$destination = $daux->local_base . DS . 'static';
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
$this->runAction(
|
|
|
|
"Copying Static assets ...",
|
|
|
|
$output,
|
|
|
|
$width,
|
|
|
|
function() use ($destination, $daux) {
|
|
|
|
Helper::copyAssets($destination, $daux->local_base);
|
|
|
|
}
|
|
|
|
);
|
2015-05-21 17:39:11 +02:00
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
$output->writeLn("Generating ...");
|
|
|
|
$this->generateRecursive($daux->tree, $destination, $params, $output, $width);
|
2015-05-21 17:39:11 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
private function generateRecursive($tree, $output_dir, $params, $output, $width, $base_url = '')
|
2015-05-21 17:39:11 +02:00
|
|
|
{
|
|
|
|
$params['base_url'] = $params['base_page'] = $base_url;
|
|
|
|
|
|
|
|
// Rebase Theme
|
2015-05-22 15:05:16 +02:00
|
|
|
$params['theme'] = DauxHelper::getTheme($params, $base_url);
|
2015-05-21 17:39:11 +02:00
|
|
|
|
|
|
|
$params['image'] = str_replace('<base_url>', $base_url, $params['image']);
|
2015-06-30 15:50:42 +02:00
|
|
|
if ($base_url !== '' && empty($params['entry_page'])) {
|
2015-05-21 17:39:11 +02:00
|
|
|
$params['entry_page'] = $tree->getFirstPage();
|
|
|
|
}
|
|
|
|
foreach ($tree->value as $key => $node) {
|
|
|
|
if ($node instanceof Directory) {
|
|
|
|
$new_output_dir = $output_dir . DS . $key;
|
|
|
|
@mkdir($new_output_dir);
|
2015-07-14 22:06:01 +02:00
|
|
|
$this->generateRecursive($node, $new_output_dir, $params, $output, $width, '../' . $base_url);
|
2015-05-21 17:39:11 +02:00
|
|
|
} elseif ($node instanceof Content) {
|
2015-07-14 22:06:01 +02:00
|
|
|
$this->runAction(
|
|
|
|
"- " . $node->getUrl(),
|
|
|
|
$output,
|
|
|
|
$width,
|
|
|
|
function() use ($node, $output_dir, $key, $params) {
|
|
|
|
$params['request'] = $node->getUrl();
|
|
|
|
$params['file_uri'] = $node->getName();
|
2015-05-21 17:39:11 +02:00
|
|
|
|
2015-07-14 22:06:01 +02:00
|
|
|
$page = MarkdownPage::fromFile($node, $params);
|
|
|
|
file_put_contents($output_dir . DS . $key, $page->getContent());
|
|
|
|
}
|
|
|
|
);
|
2015-05-21 17:39:11 +02:00
|
|
|
} else {
|
2015-07-14 22:06:01 +02:00
|
|
|
$this->runAction(
|
|
|
|
"- " . $node->getUrl(),
|
|
|
|
$output,
|
|
|
|
$width,
|
|
|
|
function() use ($node, $output_dir, $key) {
|
|
|
|
copy($node->getPath(), $output_dir . DS . $key);
|
|
|
|
}
|
|
|
|
);
|
2015-05-21 17:39:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|