Use symfony console, nicer output
This commit is contained in:
@ -1,29 +1,38 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Format\Base\RunAction;
|
||||
use Todaymade\Daux\Generator\Helper;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
|
||||
class Generator
|
||||
{
|
||||
public function generate(Daux $daux, $destination)
|
||||
use RunAction;
|
||||
|
||||
public function generate(Daux $daux, $destination, OutputInterface $output, $width)
|
||||
{
|
||||
$params = $daux->getParams();
|
||||
if (is_null($destination)) {
|
||||
$destination = $daux->local_base . DS . 'static';
|
||||
}
|
||||
|
||||
echo "Copying Static assets ...\n";
|
||||
Helper::copyAssets($destination, $daux->local_base);
|
||||
$this->runAction(
|
||||
"Copying Static assets ...",
|
||||
$output,
|
||||
$width,
|
||||
function() use ($destination, $daux) {
|
||||
Helper::copyAssets($destination, $daux->local_base);
|
||||
}
|
||||
);
|
||||
|
||||
echo "Generating ...\n";
|
||||
$this->generateRecursive($daux->tree, $destination, $params);
|
||||
echo "Done !\n";
|
||||
$output->writeLn("Generating ...");
|
||||
$this->generateRecursive($daux->tree, $destination, $params, $output, $width);
|
||||
}
|
||||
|
||||
private function generateRecursive($tree, $output_dir, $params, $base_url = '')
|
||||
private function generateRecursive($tree, $output_dir, $params, $output, $width, $base_url = '')
|
||||
{
|
||||
$params['base_url'] = $params['base_page'] = $base_url;
|
||||
|
||||
@ -38,17 +47,29 @@ class Generator
|
||||
if ($node instanceof Directory) {
|
||||
$new_output_dir = $output_dir . DS . $key;
|
||||
@mkdir($new_output_dir);
|
||||
$this->generateRecursive($node, $new_output_dir, $params, '../' . $base_url);
|
||||
$this->generateRecursive($node, $new_output_dir, $params, $output, $width, '../' . $base_url);
|
||||
} elseif ($node instanceof Content) {
|
||||
echo "- " . $node->getUrl() . "\n";
|
||||
$params['request'] = $node->getUrl();
|
||||
$params['file_uri'] = $node->getName();
|
||||
$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);
|
||||
file_put_contents($output_dir . DS . $key, $page->getContent());
|
||||
$page = MarkdownPage::fromFile($node, $params);
|
||||
file_put_contents($output_dir . DS . $key, $page->getContent());
|
||||
}
|
||||
);
|
||||
} else {
|
||||
echo "- " . $node->getUrl() . "\n";
|
||||
copy($node->getPath(), $output_dir . DS . $key);
|
||||
$this->runAction(
|
||||
"- " . $node->getUrl(),
|
||||
$output,
|
||||
$width,
|
||||
function() use ($node, $output_dir, $key) {
|
||||
copy($node->getPath(), $output_dir . DS . $key);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Verwijs in nieuw issue
Block a user