updated scss library, automatic scss detection (filename) when including it in css minification

This commit is contained in:
Ulf Gebhardt 2019-08-21 18:05:08 +02:00
parent 895eeb8bba
commit 663844eb1b
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
3 changed files with 14 additions and 82 deletions

31
cache/cache_css.php vendored
View File

@ -53,23 +53,6 @@ class cache_css {
return sha1($ident);
}
/**
* Calculate URL for a list of Files
*
* @param array $files List of Files to be cached into one Cacheentry
* @return url Returns the requested Cache-URL
*/
/*public static function url($files){
$ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_css::get($ident)){
\LIB\lib_minify::php();
$minifier = new \MatthiasMullie\Minify\CSS();
foreach($files as $f){
$minifier->add($f->SERVERPATH());}
\SYSTEM\CACHE\cache_css::put($ident, $minifier->minify());}
return './api.php?call=cache&id='.self::CACHE_CSS.'&ident='.$ident;
}*/
/**
* Minify CSS and calculate URL from it
*
@ -80,9 +63,21 @@ class cache_css {
$ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_css::get($ident)){
\LIB\lib_minify::php();
\LIB\lib_scssphp::php();
$minifier = new \MatthiasMullie\Minify\CSS();
$sccs = new \Leafo\ScssPhp\Compiler();
foreach($files as $f){
$minifier->add($f->SERVERPATH());}
// Determin CSS/SCSS based on file extension
$path = $f->SERVERPATH();
$tmp = explode(".", $path); //rediculus
if(strtolower(end($tmp)) == 'scss'){
// Compile SCSS
$minifier->add($sccs->compile(file_get_contents($path)));
} else {
// Normal CSS
$minifier->add($path);
}
}
\SYSTEM\CACHE\cache_css::put($ident, $minifier->minify());}
return './cache/'.self::CACHE_CSS.'/'.$ident;
}

63
cache/cache_scss.php vendored
View File

@ -1,63 +0,0 @@
<?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\CACHE
*/
namespace SYSTEM\CACHE;
/**
* SCSS Cache Class provided by System for compiling and caching SCSS in the Database.
*/
class cache_scss {
/** int Cache ID for SCSS cache */
const CACHE_SCSS = 1;
/**
* Put Data into the Cache
*
* @param sha1 $file Filepath of the Content
* @param int $data Data to cache
* @return mixed Returns the cached Cache Content or NULL
*/
public static function put($file,$data){
return \SYSTEM\CACHE\cache::put(self::CACHE_SCSS, self::ident($file), 'CSS', $data);}
/**
* Get Data from Cache
*
* @param sha1 $file Filepath for the cached Content
* @param bool $header Send Header
* @return mixed Returns the requested Cache Content or NULL
*/
public static function get($file,$header = false){
return \SYSTEM\CACHE\cache::get(self::CACHE_SCSS, self::ident($file),$header);}
/**
* Calculate Ident for a File
*
* @param string $file Filepath to be cached
* @return sha1 Returns the requested Ident
*/
public static function ident($file){
if(!file_exists($file)){
throw new \SYSTEM\LOG\ERROR('Could not find file: '.$file);}
return sha1($file.';'.filemtime($file));}
/**
* Calculate URL for a File
*
* @param array $file Filepath to be cached
* @return url Returns the requested Cache-URL
*/
public static function url($file){
if(!\SYSTEM\CACHE\cache_scss::get($file->SERVERPATH())){
\LIB\lib_scssphp::php();
\SYSTEM\CACHE\cache_scss::put($file->SERVERPATH(), (new \Leafo\ScssPhp\Compiler())->compile(file_get_contents($file->SERVERPATH())));}
return './api.php?call=cache&id='.self::CACHE_SCSS.'&ident='.self::ident($file->SERVERPATH());
}
}

@ -1 +1 @@
Subproject commit 96f83be5b4d3ac5ad61fa25a08088d4eb8605b7f
Subproject commit a83e62e27e088a141c49544390398722e120d3c7