Allow for custom themes on generate
with global installation, partly fixes #396
This commit is contained in:
parent
c69e2ff59d
commit
7ee564c667
@ -73,6 +73,14 @@ class Config extends ArrayObject
|
|||||||
return $this['themes_directory'];
|
return $this['themes_directory'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setThemesPath($themePath) {
|
||||||
|
$this['themes_path'] = $themePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getThemesPath() {
|
||||||
|
return $this['themes_path'];
|
||||||
|
}
|
||||||
|
|
||||||
public function setFormat($format)
|
public function setFormat($format)
|
||||||
{
|
{
|
||||||
$this['format'] = $format;
|
$this['format'] = $format;
|
||||||
@ -83,6 +91,16 @@ class Config extends ArrayObject
|
|||||||
return $this['format'];
|
return $this['format'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasTimezone()
|
||||||
|
{
|
||||||
|
return isset($this['timezone']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTimezone()
|
||||||
|
{
|
||||||
|
return $this['timezone'];
|
||||||
|
}
|
||||||
|
|
||||||
public function isMultilanguage()
|
public function isMultilanguage()
|
||||||
{
|
{
|
||||||
return array_key_exists('languages', $this) && !empty($this['languages']);
|
return array_key_exists('languages', $this) && !empty($this['languages']);
|
||||||
|
@ -70,8 +70,10 @@ class Daux
|
|||||||
*/
|
*/
|
||||||
public function initializeConfiguration($override_file = 'config.json')
|
public function initializeConfiguration($override_file = 'config.json')
|
||||||
{
|
{
|
||||||
|
$params = $this->getParams();
|
||||||
|
|
||||||
// Validate and set theme path
|
// Validate and set theme path
|
||||||
$this->getParams()->setDocumentationDirectory($docs_path = $this->normalizeDocumentationPath());
|
$params->setDocumentationDirectory($docs_path = $this->normalizeDocumentationPath());
|
||||||
|
|
||||||
// Read documentation overrides
|
// Read documentation overrides
|
||||||
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
|
||||||
@ -82,11 +84,12 @@ class Daux
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate and set theme path
|
// Validate and set theme path
|
||||||
$this->options['themes_path'] = $this->normalizeThemePath($this->getParams()->getThemesDirectory());
|
$params->setThemesPath($this->normalizeThemePath($params->getThemesDirectory()));
|
||||||
|
|
||||||
|
|
||||||
// Set a valid default timezone
|
// Set a valid default timezone
|
||||||
if (isset($this->options['timezone'])) {
|
if ($params->hasTimezone()) {
|
||||||
date_default_timezone_set($this->options['timezone']);
|
date_default_timezone_set($params->getTimezone());
|
||||||
} elseif (!ini_get('date.timezone')) {
|
} elseif (!ini_get('date.timezone')) {
|
||||||
date_default_timezone_set('GMT');
|
date_default_timezone_set('GMT');
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class DauxHelper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir(realpath(($params['themes_path'] . DIRECTORY_SEPARATOR . $params['html']['theme'])))) {
|
if (is_dir(realpath(($params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'])))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class DauxHelper
|
|||||||
$params['html']['theme'] = array_pop($theme);
|
$params['html']['theme'] = array_pop($theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_dir(realpath(($params['themes_path'] . DIRECTORY_SEPARATOR . $params['html']['theme'])))) {
|
if (!is_dir(realpath(($params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'])))) {
|
||||||
throw new \RuntimeException("Theme '{$params['html']['theme']}' not found");
|
throw new \RuntimeException("Theme '{$params['html']['theme']}' not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ class DauxHelper
|
|||||||
{
|
{
|
||||||
self::resolveVariant($params);
|
self::resolveVariant($params);
|
||||||
|
|
||||||
$theme_folder = $params['themes_path'] . DIRECTORY_SEPARATOR . $params['html']['theme'];
|
$theme_folder = $params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'];
|
||||||
$theme_url = $params['base_url'] . $params->getThemesDirectory() . '/' . $params['html']['theme'] . '/';
|
$theme_url = $params['base_url'] . 'themes/' . $params['html']['theme'] . '/';
|
||||||
|
|
||||||
$theme = [];
|
$theme = [];
|
||||||
if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) {
|
if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) {
|
||||||
|
@ -41,6 +41,29 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function ensureEmptyDestination($destination) {
|
||||||
|
if (is_dir($destination)) {
|
||||||
|
GeneratorHelper::rmdir($destination);
|
||||||
|
} else {
|
||||||
|
mkdir($destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy all files from $local to $destination
|
||||||
|
*
|
||||||
|
* @param string $destination
|
||||||
|
* @param string $local_base
|
||||||
|
*/
|
||||||
|
protected function copyThemes($destination, $local_base)
|
||||||
|
{
|
||||||
|
mkdir($destination . DIRECTORY_SEPARATOR . 'themes');
|
||||||
|
GeneratorHelper::copyRecursive(
|
||||||
|
$local_base,
|
||||||
|
$destination . DIRECTORY_SEPARATOR . 'themes'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function generateAll(InputInterface $input, OutputInterface $output, $width)
|
public function generateAll(InputInterface $input, OutputInterface $output, $width)
|
||||||
{
|
{
|
||||||
$destination = $input->getOption('destination');
|
$destination = $input->getOption('destination');
|
||||||
@ -54,8 +77,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
|||||||
'Copying Static assets ...',
|
'Copying Static assets ...',
|
||||||
$output,
|
$output,
|
||||||
$width,
|
$width,
|
||||||
function () use ($destination) {
|
function () use ($destination, $params) {
|
||||||
GeneratorHelper::copyAssets($destination, $this->daux->local_base);
|
$this->ensureEmptyDestination($destination);
|
||||||
|
|
||||||
|
$this->copyThemes($destination, $params->getThemesPath());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,34 +1,15 @@
|
|||||||
<?php namespace Todaymade\Daux;
|
<?php namespace Todaymade\Daux;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
class GeneratorHelper
|
class GeneratorHelper
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Copy all files from $path to $local_base
|
|
||||||
*
|
|
||||||
* @param string $path
|
|
||||||
* @param string $local_base
|
|
||||||
*/
|
|
||||||
public static function copyAssets($path, $local_base)
|
|
||||||
{
|
|
||||||
if (is_dir($path)) {
|
|
||||||
static::rmdir($path);
|
|
||||||
} else {
|
|
||||||
mkdir($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdir($path . DIRECTORY_SEPARATOR . 'themes');
|
|
||||||
static::copyRecursive(
|
|
||||||
$local_base . DIRECTORY_SEPARATOR . 'themes',
|
|
||||||
$path . DIRECTORY_SEPARATOR . 'themes'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a directory recursively
|
* Remove a directory recursively
|
||||||
*
|
*
|
||||||
* @param string $dir
|
* @param string $dir
|
||||||
*/
|
*/
|
||||||
protected static function rmdir($dir)
|
public static function rmdir($dir)
|
||||||
{
|
{
|
||||||
$it = new \RecursiveDirectoryIterator($dir);
|
$it = new \RecursiveDirectoryIterator($dir);
|
||||||
$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
|
$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
@ -57,6 +38,11 @@ class GeneratorHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dir = opendir($source);
|
$dir = opendir($source);
|
||||||
|
|
||||||
|
if (!$dir) {
|
||||||
|
throw new RuntimeException("Cannot copy '$source' to '$destination'");
|
||||||
|
}
|
||||||
|
|
||||||
while (false !== ($file = readdir($dir))) {
|
while (false !== ($file = readdir($dir))) {
|
||||||
if ($file != '.' && $file != '..') {
|
if ($file != '.' && $file != '..') {
|
||||||
if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
|
if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user