Commit 7a276764 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(themes): add ViewThemes library to set views in root themes folder

app, admin, install and authentication views are now located in root themes/ folder
parent 58c88399
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@

declare(strict_types=1);

use App\Libraries\View;
use ViewThemes\Theme;

/**
 * The goal of this file is to allow developers a location where they can overwrite core procedural functions and
 * replace them with their own. This file is loaded during the bootstrap process and is called during the frameworks
@@ -12,3 +15,32 @@ declare(strict_types=1);
 *
 * @link: https://codeigniter4.github.io/CodeIgniter4/
 */

if (! function_exists('view')) {
    /**
     * Grabs the current RendererInterface-compatible class and tells it to render the specified view. Simply provides a
     * convenience method that can be used in Controllers, libraries, and routed closures.
     *
     * NOTE: Does not provide any escaping of the data, so that must all be handled manually by the developer.
     *
     * @param array<string, mixed>  $data
     * @param array<string, mixed>  $options Unused - reserved for third-party extensions.
     */
    function view(string $name, array $data = [], array $options = []): string
    {
        $path = Theme::path();

        /** @var CodeIgniter\View\View $renderer */
        $renderer = single_service('renderer', $path);

        $saveData = config(View::class)->saveData;

        if (array_key_exists('saveData', $options)) {
            $saveData = (bool) $options['saveData'];
            unset($options['saveData']);
        }

        return $renderer->setData($data, 'raw')
            ->render($name, $options, $saveData);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ class Autoload extends AutoloadConfig
        'Modules\Fediverse' => ROOTPATH . 'modules/Fediverse/',
        'Config' => APPPATH . 'Config/',
        'ViewComponents' => APPPATH . 'Libraries/ViewComponents/',
        'ViewThemes' => APPPATH . 'Libraries/ViewThemes/',
        'Themes' => ROOTPATH . 'themes',
    ];

    /**
+6 −8
Original line number Diff line number Diff line
@@ -9,14 +9,12 @@ use ViewComponents\Config\ViewComponents as ViewComponentsConfig;
class ViewComponents extends ViewComponentsConfig
{
    /**
     * @var array<string, string>
     * @var string[]
     */
    public array $lookupModules = [
        APP_NAMESPACE => APPPATH,
        'Modules\Admin' => ROOTPATH . 'modules/Admin/',
        'Modules\Auth' => ROOTPATH . 'modules/Auth/',
        'Modules\Analytics' => ROOTPATH . 'modules/Analytics/',
        'Modules\Install' => ROOTPATH . 'modules/Install/',
        'Modules\Fediverse' => ROOTPATH . 'modules/Fediverse/',
    public array $lookupPaths = [
        ROOTPATH . 'themes/cp_app/',
        ROOTPATH . 'themes/cp_admin/',
        ROOTPATH . 'themes/cp_auth/',
        ROOTPATH . 'themes/cp_install/',
    ];
}
+5 −8
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use CodeIgniter\Controller;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use ViewThemes\Theme;

/**
 * Class BaseController
@@ -19,14 +20,6 @@ use Psr\Log\LoggerInterface;
 */
class BaseController extends Controller
{
    /**
     * An array of helpers to be loaded automatically upon class instantiation. These helpers will be available to all
     * other controllers that extend BaseController.
     *
     * @var string[]
     */
    protected $helpers = ['auth', 'svg', 'components', 'misc'];

    /**
     * Constructor.
     */
@@ -35,7 +28,11 @@ class BaseController extends Controller
        ResponseInterface $response,
        LoggerInterface $logger
    ): void {
        $this->helpers = array_merge($this->helpers, ['auth', 'svg', 'components', 'misc']);

        // Do Not Edit This Line
        parent::initController($request, $response, $logger);

        Theme::setTheme('app');
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class HomeController extends BaseController
        $data = [
            'podcasts' => $allPodcasts,
        ];

        return view('home', $data);
    }
}
Loading