More refactoring
This commit is contained in:
parent
f281169871
commit
c0016c759a
113
libs/Daux.php
113
libs/Daux.php
@ -15,9 +15,6 @@ class Daux
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
public $local_base;
|
public $local_base;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public $internal_base;
|
|
||||||
|
|
||||||
/** @var \Todaymade\Daux\Format\Base\Generator */
|
/** @var \Todaymade\Daux\Format\Base\Generator */
|
||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
@ -51,14 +48,7 @@ class Daux
|
|||||||
{
|
{
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
|
|
||||||
$this->local_base = $this->internal_base = dirname(__DIR__);
|
$this->local_base = dirname(__DIR__);
|
||||||
|
|
||||||
// In case we're inside the phar archive
|
|
||||||
// we save the path to the directory
|
|
||||||
// in which it is contained
|
|
||||||
if (defined('PHAR_DIR')) {
|
|
||||||
$this->local_base = PHAR_DIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// global.json
|
// global.json
|
||||||
$this->loadBaseConfiguration();
|
$this->loadBaseConfiguration();
|
||||||
@ -101,81 +91,48 @@ class Daux
|
|||||||
/**
|
/**
|
||||||
* Get the file requested for configuration overrides
|
* Get the file requested for configuration overrides
|
||||||
*
|
*
|
||||||
* @param string|null $override_file
|
* @param string|null $path
|
||||||
* @return string|null the path to a file to load for configuration overrides
|
* @return string|null the path to a file to load for configuration overrides
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getConfigurationOverride($override_file)
|
public function getConfigurationOverride($path)
|
||||||
{
|
{
|
||||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
$validPath = DauxHelper::findLocation($path, $this->local_base, 'DAUX_CONFIGURATION', 'file');
|
||||||
$env = getenv('DAUX_CONFIGURATION');
|
|
||||||
if ($env && file_exists($env)) {
|
|
||||||
return $env;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($override_file == null) {
|
if ($validPath === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($override_file)) {
|
if (!$validPath) {
|
||||||
if (DauxHelper::isAbsolutePath($override_file)) {
|
throw new Exception('The configuration override file does not exist. Check the path again : ' . $path);
|
||||||
return $override_file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getcwd() . '/' . $override_file;
|
return $validPath;
|
||||||
}
|
|
||||||
|
|
||||||
$newPath = $this->local_base . DIRECTORY_SEPARATOR . $override_file;
|
|
||||||
if (file_exists($newPath)) {
|
|
||||||
return $newPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception('The configuration override file does not exist. Check the path again : ' . $override_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function normalizeThemePath($path)
|
public function normalizeThemePath($path)
|
||||||
{
|
{
|
||||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
$validPath = DauxHelper::findLocation($path, $this->local_base, 'DAUX_THEME', 'dir');
|
||||||
$env = getenv('DAUX_THEME');
|
|
||||||
if ($env && is_dir($env)) {
|
|
||||||
return $env;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir($path)) {
|
|
||||||
if (DauxHelper::isAbsolutePath($path)) {
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getcwd() . '/' . $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newPath = $this->local_base . DIRECTORY_SEPARATOR . $path;
|
|
||||||
if (is_dir($newPath)) {
|
|
||||||
return $newPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!$validPath) {
|
||||||
throw new Exception('The Themes directory does not exist. Check the path again : ' . $path);
|
throw new Exception('The Themes directory does not exist. Check the path again : ' . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $validPath;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function normalizeDocumentationPath($path)
|
public function normalizeDocumentationPath($path)
|
||||||
{
|
{
|
||||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
$validPath = DauxHelper::findLocation($path, $this->local_base, 'DAUX_SOURCE', 'dir');
|
||||||
$env = getenv('DAUX_SOURCE');
|
|
||||||
if ($env && is_dir($env)) {
|
|
||||||
return $env;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir($path)) {
|
|
||||||
if (DauxHelper::isAbsolutePath($path)) {
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getcwd() . '/' . $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!$validPath) {
|
||||||
throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
|
throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $validPath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load and validate the global configuration
|
* Load and validate the global configuration
|
||||||
*
|
*
|
||||||
@ -247,37 +204,9 @@ class Daux
|
|||||||
$this->getProcessor()->manipulateTree($this->tree);
|
$this->getProcessor()->manipulateTree($this->tree);
|
||||||
|
|
||||||
// Sort the tree one last time before it is finalized
|
// Sort the tree one last time before it is finalized
|
||||||
$this->sortTree($this->tree);
|
Builder::sortTree($this->tree);
|
||||||
|
|
||||||
$this->finalizeTree($this->tree);
|
Builder::finalizeTree($this->tree);
|
||||||
}
|
|
||||||
|
|
||||||
public function sortTree(Directory $current)
|
|
||||||
{
|
|
||||||
$current->sort();
|
|
||||||
foreach ($current->getEntries() as $entry) {
|
|
||||||
if ($entry instanceof Directory) {
|
|
||||||
$this->sortTree($entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function finalizeTree(Directory $current, $prev = null)
|
|
||||||
{
|
|
||||||
foreach ($current->getEntries() as $entry) {
|
|
||||||
if ($entry instanceof Directory) {
|
|
||||||
$prev = $this->finalizeTree($entry, $prev);
|
|
||||||
} elseif ($entry instanceof Content) {
|
|
||||||
if ($prev) {
|
|
||||||
$prev->setNext($entry);
|
|
||||||
$entry->setPrevious($prev);
|
|
||||||
}
|
|
||||||
|
|
||||||
$prev = $entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $prev;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -468,4 +468,42 @@ class DauxHelper
|
|||||||
|
|
||||||
return '' !== $parts['root'];
|
return '' !== $parts['root'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $path
|
||||||
|
* @param $basedir
|
||||||
|
* @param $var
|
||||||
|
* @param $type
|
||||||
|
* @return false|null|string
|
||||||
|
*/
|
||||||
|
public static function findLocation($path, $basedir, $var, $type) {
|
||||||
|
// When running through `daux --serve` we set an environment variable to know where we started from
|
||||||
|
$env = getenv($var);
|
||||||
|
if ($env && DauxHelper::is($env, $type)) {
|
||||||
|
return $env;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($path == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DauxHelper::is($path, $type)) {
|
||||||
|
if (DauxHelper::isAbsolutePath($path)) {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getcwd() . '/' . $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newPath = $basedir . DIRECTORY_SEPARATOR . $path;
|
||||||
|
if (DauxHelper::is($newPath, $type)) {
|
||||||
|
return $newPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function is($path, $type) {
|
||||||
|
return ($type == 'dir') ? is_dir($path) : file_exists($path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class Publisher
|
|||||||
public $width;
|
public $width;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\Console\Output\Output
|
* @var \Symfony\Component\Console\Output\OutputInterface
|
||||||
*/
|
*/
|
||||||
public $output;
|
public $output;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
class PublisherDelete
|
class PublisherDelete
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\Console\Output\Output
|
* @var \Symfony\Component\Console\Output\OutputInterface
|
||||||
*/
|
*/
|
||||||
public $output;
|
public $output;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class Processor
|
|||||||
*
|
*
|
||||||
* @param Root $root
|
* @param Root $root
|
||||||
*/
|
*/
|
||||||
public function manipulateTree(Root $root)
|
public function manipulateTree(/** @scrutinizer ignore-unused */ Root $root)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class Processor
|
|||||||
*
|
*
|
||||||
* @param Environment $environment
|
* @param Environment $environment
|
||||||
*/
|
*/
|
||||||
public function extendCommonMarkEnvironment(Environment $environment)
|
public function extendCommonMarkEnvironment(/** @scrutinizer ignore-unused */ Environment $environment)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,4 +203,44 @@ class Builder
|
|||||||
|
|
||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the tree recursively
|
||||||
|
*
|
||||||
|
* @param Directory $current
|
||||||
|
*/
|
||||||
|
public static function sortTree(Directory $current) {
|
||||||
|
$current->sort();
|
||||||
|
foreach ($current->getEntries() as $entry) {
|
||||||
|
if ($entry instanceof Directory) {
|
||||||
|
Builder::sortTree($entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate next and previous for all pages
|
||||||
|
*
|
||||||
|
* @param Directory $current
|
||||||
|
* @param null|Content $prev
|
||||||
|
* @return null|Content
|
||||||
|
*/
|
||||||
|
public static function finalizeTree(Directory $current, $prev = null)
|
||||||
|
{
|
||||||
|
foreach ($current->getEntries() as $entry) {
|
||||||
|
if ($entry instanceof Directory) {
|
||||||
|
$prev = Builder::finalizeTree($entry, $prev);
|
||||||
|
} elseif ($entry instanceof Content) {
|
||||||
|
if ($prev) {
|
||||||
|
$prev->setNext($entry);
|
||||||
|
$entry->setPrevious($prev);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prev = $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $prev;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user