Skip to content

Commit 956bc07

Browse files
committed
added lessify, css to less compiler
uses parser from lessphp to recursively describe a css file as a less file. Looks for common ancestors in selectors and builds a less document. For now: ./lessify filename > output or, include `lessify.inc.php` and: $l = new lessify($file); echo $l->parse();
1 parent c3a1418 commit 956bc07

File tree

3 files changed

+469
-2
lines changed

3 files changed

+469
-2
lines changed

lessc.inc.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class lessc {
2525
protected $inAnimations;
2626

2727
public $indentLevel;
28+
public $indentChar = ' ';
2829

2930
protected $env = null;
3031

@@ -818,14 +819,14 @@ function compileBlock($block, $parentTags = null, $bindEnv = true) {
818819
// write a line a the proper indent
819820
function indent($str, $level = null) {
820821
if (is_null($level)) $level = $this->indentLevel;
821-
return str_repeat(' ', $level).$str."\n";
822+
return str_repeat($this->indentChar, $level).$str."\n";
822823
}
823824

824825
function compileProperty($name, $value, $level = 0) {
825826
$level = $this->indentLevel + $level;
826827
// output all repeated properties
827828
foreach ($value as $v)
828-
$props[] = str_repeat(' ', $level).
829+
$props[] = str_repeat($this->indentChar, $level).
829830
$name.':'.$this->compileValue($v).';';
830831

831832
return implode("\n", $props);

lessify

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/php -q
2+
<?php
3+
4+
if (php_sapi_name() != "cli") {
5+
err($fa.$argv[0]." must be run in the command line.");
6+
exit(1);
7+
}
8+
$exe = array_shift($argv); // remove filename
9+
10+
if (!$fname = array_shift($argv)) {
11+
exit("Usage: ".$exe." input-file\n");
12+
}
13+
14+
require "lessify.inc.php";
15+
16+
try {
17+
$parser = new lessify($fname);
18+
echo $parser->parse();
19+
} catch (exception $e) {
20+
exit("Fatal error: ".$e->getMessage()."\n");
21+
}
22+
23+

0 commit comments

Comments
 (0)