Convert to PSR2

Cette révision appartient à :
Stéphane Goetz
2015-04-23 00:32:30 +02:00
Parent ecd5efe758
révision de1214cbab
21 fichiers modifiés avec 664 ajouts et 493 suppressions

Voir le fichier

@ -1,45 +1,49 @@
<?php namespace Todaymade\Daux\Generator;
use Todaymade\Daux\Daux;
use Todaymade\Daux\Entry;
use Todaymade\Daux\MarkdownPage;
use Todaymade\Daux\Tree\Directory;
use Todaymade\Daux\Tree\Content;
class Generator {
public function generate($global_config, $destination) {
class Generator
{
public function generate($global_config, $destination)
{
$daux = new Daux(Daux::STATIC_MODE);
$daux->initialize($global_config);
$this->generate_static($daux, $destination);
$params = $daux->getParams();
if (is_null($destination)) {
$destination = $daux->local_base . DS . 'static';
}
Helper::copyAssets($destination, $daux->local_base);
$this->generateRecursive($daux->tree, $destination, $params);
}
public function generate_static(Daux $daux, $output_dir = NULL) {
$params = $daux->get_page_params();
if (is_null($output_dir)) $output_dir = $daux->local_base . DIRECTORY_SEPARATOR . 'static';
Helper::clean_copy_assets($output_dir, $daux->local_base);
$this->recursive_generate_static($daux->tree, $output_dir, $params);
}
private function recursive_generate_static($tree, $output_dir, $params, $base_url = '') {
private function generateRecursive($tree, $output_dir, $params, $base_url = '')
{
$params['base_url'] = $params['base_page'] = $base_url;
$new_params = $params;
//
$params['image'] = str_replace('<base_url>', $base_url, $params['image']);
if ($base_url !== '') $params['entry_page'] = $tree->first_page;
if ($base_url !== '') {
$params['entry_page'] = $tree->getFirstPage();
}
foreach ($tree->value as $key => $node) {
if ($node instanceof Directory) {
$new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key;
$new_output_dir = $output_dir . DS . $key;
@mkdir($new_output_dir);
$this->recursive_generate_static($node, $new_output_dir, $new_params, '../' . $base_url);
} else if ($node instanceof Content) {
$params['request'] = $node->get_url();
$params['file_uri'] = $node->name;
$this->generateRecursive($node, $new_output_dir, $new_params, '../' . $base_url);
} elseif ($node instanceof Content) {
$params['request'] = $node->getUrl();
$params['file_uri'] = $node->getName();
$page = MarkdownPage::fromFile($node, $params);
file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $page->get_page_content());
file_put_contents($output_dir . DS . $key, $page->getContent());
} else {
copy($node->local_path, $output_dir . DIRECTORY_SEPARATOR . $key);
copy($node->getPath(), $output_dir . DS . $key);
}
}
}

Voir le fichier

@ -1,48 +1,55 @@
<?php namespace Todaymade\Daux\Generator;
use Todaymade\Daux\DauxHelper;
class Helper
{
class Helper {
public static function clean_copy_assets($path, $local_base){
public static function copyAssets($path, $local_base)
{
@mkdir($path);
static::clean_directory($path);
static::rmdir($path);
@mkdir($path . DS . 'resources');
static::copyRecursive($local_base . DS . 'resources', $path . DS . 'resources');
@mkdir($path . DS . 'js');
static::copyRecursive($local_base . DS . 'js', $path . DS . 'js');
@mkdir($path . DIRECTORY_SEPARATOR . 'resources');
static::copy_recursive($local_base . DIRECTORY_SEPARATOR . 'resources', $path . DIRECTORY_SEPARATOR . 'resources');
@mkdir($path . DIRECTORY_SEPARATOR . 'js');
static::copy_recursive($local_base . DIRECTORY_SEPARATOR . 'js', $path . DIRECTORY_SEPARATOR . 'js');
//added and changed these in order to fetch the theme files and put them in the right place
@mkdir($path . DIRECTORY_SEPARATOR . 'templates');
@mkdir($path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'default');
@mkdir($path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'themes');
static::copy_recursive(
$local_base . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'themes',
$path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'themes'
@mkdir($path . DS . 'templates');
@mkdir($path . DS . 'templates' . DS . 'default');
@mkdir($path . DS . 'templates' . DS . 'default' . DS . 'themes');
static::copyRecursive(
$local_base . DS . 'templates' . DS . 'default' . DS . 'themes',
$path . DS . 'templates' . DS . 'default' . DS . 'themes'
);
}
// Rmdir
private static function clean_directory($dir) {
private static function rmdir($dir)
{
$it = new \RecursiveDirectoryIterator($dir);
$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') continue;
if ($file->isDir()) rmdir($file->getRealPath());
else unlink($file->getRealPath());
foreach ($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
}
private static function copy_recursive($src,$dst) {
private static function copyRecursive($src, $dst)
{
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
static::copy_recursive($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
if (is_dir($src . '/' . $file)) {
static::copyRecursive($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}