diff --git a/.gitignore b/.gitignore index 6f26b5e..0b4d763 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ +/app/dist/ +/node_modules/ /vendor/ .env .php_cs.cache .phpunit.result.cache +mix-manifest.json diff --git a/app/Bootstrap/FinderComposer.php b/app/Bootstrap/FinderComposer.php index dc1205f..0500b21 100644 --- a/app/Bootstrap/FinderComposer.php +++ b/app/Bootstrap/FinderComposer.php @@ -13,7 +13,7 @@ use Tightenco\Collect\Support\Collection; class FinderComposer { /** @const Application paths to be hidden */ - protected const APP_FILES = ['app', 'vendor', 'index.php']; + protected const APP_FILES = ['app', 'node_modules', 'vendor', 'index.php']; /** @var Config Application config */ protected $config; diff --git a/app/Bootstrap/ViewComposer.php b/app/Bootstrap/ViewComposer.php index d85846c..28419c4 100644 --- a/app/Bootstrap/ViewComposer.php +++ b/app/Bootstrap/ViewComposer.php @@ -5,6 +5,7 @@ namespace App\Bootstrap; use DI\Container; use PHLAK\Config\Config; use Slim\Views\Twig; +use Symfony\Component\Finder\SplFileInfo; use Twig\Extension\CoreExtension; use Twig\TwigFunction; @@ -35,34 +36,33 @@ class ViewComposer */ public function __invoke(): void { - $twig = new Twig("app/themes/{$this->config->get('app.theme', 'default')}"); + $twig = new Twig('app/resources/views'); $twig->getEnvironment()->setCache( - $this->config->get('cache.view_cache', 'app/cache/views') + $this->config->get('view.cache', 'app/cache/views') ); $twig->getEnvironment()->getExtension(CoreExtension::class)->setDateFormat( $this->config->get('app.date_format', 'Y-m-d H:i:s'), '%d days' ); - $this->registerGlobalFunctions($twig); - $this->registerThemeFunctions($twig); + $this->registerFunctions($twig); $this->container->set(Twig::class, $twig); } /** - * Register global Twig functions. + * Register Twig functions. * * @param \Slim\Views\Twig $twig * * @return void */ - protected function registerGlobalFunctions(Twig $twig): void + protected function registerFunctions(Twig $twig): void { $twig->getEnvironment()->addFunction( new TwigFunction('asset', function (string $path) use ($twig) { - return "/{$twig->getLoader()->getPaths()[0]}/{$path}"; + return "/app/dist/{$path}"; }) ); @@ -74,25 +74,24 @@ class ViewComposer return sprintf('%.2f', $bytes / pow(1024, $factor)) . $sizes[$factor]; }) ); - } - /** - * Register theme specific Twig functions. - * - * @param \Slim\Views\Twig $twig - * - * @return void - */ - protected function registerThemeFunctions(Twig $twig): void - { - $themeFunctionsFile = "{$twig->getLoader()->getPaths()[0]}/functions.php"; + $twig->getEnvironment()->addFunction( + new TwigFunction('icon', function (SplFileInfo $file) { + $iconConfig = $this->config->split('icons'); - if (file_exists($themeFunctionsFile)) { - $themeConfig = include $themeFunctionsFile; - } + $icon = $file->isDir() ? 'fas fa-folder' + : $iconConfig->get($file->getExtension(), 'fas fa-file'); - foreach ($themeConfig['functions'] ?? [] as $function) { - $twig->getEnvironment()->addFunction($function); - } + return ""; + }) + ); + + $twig->getEnvironment()->addFunction( + new TwigFunction('config', function (string $key, $default = null) { + $viewConfig = $this->config->split('view'); + + return $viewConfig->get($key, $default); + }) + ); } } diff --git a/app/config/app.php b/app/config/app.php index 7cb20fe..57c9111 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -18,14 +18,7 @@ return [ 'reverse_sort' => false, /** - * Name of the theme to use for styling the application. - * - * Default value: default - */ - 'theme' => 'default', - - /** - * Description here... + * Default date format. * * Default value: 'Y-m-d H:i:s' */ diff --git a/app/config/cache.php b/app/config/cache.php deleted file mode 100644 index eede807..0000000 --- a/app/config/cache.php +++ /dev/null @@ -1,10 +0,0 @@ - env('VIEW_CACHE', 'app/cache/views'), -]; diff --git a/app/themes/default/icons.php b/app/config/icons.php similarity index 100% rename from app/themes/default/icons.php rename to app/config/icons.php diff --git a/app/config/view.php b/app/config/view.php new file mode 100644 index 0000000..96c20e4 --- /dev/null +++ b/app/config/view.php @@ -0,0 +1,17 @@ + env('DARK_MODE', false), + + /** + * Path to the view cache directory. + * + * Default value: 'app/cache/views' + */ + 'cache' => env('VIEW_CACHE', 'app/cache/views'), +]; diff --git a/app/themes/default/src/js/app.js b/app/resources/js/app.js similarity index 100% rename from app/themes/default/src/js/app.js rename to app/resources/js/app.js diff --git a/app/themes/default/src/js/components/file-info-modal.vue b/app/resources/js/components/file-info-modal.vue similarity index 100% rename from app/themes/default/src/js/components/file-info-modal.vue rename to app/resources/js/components/file-info-modal.vue diff --git a/app/themes/default/src/sass/app.scss b/app/resources/sass/app.scss similarity index 100% rename from app/themes/default/src/sass/app.scss rename to app/resources/sass/app.scss diff --git a/app/themes/default/src/sass/dark-mode.scss b/app/resources/sass/dark-mode.scss similarity index 100% rename from app/themes/default/src/sass/dark-mode.scss rename to app/resources/sass/dark-mode.scss diff --git a/app/themes/default/components/file.twig b/app/resources/views/components/file.twig similarity index 100% rename from app/themes/default/components/file.twig rename to app/resources/views/components/file.twig diff --git a/app/themes/default/index.twig b/app/resources/views/index.twig similarity index 94% rename from app/themes/default/index.twig rename to app/resources/views/index.twig index f6f9f19..5e936f4 100644 --- a/app/themes/default/index.twig +++ b/app/resources/views/index.twig @@ -2,8 +2,8 @@ - - + +