From f6e73e327e311c9a9c57ad9438b694d9337fdb4d Mon Sep 17 00:00:00 2001 From: Celestora Date: Thu, 16 Sep 2021 21:29:50 +0300 Subject: [PATCH] Add SCSS support --- Web/Themes/Themepack.php | 30 +++++++++++++--- composer.json | 3 +- composer.lock | 78 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 8 deletions(-) diff --git a/Web/Themes/Themepack.php b/Web/Themes/Themepack.php index b7718c2b..21de3973 100644 --- a/Web/Themes/Themepack.php +++ b/Web/Themes/Themepack.php @@ -1,5 +1,7 @@ id = $id; @@ -72,16 +79,31 @@ class Themepack return $this->tpl; } + function fetchResource(string $resource, bool $processCSS = false): ?string + { + $file = "$this->home/$resource"; + if(!file_exists($file)) + return NULL; + + $result = file_get_contents($file); + if(in_array(@end(explode(".", $resource)), $this->cssExtensions) && $processCSS) { + $compiler = new CSSCompiler([ "cacheDir" => OPENVK_ROOT . "/tmp" ]); + $compiler->setOutputStyle(OutputStyle::COMPRESSED); + + $result = $compiler->compileString($result, $file)->getCSS(); + } + + return $result; + } + function fetchStyleSheet(): ?string { - $file = "$this->home/stylesheet.css"; - return file_exists($file) ? file_get_contents($file) : NULL; + return $this->fetchResource("stylesheet.scss", true) ?? $this->fetchResource("stylesheet.css", true); } function fetchStaticResource(string $name): ?string { - $file = "$this->home/res/$name"; - return file_exists($file) ? file_get_contents($file) : NULL; + return $this->fetchResource("res/$name"); } static function themepackFromDir(string $dirname): Themepack diff --git a/composer.json b/composer.json index 8ef929af..345550c2 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "wapmorgan/binary-stream": "dev-master", "netcarver/textile": "^3.7@dev", "al/emoji-detector": "dev-master", - "ezyang/htmlpurifier": "dev-master" + "ezyang/htmlpurifier": "dev-master", + "scssphp/scssphp": "dev-master" }, "minimum-stability": "dev" } diff --git a/composer.lock b/composer.lock index 78758e20..3d130755 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6188ae124a67b6cf9d5283904dadc141", + "content-hash": "4d1d3d279e0f7adca1e7035ddd41797b", "packages": [ { "name": "al/emoji-detector", @@ -730,6 +730,77 @@ ], "time": "2020-05-02T23:50:29+00:00" }, + { + "name": "scssphp/scssphp", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/scssphp/scssphp.git", + "reference": "ef764826670a6a56161eee63996101b0ad9eecfc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/scssphp/scssphp/zipball/ef764826670a6a56161eee63996101b0ad9eecfc", + "reference": "ef764826670a6a56161eee63996101b0ad9eecfc", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "php": ">=7.2" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4", + "phpunit/phpunit": "^8.5 || ^9.5", + "sass/sass-spec": "*", + "squizlabs/php_codesniffer": "~3.5", + "symfony/phpunit-bridge": "^5.1", + "twbs/bootstrap": "~5.0", + "twbs/bootstrap4": "4.6.0", + "zurb/foundation": "~6.5" + }, + "suggest": { + "ext-iconv": "Can be used as fallback when ext-mbstring is not available", + "ext-mbstring": "For best performance, mbstring should be installed as it is faster than ext-iconv" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "ScssPhp\\ScssPhp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthon Pang", + "email": "apang@softwaredevelopment.ca", + "homepage": "https://github.com/robocoder" + }, + { + "name": "Cédric Morin", + "email": "cedric@yterium.com", + "homepage": "https://github.com/Cerdic" + } + ], + "description": "scssphp is a compiler for SCSS written in PHP.", + "homepage": "http://scssphp.github.io/scssphp/", + "keywords": [ + "css", + "less", + "sass", + "scss", + "stylesheet" + ], + "support": { + "issues": "https://github.com/scssphp/scssphp/issues", + "source": "https://github.com/scssphp/scssphp/tree/master" + }, + "time": "2021-09-15T23:25:40+00:00" + }, { "name": "symfony/polyfill-intl-idn", "version": "dev-master", @@ -1206,11 +1277,12 @@ "wapmorgan/binary-stream": 20, "netcarver/textile": 20, "al/emoji-detector": 20, - "ezyang/htmlpurifier": 20 + "ezyang/htmlpurifier": 20, + "scssphp/scssphp": 20 }, "prefer-stable": false, "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" }