lessc.php
1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once dirname(__FILE__) . '/lessc.inc.php';
class drupalexp_lessc{
var $theme;
var $output;
var $css;
var $lessc;
var $importDir;
function __construct($theme){
$this->theme = $theme;
$this->lessc = new lessc();
$this->lessc->setImportDir(drupal_get_path('theme',$theme->theme));
$this->importDir = drupal_get_path('theme',$theme->theme);
$this->__addPresetVariables();
$this->__addBaseCSS();
}
function addVariable($name, $value){
$this->output .= "@{$name}:{$value};\n";
}
function filetime($file){
if(($time = @filemtime($file)) != FALSE){
return $time;
}
if(($time = @filemtime($this->importDir.'/'.$file)) != FALSE){
return $time;
}
return 0;
}
function complie($file = null){
$update = drupalexp_is_settings_change();
$ftime = $this->filetime($file);
if (!empty($this->theme->lessc)) {
foreach($this->theme->lessc as $lessc_file) {
if($ftime < $this->filetime($lessc_file)){
$update = true;
}
$this->output .= "@import \"$lessc_file\";\n";
}
}
if($update){
try{
$this->css = $this->lessc->compile($this->output);
}catch(exception $e){
drupal_set_message("fatal error: " . $e->getMessage(),'error');
return FALSE;
}
if($file){
$css_output = "/*This file is generated by less css (http://lesscss.org) using drupalexp framework (http://drupalexp.com)*/\n/*Please do not modify this file content*/\n".$this->css;
file_unmanaged_save_data($css_output,$file,FILE_EXISTS_REPLACE);
}
}
return $this->css;
}
private function __addPresetVariables(){
foreach($this->theme->lessc_vars as $key => $value){
$this->addVariable($key, $value);
}
}
private function __addBaseCSS(){
$this->output .= 'body{color: @text_color;}a:not(.btn){color:@link_color; &:hover{color:@link_hover_color}}h1,h2,h3,h4,h5,h6{color:@heading_color}';
}
}