Skip to content
Snippets Groups Projects
Commit 07d12146 authored by Tilman Vatteroth's avatar Tilman Vatteroth :robot:
Browse files

LessC durch PHPLess ersetzt.

Kompilieren von Less Dateien zu tmp CSS Dateien
anpassen von code
parent ee84af16
Branches
No related tags found
No related merge requests found
@viewport {
width: device-width;
user-zoom: fixed;
}
body {
margin: 0px;
background: #0a0a0a;
font-family: Arial;
overflow: hidden;
}
[data-container=panel] {
background-color: rgba(8, 8, 8, 0.68);
border: solid 1px #252525;
box-shadow: 0px 2px 1px #000000;
padding: 6px;
/* margin: 5px;*/
float: left;
box-sizing: border-box;
height: 100%;
width: 100%;
overflow: hidden;
}
[data-container=panelContainer] {
float: left;
width: 100%;
height: 100%;
/*padding: 4px;*/
padding: 0.2vw;
box-sizing: border-box;
}
[data-container=split] {
box-sizing: border-box;
/* display: flex;
flex-direction: column;*/
height: 100%;
width: 100%;
float: left;
}
[data-container=main] {
height: 100%;
width: 100%;
position: absolute;
box-sizing: border-box;
padding: 0.2vw;
background: radial-gradient(black 15%, transparent 15%) 0 0, radial-gradient(black 15%, transparent 15%) 12px 12px, radial-gradient(rgba(255, 255, 255, 0.1) 15%, transparent 20%) 0 1px, radial-gradient(rgba(255, 255, 255, 0.1) 15%, transparent 20%) 12px 13px;
background-size: 24px 24px;
background-color: #171717;
}
@font-face {
font-family: 'time';
font-style: normal;
font-weight: 400;
src: url(font/time.ttf) format('truetype');
}
@font-face {
font-family: 'vrr';
font-style: normal;
font-weight: 400;
src: url(font/vrr.ttf) format('truetype');
}
@font-face {
font-family: 'display';
font-style: normal;
font-weight: 400;
src: url(font/display.ttf) format('truetype');
}
@font-face {
font-family: 'newcicle';
font-style: normal;
font-weight: 400;
src: url(font/NewCicle.ttf) format('truetype');
}
@font-face {
font-family: 'Ubuntu Mono';
font-style: normal;
font-weight: 400;
src: local('Ubuntu Mono'), local('UbuntuMono-Regular'), url(ubuntumono.woff) format('woff');
}
@font-face {
font-family: 'LCD';
font-style: normal;
font-weight: 400;
src: url(font/lcd_clock.ttf) format('truetype');
}
@font-face {
font-family: 'time-medium';
font-style: normal;
font-weight: 400;
src: url(font/time-medium.ttf) format('truetype');
}
@font-face {
font-family: 'time-fat';
font-style: normal;
font-weight: 400;
src: url(font/time-fat.ttf) format('truetype');
}
@keyframes marquee {
from {transform:translateX(0%);}
to {transform:translateX(-20%);}
}
@-webkit-keyframes marquee {
from {transform:translateX(0%);}
to {transform:translateX(-20%);}
}
\ No newline at end of file
......@@ -5,9 +5,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="favicon.png" type="image/x-icon" rel="icon">
<link rel="stylesheet" href="css/font.css">
<link rel="stylesheet" href="css/design.css">
<link rel="stylesheet" href="css/marquee.css">
<link rel="stylesheet" href="css/font.less">
<link rel="stylesheet" href="style.php?type=design&name=design">
<link rel="stylesheet" href="style.php?type=design&name=marquee">
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/marquee.js"></script>
......@@ -21,7 +21,6 @@
WebFont.load( {
custom : {
families : ['time-medium', 'time-fat', 'vrr'],
urls : ['css/font.css']
},
active : function() {
window.fontsReady = true;
......
......@@ -99,7 +99,7 @@ layout.insertTemplate = function(name, panel) {
layout.error("get fail of template " + n );
});
$.get("style.php?style=" + n, function(k) {
$.get("style.php?name=" + n, function(k) {
console.log("get success of style " + n)
e.css=k;
doMore();
......
<?php
require_once( dirname(__FILE__).'/Version.php');
/**
* Utility for handling the generation and caching of css files
*
* @package Less
* @subpackage cache
*
*/
class Less_Cache{
// directory less.php can use for storing data
public static $cache_dir = false;
// prefix for the storing data
public static $prefix = 'lessphp_';
// prefix for the storing vars
public static $prefix_vars = 'lessphpvars_';
// specifies the number of seconds after which data created by less.php will be seen as 'garbage' and potentially cleaned up
public static $gc_lifetime = 604800;
/**
* Save and reuse the results of compiled less files.
* The first call to Get() will generate css and save it.
* Subsequent calls to Get() with the same arguments will return the same css filename
*
* @param array $less_files Array of .less files to compile
* @param array $parser_options Array of compiler options
* @param array $modify_vars Array of variables
* @return string Name of the css file
*/
public static function Get( $less_files, $parser_options = array(), $modify_vars = array() ){
//check $cache_dir
if( isset($parser_options['cache_dir']) ){
Less_Cache::$cache_dir = $parser_options['cache_dir'];
}
if( empty(Less_Cache::$cache_dir) ){
throw new Exception('cache_dir not set');
}
if( isset($parser_options['prefix']) ){
Less_Cache::$prefix = $parser_options['prefix'];
}
if( empty(Less_Cache::$prefix) ){
throw new Exception('prefix not set');
}
if( isset($parser_options['prefix_vars']) ){
Less_Cache::$prefix_vars = $parser_options['prefix_vars'];
}
if( empty(Less_Cache::$prefix_vars) ){
throw new Exception('prefix_vars not set');
}
self::CheckCacheDir();
$less_files = (array)$less_files;
//create a file for variables
if( !empty($modify_vars) ){
$lessvars = Less_Parser::serializeVars($modify_vars);
$vars_file = Less_Cache::$cache_dir . Less_Cache::$prefix_vars . sha1($lessvars) . '.less';
if( !file_exists($vars_file) ){
file_put_contents($vars_file, $lessvars);
}
$less_files += array($vars_file => '/');
}
// generate name for compiled css file
$hash = md5(json_encode($less_files));
$list_file = Less_Cache::$cache_dir . Less_Cache::$prefix . $hash . '.list';
// check cached content
if( !isset($parser_options['use_cache']) || $parser_options['use_cache'] === true ){
if( file_exists($list_file) ){
self::ListFiles($list_file, $list, $cached_name);
$compiled_name = self::CompiledName($list);
// if $cached_name is the same as the $compiled name, don't regenerate
if( !$cached_name || $cached_name === $compiled_name ){
$output_file = self::OutputFile($compiled_name, $parser_options );
if( $output_file && file_exists($output_file) ){
@touch($list_file);
return basename($output_file); // for backwards compatibility, we just return the name of the file
}
}
}
}
$compiled = self::Cache( $less_files, $parser_options );
if( !$compiled ){
return false;
}
$compiled_name = self::CompiledName( $less_files );
$output_file = self::OutputFile($compiled_name, $parser_options );
//save the file list
$list = $less_files;
$list[] = $compiled_name;
$cache = implode("\n",$list);
file_put_contents( $list_file, $cache );
//save the css
file_put_contents( $output_file, $compiled );
//clean up
self::CleanCache();
return basename($output_file);
}
/**
* Force the compiler to regenerate the cached css file
*
* @param array $less_files Array of .less files to compile
* @param array $parser_options Array of compiler options
* @param array $modify_vars Array of variables
* @return string Name of the css file
*/
public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ){
$parser_options['use_cache'] = false;
return self::Get( $less_files, $parser_options, $modify_vars );
}
public static function Cache( &$less_files, $parser_options = array() ){
// get less.php if it exists
$file = dirname(__FILE__) . '/Less.php';
if( file_exists($file) && !class_exists('Less_Parser') ){
require_once($file);
}
$parser_options['cache_dir'] = Less_Cache::$cache_dir;
$parser = new Less_Parser($parser_options);
// combine files
foreach($less_files as $file_path => $uri_or_less ){
//treat as less markup if there are newline characters
if( strpos($uri_or_less,"\n") !== false ){
$parser->Parse( $uri_or_less );
continue;
}
$parser->ParseFile( $file_path, $uri_or_less );
}
$compiled = $parser->getCss();
$less_files = $parser->allParsedFiles();
return $compiled;
}
private static function OutputFile( $compiled_name, $parser_options ){
//custom output file
if( !empty($parser_options['output']) ){
//relative to cache directory?
if( preg_match('#[\\\\/]#',$parser_options['output']) ){
return $parser_options['output'];
}
return Less_Cache::$cache_dir.$parser_options['output'];
}
return Less_Cache::$cache_dir.$compiled_name;
}
private static function CompiledName( $files ){
//save the file list
$temp = array(Less_Version::cache_version);
foreach($files as $file){
$temp[] = filemtime($file)."\t".filesize($file)."\t".$file;
}
return Less_Cache::$prefix.sha1(json_encode($temp)).'.css';
}
public static function SetCacheDir( $dir ){
Less_Cache::$cache_dir = $dir;
}
public static function CheckCacheDir(){
Less_Cache::$cache_dir = str_replace('\\','/',Less_Cache::$cache_dir);
Less_Cache::$cache_dir = rtrim(Less_Cache::$cache_dir,'/').'/';
if( !file_exists(Less_Cache::$cache_dir) ){
if( !mkdir(Less_Cache::$cache_dir) ){
throw new Less_Exception_Parser('Less.php cache directory couldn\'t be created: '.Less_Cache::$cache_dir);
}
}elseif( !is_dir(Less_Cache::$cache_dir) ){
throw new Less_Exception_Parser('Less.php cache directory doesn\'t exist: '.Less_Cache::$cache_dir);
}elseif( !is_writable(Less_Cache::$cache_dir) ){
throw new Less_Exception_Parser('Less.php cache directory isn\'t writable: '.Less_Cache::$cache_dir);
}
}
/**
* Delete unused less.php files
*
*/
public static function CleanCache(){
static $clean = false;
if( $clean ){
return;
}
$files = scandir(Less_Cache::$cache_dir);
if( $files ){
$check_time = time() - self::$gc_lifetime;
foreach($files as $file){
// don't delete if the file wasn't created with less.php
if( strpos($file,Less_Cache::$prefix) !== 0 ){
continue;
}
$full_path = Less_Cache::$cache_dir . $file;
// make sure the file still exists
// css files may have already been deleted
if( !file_exists($full_path) ){
continue;
}
$mtime = filemtime($full_path);
// don't delete if it's a relatively new file
if( $mtime > $check_time ){
continue;
}
$parts = explode('.',$file);
$type = array_pop($parts);
// delete css files based on the list files
if( $type === 'css' ){
continue;
}
// delete the list file and associated css file
if( $type === 'list' ){
self::ListFiles($full_path, $list, $css_file_name);
if( $css_file_name ){
$css_file = Less_Cache::$cache_dir . $css_file_name;
if( file_exists($css_file) ){
unlink($css_file);
}
}
}
unlink($full_path);
}
}
$clean = true;
}
/**
* Get the list of less files and generated css file from a list file
*
*/
static function ListFiles($list_file, &$list, &$css_file_name ){
$list = explode("\n",file_get_contents($list_file));
//pop the cached name that should match $compiled_name
$css_file_name = array_pop($list);
if( !preg_match('/^' . Less_Cache::$prefix . '[a-f0-9]+\.css$/',$css_file_name) ){
$list[] = $css_file_name;
$css_file_name = false;
}
}
}
This diff is collapsed.
<?php
/**
* Release numbers
*
* @package Less
* @subpackage version
*/
class Less_Version{
const version = '1.7.0.9'; // The current build number of less.php
const less_version = '1.7'; // The less.js version that this build should be compatible with
const cache_version = '170'; // The parser cache version
}
This diff is collapsed.
<?php
//header("content-type:text/css;charset=utf8");
require "lessc.php";
$less = new lessc();
$style = $_GET["style"];
echo $style;
$less_file = "panels/$style/style.less";
$css_file = "tmp/$style.css";
header("content-type:text/plain; charset=utf8");
$tmp = "tmp";
$name = $_GET["name"];
$type = $_GET["type"];
$prec_file_content = "";
$prec_file="$tmp/$name.less";
switch ($type) {
case "design":
$less_file = "css/$name.less";
$prec_file_content = "
@import \"css/colors.less\";
@import \"$less_file\";
";
break;
default:
$less_file = "panels/$name/style.less";
$prec_file_content = "
@import \"css/colors.less\";
[data-template=$name] {
@import \"$less_file\";
}
";
break;
}
if (!file_exists($less_file)) {
http_response_code(404);
echo $less_file." not found";
return;
http_response_code(404);
echo $less_file." not found";
return;
}
require "less/Less.php";
if (!file_exists($prec_file)) {
file_put_contents($prec_file, $prec_file_content);
}
//if ( !file_exists($css_file))
//{
$code =
$less->compile(
"[data-template=$style] {" .
file_get_contents( $less_file ) .
"}"
);
//}
Less_Cache::$cache_dir=$tmp;
$cached_file = Less_Cache::Get(array($prec_file=>"/"));
file_put_contents("tmp/" . $style . ".css", $code);
header("Location: $tmp/$cached_file");
header("Location: tmp/" . $style . ".css" );
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment