mirror of
https://github.com/getgrav/grav.git
synced 2026-07-05 16:49:18 +02:00
Add basic theme configuration support
This commit is contained in:
@@ -5,7 +5,6 @@ use Grav\Common\Service\StreamsServiceProvider;
|
||||
use Grav\Component\DI\Container;
|
||||
use Grav\Component\EventDispatcher\Event;
|
||||
use Grav\Component\EventDispatcher\EventDispatcher;
|
||||
use Grav\Component\Filesystem\ResourceLocator;
|
||||
|
||||
/**
|
||||
* Grav
|
||||
|
||||
@@ -61,6 +61,7 @@ class Plugins extends Iterator
|
||||
}
|
||||
|
||||
$instance = $this->grav['themes']->load();
|
||||
$instance->configure();
|
||||
if ($instance instanceof EventSubscriberInterface) {
|
||||
$events->addSubscriber($instance);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,61 @@
|
||||
<?php
|
||||
namespace Grav\Common;
|
||||
|
||||
use Grav\Common\Filesystem\File\Yaml;
|
||||
use Grav\Component\Filesystem\ResourceLocator;
|
||||
|
||||
class Theme extends Plugin
|
||||
{
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Grav $grav
|
||||
* @param Config $config
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(Grav $grav, Config $config, $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
parent::__construct($grav, $config);
|
||||
}
|
||||
|
||||
public function configure() {
|
||||
$themeConfig = Yaml::instance(THEMES_DIR . "{$this->name}/{$this->name}.yaml")->content();
|
||||
|
||||
$this->config->merge(['themes' => [$this->name => $themeConfig]]);
|
||||
|
||||
/** @var ResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
// TODO: move
|
||||
$registered = stream_get_wrappers();
|
||||
$schemes = $this->config->get("themes.{$this->name}.streams.scheme");
|
||||
|
||||
foreach ($schemes as $scheme => $config) {
|
||||
if (isset($config['paths'])) {
|
||||
$locator->addPath($scheme, '', $config['paths']);
|
||||
}
|
||||
if (isset($config['prefixes'])) {
|
||||
foreach ($config['prefixes'] as $prefix => $paths) {
|
||||
$locator->addPath($scheme, $prefix, $paths);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($scheme, $registered)) {
|
||||
stream_wrapper_unregister($scheme);
|
||||
}
|
||||
$type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream';
|
||||
if ($type[0] != '\\') {
|
||||
$type = '\\Grav\\Component\\Filesystem\\StreamWrapper\\' . $type;
|
||||
}
|
||||
|
||||
if (!stream_wrapper_register($scheme, $type)) {
|
||||
throw new \InvalidArgumentException("Stream '{$type}' could not be initialized.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,13 +101,13 @@ class Themes
|
||||
$className = '\\Grav\\Theme\\' . ucfirst($name);
|
||||
|
||||
if (class_exists($className)) {
|
||||
$class = new $className($this->grav, $config);
|
||||
$class = new $className($this->grav, $config, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($class)) {
|
||||
$class = new Theme($this->grav, $config);
|
||||
$class = new Theme($this->grav, $config, $name);
|
||||
}
|
||||
|
||||
return $class;
|
||||
|
||||
Reference in New Issue
Block a user