-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-processor.php
More file actions
113 lines (113 loc) · 2.5 KB
/
css-processor.php
File metadata and controls
113 lines (113 loc) · 2.5 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php namespace Jas_n;
include('../../../FUNCTIONS/CORE/print_pre.php'); # For debugging purposes
class css_processor{
/**
Combined defaults and constructor variables
*/
private $args=array();
/**
Default file processing
*/
private $defaults=array(
'minify' =>true, # Minify the CSS
'output' =>'download', # What to do when processing is complete
'output_dir'=>'', # The destination to save the processed CSS
);
/**
List of files/data to process
*/
private $files=array();
/**
List of messages
*/
private $messages=array(
'errors' =>array(),
'success'=>array()
);
public function __construct($options=NULL){
if(is_array($args)){
$this->args=array_merge($this->defaults,$args);
}else{
$this->args=$this->defaults;
}
print_pre($this->args);
}
/**
Add CSS text to process
*/
public function add_text($text){
}
/**
Add a file to process
*/
public function add_file($file){
/* Check against:
- Whether the file exists
- Whether the extension is a .css
- Whether the file type is css*/
}
/**
Get messages captured during processing
*/
public function get_messages(){
print_pre($this->messages);
}
/**
Process the files
- This method handles the return messages
*/
public function process($browsers){
# Check whether files/text has been added
if(sizeof($this->files)===0){
$this->messages['errors'][]='No files/CSS has been added.';
return false;
}
# Process which browsers to add prefixes for
switch($browsers){
case 'bootstrap-3':
break;
case 'bootstrap-4':
break;
}
$this->messages['success'][]='Using browser set '.$browsers;
/*
- Get caniuse.com data if current data is over a day old
*/
# Minify
if($this->args['minify']){
$css=$this->minify($css);
}
# Output
switch($this->args['output']){
case 'dir':
if(!$this->args['output_dir']){
$this->messages['errors'][]='Output directory is not defined.';
return false;
}
break;
case 'download':
break;
case 'text':
break;
default:
$this->messages['errors'][]='Output is incorrectly defined.';
return false;
break;
}
}
/**
Minify compiled css
*/
private function minify($css){
# Strip comments
$css=preg_replace('!/\*.*?\*/!s','', $css);
$css=preg_replace('/\n\s*\n/',"\n", $css);
# Minify
$css=preg_replace('/[\n\r \t]/',' ', $css);
$css=preg_replace('/ +/',' ', $css);
$css=preg_replace('/ ?([,:;{}]) ?/','$1',$css);
# Remove trailing semicolon
$css=preg_replace('/;}/','}',$css);
return $css;
}
}