mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Add SCSS support
This commit is contained in:
parent
0acad2066f
commit
f6e73e327e
3 changed files with 103 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Themes;
|
namespace openvk\Web\Themes;
|
||||||
|
use ScssPhp\ScssPhp\Compiler as CSSCompiler;
|
||||||
|
use ScssPhp\ScssPhp\OutputStyle;
|
||||||
|
|
||||||
class Themepack
|
class Themepack
|
||||||
{
|
{
|
||||||
|
@ -11,6 +13,11 @@ class Themepack
|
||||||
private $home;
|
private $home;
|
||||||
private $enabled;
|
private $enabled;
|
||||||
|
|
||||||
|
private $cssExtensions = [
|
||||||
|
"css",
|
||||||
|
"scss",
|
||||||
|
];
|
||||||
|
|
||||||
function __construct(string $id, string $ver, bool $inh, bool $tpl, bool $enabled, object $meta)
|
function __construct(string $id, string $ver, bool $inh, bool $tpl, bool $enabled, object $meta)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
@ -72,16 +79,31 @@ class Themepack
|
||||||
return $this->tpl;
|
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
|
function fetchStyleSheet(): ?string
|
||||||
{
|
{
|
||||||
$file = "$this->home/stylesheet.css";
|
return $this->fetchResource("stylesheet.scss", true) ?? $this->fetchResource("stylesheet.css", true);
|
||||||
return file_exists($file) ? file_get_contents($file) : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchStaticResource(string $name): ?string
|
function fetchStaticResource(string $name): ?string
|
||||||
{
|
{
|
||||||
$file = "$this->home/res/$name";
|
return $this->fetchResource("res/$name");
|
||||||
return file_exists($file) ? file_get_contents($file) : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function themepackFromDir(string $dirname): Themepack
|
static function themepackFromDir(string $dirname): Themepack
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
"wapmorgan/binary-stream": "dev-master",
|
"wapmorgan/binary-stream": "dev-master",
|
||||||
"netcarver/textile": "^3.7@dev",
|
"netcarver/textile": "^3.7@dev",
|
||||||
"al/emoji-detector": "dev-master",
|
"al/emoji-detector": "dev-master",
|
||||||
"ezyang/htmlpurifier": "dev-master"
|
"ezyang/htmlpurifier": "dev-master",
|
||||||
|
"scssphp/scssphp": "dev-master"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev"
|
"minimum-stability": "dev"
|
||||||
}
|
}
|
||||||
|
|
78
composer.lock
generated
78
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "6188ae124a67b6cf9d5283904dadc141",
|
"content-hash": "4d1d3d279e0f7adca1e7035ddd41797b",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "al/emoji-detector",
|
"name": "al/emoji-detector",
|
||||||
|
@ -730,6 +730,77 @@
|
||||||
],
|
],
|
||||||
"time": "2020-05-02T23:50:29+00:00"
|
"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",
|
"name": "symfony/polyfill-intl-idn",
|
||||||
"version": "dev-master",
|
"version": "dev-master",
|
||||||
|
@ -1206,11 +1277,12 @@
|
||||||
"wapmorgan/binary-stream": 20,
|
"wapmorgan/binary-stream": 20,
|
||||||
"netcarver/textile": 20,
|
"netcarver/textile": 20,
|
||||||
"al/emoji-detector": 20,
|
"al/emoji-detector": 20,
|
||||||
"ezyang/htmlpurifier": 20
|
"ezyang/htmlpurifier": 20,
|
||||||
|
"scssphp/scssphp": 20
|
||||||
},
|
},
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": [],
|
"platform": [],
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.0.0"
|
"plugin-api-version": "2.1.0"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue