Added confluence export type, starts to work

This commit is contained in:
Stéphane Goetz
2015-05-21 17:39:11 +02:00
committed by Stéphane Goetz
parent 90dbdb4f0b
commit 1445bf7c0f
10 changed files with 929 additions and 55 deletions

View File

@ -1,63 +1,24 @@
<?php namespace Todaymade\Daux\Generator;
use Todaymade\Daux\Daux;
use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Format\HTML\MarkdownPage;
use Todaymade\Daux\Tree\Directory;
use Todaymade\Daux\Tree\Content;
use Todaymade\Daux\Format\HTML\Generator as HTMLGenerator;
use Todaymade\Daux\Format\Confluence\Generator as ConfluenceGenerator;
class Generator
{
public function generate($global_config, $destination)
public function generate($options)
{
$daux = new Daux(Daux::STATIC_MODE);
$daux->initialize($global_config);
$daux->initialize(null, $options['config']);
$params = $daux->getParams();
if (is_null($destination)) {
$destination = $daux->local_base . DS . 'static';
switch(strtolower($options['format'])) {
case 'confluence':
(new ConfluenceGenerator())->generate($daux, $options['destination']);
break;
case 'html':
default:
(new HTMLGenerator())->generate($daux, $options['destination']);
}
echo "Copying Static assets ...\n";
Helper::copyAssets($destination, $daux->local_base);
echo "Generating ...\n";
$this->generateRecursive($daux->tree, $destination, $params);
echo "Done !\n";
}
private function generateRecursive($tree, $output_dir, $params, $base_url = '')
{
$params['base_url'] = $params['base_page'] = $base_url;
// Rebase Theme
$params['theme'] = DauxHelper::getTheme(
$params['theme-name'],
$params['base_url'],
$params['local_base'],
$base_url
);
$params['image'] = str_replace('<base_url>', $base_url, $params['image']);
if ($base_url !== '') {
$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);
$this->generateRecursive($node, $new_output_dir, $params, '../' . $base_url);
} elseif ($node instanceof Content) {
echo "- " . $node->getUrl() . "\n";
$params['request'] = $node->getUrl();
$params['file_uri'] = $node->getName();
$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);
}
}
}
}