-
Notifications
You must be signed in to change notification settings - Fork 10
/
custom_function.php
49 lines (42 loc) · 1.1 KB
/
custom_function.php
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
<?php
use ILess\Exception\Exception;
use ILess\FunctionRegistry;
use ILess\Node;
use ILess\Node\AnonymousNode;
use ILess\Node\ColorNode;
use ILess\Parser;
require_once '_bootstrap.php';
class myLessUtils
{
public static function foobar(FunctionRegistry $registry, Node $color = null)
{
// what can you do here, look to ILess\FunctionRegistry.php
if ($color instanceof ColorNode) {
return new AnonymousNode('"Color is here"');
}
return new AnonymousNode('"Foobar is here!"');
}
}
try {
$cacheDir = dirname(__FILE__) . '/cache';
$parser = new Parser();
// adds a function with an alias: fb
$parser->addFunction('foobar', ['myLessUtils', 'foobar'], [
'fb',
]);
$parser->parseString('
@color: red;
#head {
color: foobar(@color);
font-size: fb();
}');
} catch (Exception $e) {
@header('HTTP/1.0 500 Internal Server Error');
echo $e;
exit;
}
$cssContent = $parser->getCSS();
file_put_contents($cacheDir . '/function.css', $cssContent);
$css = 'cache/function.css';
$example = 'custom function';
include '_page.php';