8
0
Fork 0

Allow for custom themes on `generate` with global installation, partly fixes #396

Dieser Commit ist enthalten in:
Stéphane Goetz 2016-09-06 23:11:32 +02:00
Ursprung c69e2ff59d
Commit 7ee564c667
5 geänderte Dateien mit 64 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -73,6 +73,14 @@ class Config extends ArrayObject
return $this['themes_directory'];
}
public function setThemesPath($themePath) {
$this['themes_path'] = $themePath;
}
public function getThemesPath() {
return $this['themes_path'];
}
public function setFormat($format)
{
$this['format'] = $format;
@ -83,6 +91,16 @@ class Config extends ArrayObject
return $this['format'];
}
public function hasTimezone()
{
return isset($this['timezone']);
}
public function getTimezone()
{
return $this['timezone'];
}
public function isMultilanguage()
{
return array_key_exists('languages', $this) && !empty($this['languages']);

Datei anzeigen

@ -70,8 +70,10 @@ class Daux
*/
public function initializeConfiguration($override_file = 'config.json')
{
$params = $this->getParams();
// Validate and set theme path
$this->getParams()->setDocumentationDirectory($docs_path = $this->normalizeDocumentationPath());
$params->setDocumentationDirectory($docs_path = $this->normalizeDocumentationPath());
// Read documentation overrides
$this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json');
@ -82,11 +84,12 @@ class Daux
}
// 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
if (isset($this->options['timezone'])) {
date_default_timezone_set($this->options['timezone']);
if ($params->hasTimezone()) {
date_default_timezone_set($params->getTimezone());
} elseif (!ini_get('date.timezone')) {
date_default_timezone_set('GMT');
}

Datei anzeigen

@ -30,7 +30,7 @@ class DauxHelper
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;
}
@ -44,7 +44,7 @@ class DauxHelper
$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");
}
}
@ -58,8 +58,8 @@ class DauxHelper
{
self::resolveVariant($params);
$theme_folder = $params['themes_path'] . DIRECTORY_SEPARATOR . $params['html']['theme'];
$theme_url = $params['base_url'] . $params->getThemesDirectory() . '/' . $params['html']['theme'] . '/';
$theme_folder = $params->getThemesPath() . DIRECTORY_SEPARATOR . $params['html']['theme'];
$theme_url = $params['base_url'] . 'themes/' . $params['html']['theme'] . '/';
$theme = [];
if (is_file($theme_folder . DIRECTORY_SEPARATOR . 'config.json')) {

Datei anzeigen

@ -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)
{
$destination = $input->getOption('destination');
@ -54,8 +77,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
'Copying Static assets ...',
$output,
$width,
function () use ($destination) {
GeneratorHelper::copyAssets($destination, $this->daux->local_base);
function () use ($destination, $params) {
$this->ensureEmptyDestination($destination);
$this->copyThemes($destination, $params->getThemesPath());
}
);

Datei anzeigen

@ -1,34 +1,15 @@
<?php namespace Todaymade\Daux;
use RuntimeException;
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
*
* @param string $dir
*/
protected static function rmdir($dir)
public static function rmdir($dir)
{
$it = new \RecursiveDirectoryIterator($dir);
$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
@ -57,6 +38,11 @@ class GeneratorHelper
}
$dir = opendir($source);
if (!$dir) {
throw new RuntimeException("Cannot copy '$source' to '$destination'");
}
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {