From 061ea5ea55d879efad11e4ede6a58dcefdd1a306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Goetz?= Date: Mon, 20 Jul 2015 15:59:52 +0200 Subject: [PATCH] Code Style and refactorings --- daux.phar | Bin 715082 -> 716480 bytes generate | 2 - index.php | 2 - libs/Daux.php | 101 +++++++++--------- libs/DauxHelper.php | 15 ++- libs/Format/Base/CommonMark/LinkRenderer.php | 11 ++ .../Confluence/CommonMark/LinkRenderer.php | 11 ++ libs/Format/Confluence/Generator.php | 3 + libs/Format/Confluence/Publisher.php | 2 +- libs/Format/HTML/Generator.php | 12 +-- libs/Generator/Command.php | 4 +- libs/Generator/Helper.php | 7 +- libs/Server/Server.php | 6 +- libs/Tree/Builder.php | 37 ++----- libs/Tree/Directory.php | 4 +- templates/content.php | 20 ++-- templates/error.php | 4 +- templates/home.php | 28 +++-- templates/layout/00_layout.php | 44 +++++--- templates/layout/05_page.php | 23 ++-- templates/partials/navbar_content.php | 2 +- 21 files changed, 193 insertions(+), 145 deletions(-) mode change 100644 => 100755 daux.phar diff --git a/daux.phar b/daux.phar old mode 100644 new mode 100755 index 3621bae04c8e581fcbca7b8a0d5ac3c1962d0bf3..20e5f6b63010de61a74533a80eed8f552ca9688e GIT binary patch delta 8401 zcmbVR33yZ0w$5&wq&=O|CY{^#bWGE9E-jr03Z>8)T80j^X?mIl(j-mNGE^qfB8n8c zm7|CZSM(|%SFMsyLGa;K0SCYfS3prwyb356o)dys-#&XK)PeW$zSr+NU1#sT_8R}S z_D*v2ea&m)euLHYcY*mt1SB#lvnB-H8(Xnp=VFW2bC^ z%6u*kW5zv~E>^h5=d0X6oIodin5El`2p9SDC6Ce2WlNu|9axlR>9zC+0i!@){9u(A z-sT=H`z{711^UGy(?xvDJ(i08&b=Lr^sdS%IiNE8J(1iDK#$BtXP(kRmdUg@&E5?B=I=2r@P z@KLV>8Sep;0zLF|XfFQM3j!L?q{+T_=1QOoUc53BcQHv++=EO3rAHZ!EZ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ate b/generate index 146dd5b..9c5d154 100755 --- a/generate +++ b/generate @@ -66,7 +66,5 @@ software, even if advised of the possibility of such damage. require_once("vendor/autoload.php"); -\Todaymade\Daux\Daux::initConstants(); - $application = new \Todaymade\Daux\Generator\Application(); $application->run(); diff --git a/index.php b/index.php index 5dd44fe..350e1f4 100644 --- a/index.php +++ b/index.php @@ -84,6 +84,4 @@ if (file_exists('vendor/autoload.php')) { throw new Exception("Impossible to load Daux, missing vendor and phar"); } -\Todaymade\Daux\Daux::initConstants(); - \Todaymade\Daux\Server\Server::serve($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], $_REQUEST); diff --git a/libs/Daux.php b/libs/Daux.php index c654ba2..14815ba 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -53,22 +53,32 @@ class Daux } } - public static function initConstants() - { - define("DS", DIRECTORY_SEPARATOR); - } - /** * @param string $override_file * @throws Exception */ public function initialize($override_file = 'config.json') { - //global.json (docs dir, markdown files) - $this->loadConfig(); + // global.json + $this->loadBaseConfiguration(); - //config.json - $this->loadConfigOverrides($override_file); + // Check the documentation path + $this->docs_path = $this->options['docs_directory']; + if (!is_dir($this->docs_path) && + !is_dir($this->docs_path = $this->local_base . DIRECTORY_SEPARATOR . $this->docs_path) + ) { + throw new Exception('The Docs directory does not exist. Check the path again : ' . $this->docs_path); + } + + // /config.json, + $this->loadConfigurationOverrides($override_file); + + // Set a valid default timezone + if (isset($this->options['timezone'])) { + date_default_timezone_set($this->options['timezone']); + } elseif (!ini_get('date.timezone')) { + date_default_timezone_set('GMT'); + } } /** @@ -76,31 +86,18 @@ class Daux * * @throws Exception */ - private function loadConfig() + protected function loadBaseConfiguration() { - $default_config = [ + $this->options = new Config(); + + // Set the default configuration + $this->options->merge([ 'docs_directory' => 'docs', 'valid_content_extensions' => ['md', 'markdown'] - ]; + ]); - $global_config_file = $this->local_base . DS . 'global.json'; - - if (!file_exists($global_config_file)) { - throw new Exception('The Global Config file is missing. Requested File : ' . $global_config_file); - } - - $default_config = array_merge($default_config, json_decode(file_get_contents($global_config_file), true)); - if (!isset($default_config)) { - throw new Exception('The Global Config file is corrupt. Check that the JSON encoding is correct'); - } - - $this->docs_path = $default_config['docs_directory']; - if (!is_dir($this->docs_path) && !is_dir($this->docs_path = $this->local_base . DS . $this->docs_path)) { - throw new Exception('The Docs directory does not exist. Check the path again : ' . $this->docs_path); - } - - $this->options = new Config(); - $this->options->merge($default_config); + // Load the global configuration + $this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . 'global.json', false); } /** @@ -111,33 +108,37 @@ class Daux * @param string $override_file * @throws Exception */ - private function loadConfigOverrides($override_file) + protected function loadConfigurationOverrides($override_file) { // Read documentation overrides - $config_file = $this->docs_path . DS . 'config.json'; - if (file_exists($config_file)) { - $config = json_decode(file_get_contents($config_file), true); - if (!isset($config)) { - throw new Exception('The local config file is missing. Check path : ' . $config_file); - } - $this->options->merge($config); - } + $this->loadConfiguration($this->docs_path . DIRECTORY_SEPARATOR . 'config.json'); // Read command line overrides - $config_file = $this->local_base . DS . $override_file; - if (!is_null($override_file) && file_exists($config_file)) { - $config = json_decode(file_get_contents($config_file), true); - if (!isset($config)) { - throw new Exception('The local config file is missing. Check path : ' . $config_file); + if (!is_null($override_file)) { + $this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file); + } + } + + /** + * @param string $config_file + * @param bool $optional + * @throws Exception + */ + protected function loadConfiguration($config_file, $optional = true) + { + if (!file_exists($config_file)) { + if ($optional) { + return; } - $this->options->merge($config); + + throw new Exception('The configuration file is missing. Check path : ' . $config_file); } - if (isset($this->options['timezone'])) { - date_default_timezone_set($this->options['timezone']); - } elseif (!ini_get('date.timezone')) { - date_default_timezone_set('GMT'); + $config = json_decode(file_get_contents($config_file), true); + if (!isset($config)) { + throw new Exception('The configuration file "' . $config_file . '" is corrupt. Is your JSON well-formed ?'); } + $this->options->merge($config); } /** @@ -169,7 +170,7 @@ class Daux 'mode' => $this->mode, 'local_base' => $this->local_base, 'docs_path' => $this->docs_path, - 'templates' => $this->internal_base . DS . 'templates', + 'templates' => $this->internal_base . DIRECTORY_SEPARATOR . 'templates', ]; $this->options->conservativeMerge($default); diff --git a/libs/DauxHelper.php b/libs/DauxHelper.php index 1671442..f826fd1 100644 --- a/libs/DauxHelper.php +++ b/libs/DauxHelper.php @@ -4,6 +4,12 @@ use Todaymade\Daux\Tree\Directory; class DauxHelper { + /** + * Set a new base_url for the configuration + * + * @param Config $config + * @param string $base_url + */ public static function rebaseConfiguration(Config $config, $base_url) { // Avoid changing the url if it is already correct @@ -24,12 +30,13 @@ class DauxHelper */ public static function getTheme($params, $current_url) { - $theme_folder = $params['local_base'] . DS . 'resources' . DS . 'themes' . DS . $params['html']['theme']; + $theme_folder = $params['local_base'] . DIRECTORY_SEPARATOR . 'resources' . + DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $params['html']['theme']; $theme_url = $params['base_url'] . "resources/themes/" . $params['html']['theme'] . '/'; $theme = array(); - if (is_file($theme_folder . DS . "config.json")) { - $theme = json_decode(file_get_contents($theme_folder . DS . "config.json"), true); + if (is_file($theme_folder . DIRECTORY_SEPARATOR . "config.json")) { + $theme = json_decode(file_get_contents($theme_folder . DIRECTORY_SEPARATOR . "config.json"), true); if (!$theme) { $theme = array(); } @@ -44,7 +51,7 @@ class DauxHelper 'require-jquery' => false, 'bootstrap-js' => false, 'favicon' => 'resources/img/favicon.png', - 'templates' => $theme_folder . DS . 'templates', + 'templates' => $theme_folder . DIRECTORY_SEPARATOR . 'templates', ]; $substitutions = [ diff --git a/libs/Format/Base/CommonMark/LinkRenderer.php b/libs/Format/Base/CommonMark/LinkRenderer.php index 3411dfd..06c7ebd 100644 --- a/libs/Format/Base/CommonMark/LinkRenderer.php +++ b/libs/Format/Base/CommonMark/LinkRenderer.php @@ -49,6 +49,17 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer */ public function render(AbstractInline $inline, HtmlRendererInterface $htmlRenderer) { + // This can't be in the method type as + // the method is an abstract and should + // have the same interface + if (!$inline instanceof Link) { + throw new \RuntimeException( + "Wrong type passed to " . __CLASS__ . "::" . __METHOD__ . + " the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" . + get_class($inline) . "' was provided" + ); + } + $element = parent::render($inline, $htmlRenderer); $url = $inline->getUrl(); diff --git a/libs/Format/Confluence/CommonMark/LinkRenderer.php b/libs/Format/Confluence/CommonMark/LinkRenderer.php index 2ae066f..5b6bfd2 100644 --- a/libs/Format/Confluence/CommonMark/LinkRenderer.php +++ b/libs/Format/Confluence/CommonMark/LinkRenderer.php @@ -15,6 +15,17 @@ class LinkRenderer extends \Todaymade\Daux\Format\Base\CommonMark\LinkRenderer */ public function render(AbstractInline $inline, HtmlRendererInterface $htmlRenderer) { + // This can't be in the method type as + // the method is an abstract and should + // have the same interface + if (!$inline instanceof Link) { + throw new \RuntimeException( + "Wrong type passed to " . __CLASS__ . "::" . __METHOD__ . + " the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" . + get_class($inline) . "' was provided" + ); + } + // Default handling $element = parent::render($inline, $htmlRenderer); $url = $inline->getUrl(); diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index d159e10..779220a 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -31,6 +31,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->converter = new CommonMarkConverter(['daux' => $this->daux->getParams()]); } + /** + * {@inheritdoc} + */ public function generateAll(InputInterface $input, OutputInterface $output, $width) { $params = $this->daux->getParams(); diff --git a/libs/Format/Confluence/Publisher.php b/libs/Format/Confluence/Publisher.php index 03e63df..8da36ce 100644 --- a/libs/Format/Confluence/Publisher.php +++ b/libs/Format/Confluence/Publisher.php @@ -25,7 +25,7 @@ class Publisher protected $previous_title; /** - * @var string terminal width + * @var integer terminal width */ public $width; diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 9be5276..de00af6 100644 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -39,14 +39,14 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator $params = $this->daux->getParams(); if (is_null($destination)) { - $destination = $this->daux->local_base . DS . 'static'; + $destination = $this->daux->local_base . DIRECTORY_SEPARATOR . 'static'; } $this->runAction( "Copying Static assets ...", $output, $width, - function () use ($destination) { + function() use ($destination) { Helper::copyAssets($destination, $this->daux->local_base); } ); @@ -76,7 +76,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator foreach ($tree->getEntries() as $key => $node) { if ($node instanceof Directory) { - $new_output_dir = $output_dir . DS . $key; + $new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key; mkdir($new_output_dir); $this->generateRecursive($node, $new_output_dir, $params, $output, $width, '../' . $base_url); @@ -87,14 +87,14 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator "- " . $node->getUrl(), $output, $width, - function () use ($node, $output_dir, $key, $params) { + function() use ($node, $output_dir, $key, $params) { if (!$node instanceof Content) { - copy($node->getPath(), $output_dir . DS . $key); + copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key); return; } $generated = $this->generateOne($node, $params); - file_put_contents($output_dir . DS . $key, $generated->getContent()); + file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent()); } ); } diff --git a/libs/Generator/Command.php b/libs/Generator/Command.php index 312df2c..620f0c1 100644 --- a/libs/Generator/Command.php +++ b/libs/Generator/Command.php @@ -5,8 +5,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Todaymade\Daux\Daux; -use Todaymade\Daux\Format\HTML\Generator as HTMLGenerator; -use Todaymade\Daux\Format\Confluence\Generator as ConfluenceGenerator; class Command extends SymfonyCommand { @@ -53,7 +51,7 @@ class Command extends SymfonyCommand } $class = $daux->getProcessorClass(); - if ($class) { + if (!empty($class)) { $daux->setProcessor(new $class($daux, $output, $width)); } } diff --git a/libs/Generator/Helper.php b/libs/Generator/Helper.php index 167dead..48f50d6 100644 --- a/libs/Generator/Helper.php +++ b/libs/Generator/Helper.php @@ -16,8 +16,11 @@ class Helper mkdir($path); } - mkdir($path . DS . 'resources'); - static::copyRecursive($local_base . DS . 'resources', $path . DS . 'resources'); + mkdir($path . DIRECTORY_SEPARATOR . 'resources'); + static::copyRecursive( + $local_base . DIRECTORY_SEPARATOR . 'resources', + $path . DIRECTORY_SEPARATOR . 'resources' + ); } /** diff --git a/libs/Server/Server.php b/libs/Server/Server.php index bf98728..f1ee380 100644 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -25,7 +25,7 @@ class Server $daux->initialize(); $class = $daux->getProcessorClass(); - if ($class) { + if (!empty($class)) { $daux->setProcessor(new $class($daux, new NullOutput(), 0)); } @@ -101,7 +101,7 @@ class Server * Handle an incoming request * * @param array $query - * @return \Todaymade\Daux\Tree\Entry + * @return \Todaymade\Daux\Format\Base\Page * @throws Exception * @throws NotFoundException */ @@ -120,7 +120,7 @@ class Server /** * @param string $request - * @return \Todaymade\Daux\Tree\Entry + * @return \Todaymade\Daux\Format\Base\Page * @throws NotFoundException */ private function getPage($request) diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 230264a..6d1e88d 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -27,7 +27,7 @@ class Builder continue; } - $path = $node->getPath() . DS . $file; + $path = $node->getPath() . DIRECTORY_SEPARATOR . $file; if (is_dir($path) && in_array($file, $ignore['folders'])) { continue; @@ -37,9 +37,9 @@ class Builder } if (is_dir($path)) { - $new = new Directory($node, static::getUriFromFilename(static::getFilename($path)), $path); + $new = new Directory($node, static::removeSortingInformations(static::getFilename($path)), $path); $new->setName(DauxHelper::pathinfo($path)['filename']); - $new->setTitle(static::getTitleFromFilename($new->getName())); + $new->setTitle(static::removeSortingInformations($new->getName(), ' ')); static::build($new, $ignore); } else { static::createContent($node, $path); @@ -61,14 +61,14 @@ class Builder $config = $parent->getConfig(); if (!in_array(pathinfo($path, PATHINFO_EXTENSION), $config['valid_content_extensions'])) { - $entry = new Raw($parent, static::getUriFromFilename(static::getFilename($path)), $path, filemtime($path)); - $entry->setTitle(static::getTitleFromFilename($name)); + $entry = new Raw($parent, static::removeSortingInformations(static::getFilename($path)), $path, filemtime($path)); + $entry->setTitle(static::removeSortingInformations($name, ' ')); $entry->setName($name); return $entry; } - $uri = static::getUriFromFilename($name); + $uri = static::removeSortingInformations($name); if ($config['mode'] === Daux::STATIC_MODE) { $uri .= '.html'; } @@ -82,7 +82,7 @@ class Builder $entry->setTitle($parent->getTitle()); } } else { - $entry->setTitle(static::getTitleFromFilename($name)); + $entry->setTitle(static::removeSortingInformations($name, ' ')); } $entry->setName($name); @@ -104,7 +104,7 @@ class Builder * @param string $filename * @return string */ - protected static function getTitleFromFilename($filename) + protected static function removeSortingInformations($filename, $separator = '_') { $filename = explode('_', $filename); if ($filename[0] == '' || is_numeric($filename[0])) { @@ -115,26 +115,7 @@ class Builder $filename[0] = substr($t, 1); } } - $filename = implode(' ', $filename); - return $filename; - } - - /** - * @param string $filename - * @return string - */ - protected static function getUriFromFilename($filename) - { - $filename = explode('_', $filename); - if ($filename[0] == '' || is_numeric($filename[0])) { - unset($filename[0]); - } else { - $t = $filename[0]; - if ($t[0] == '-') { - $filename[0] = substr($t, 1); - } - } - $filename = implode('_', $filename); + $filename = implode($separator, $filename); return $filename; } diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index 1e1851c..a994b79 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -58,7 +58,7 @@ class Directory extends Entry } /** - * @return Content|false + * @return Content|null */ public function getFirstPage() { @@ -87,7 +87,7 @@ class Directory extends Entry } } - return false; + return null; } /** diff --git a/templates/content.php b/templates/content.php index 585b92a..525165c 100644 --- a/templates/content.php +++ b/templates/content.php @@ -3,27 +3,33 @@ - + diff --git a/templates/error.php b/templates/error.php index 67d16a4..b56c671 100644 --- a/templates/error.php +++ b/templates/error.php @@ -2,8 +2,8 @@
- +
diff --git a/templates/home.php b/templates/home.php index 3975562..a2ffff9 100644 --- a/templates/home.php +++ b/templates/home.php @@ -5,19 +5,23 @@ - Fork me on GitHub + Fork me on GitHub
- ' . $params['tagline'] . ''; ?> + ' . $params['tagline'] . ''; + } ?>
- '; ?> + '; + } ?>
@@ -28,8 +32,12 @@
View On GitHub'; - foreach ($page['entry_page'] as $key => $node) echo '' . $key . ''; + if ($params['html']['repo']) { + echo 'View On GitHub'; + } + foreach ($page['entry_page'] as $key => $node) { + echo '' . $key . ''; + } ?>
@@ -40,7 +48,7 @@
- +
@@ -52,7 +60,9 @@
@@ -60,10 +70,10 @@
- <?php echo $page['title']; ?> - - + <?= $page['title']; ?> + + - + - "; ?> + "; + } ?> - "; ?> + "; + } ?> '; - if ($params['theme']['bootstrap-js']) echo ''; + if ($params['theme']['require-jquery']) { + echo ''; + } + if ($params['theme']['bootstrap-js']) { + echo ''; + } ?> - + - '; ?> + '; + } ?> - + diff --git a/templates/layout/05_page.php b/templates/layout/05_page.php index b34b276..bae70d7 100644 --- a/templates/layout/05_page.php +++ b/templates/layout/05_page.php @@ -1,7 +1,7 @@ layout('theme::layout/00_layout') ?> - Fork me on GitHub + Fork me on GitHub
-
+
section('content'); ?>
diff --git a/templates/partials/navbar_content.php b/templates/partials/navbar_content.php index 7932a42..9017004 100644 --- a/templates/partials/navbar_content.php +++ b/templates/partials/navbar_content.php @@ -1,2 +1,2 @@ - +