class SassCompiler in Sassy 7
Hierarchy
- class \SassCompiler
Expanded class hierarchy of SassCompiler
File
- phamlp/
sassc.php, line 45
View source
class SassCompiler {
private $_sass;
private $_path;
private $_updates;
public function __construct() {
require_once dirname(__FILE__) . '/sass/SassParser.php';
$this->_sass = new SassParser(array(
'extensions' => array(
'compass' => array(),
),
'style' => SassRenderer::STYLE_EXPANDED,
'syntax' => SassFile::SCSS,
));
}
public function loop() {
while (1) {
$this
->compile();
sleep(1);
}
}
public function compile() {
try {
clearstatcache();
foreach ($this
->getFiles() as $i => $file) {
$fname = $file['filename'];
if (!isset($this->_updates[$fname]) || filemtime($file['filename']) > $this->_updates[$fname]) {
$c = file_get_contents($file['filename']);
if (empty($c)) {
continue;
}
$result = $this->_sass
->toCss($c, false);
$newfile = substr($fname, 0, -5) . '.css';
file_put_contents($newfile, $result);
$this->_updates[$fname] = filemtime($file['filename']);
echo "save file {$newfile}\n";
}
}
} catch (Exception $e) {
$result = $e
->getMessage();
echo "Error: " . $result;
}
}
public function setPath($path) {
$this->_path = $path;
}
public function getFiles() {
$files = array();
if (is_dir($this->_path)) {
if ($handle = opendir($this->_path)) {
while (($file = readdir($handle)) !== false) {
if (substr($file, -5) === '.scss' && is_file($this->_path . DIRECTORY_SEPARATOR . $file)) {
$files[] = array(
'filename' => $this->_path . DIRECTORY_SEPARATOR . $file,
);
}
}
}
}
else {
if (is_file($this->_path)) {
$files[] = array(
'filename' => $file,
);
}
}
return $files;
}
public function addDir($dir) {
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (substr($file, -5) === '.scss' && is_file($dir . DIRECTORY_SEPARATOR . $file)) {
$this->_files[] = array(
'filename' => $dir . DIRECTORY_SEPARATOR . $file,
);
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SassCompiler:: |
private | property | ||
SassCompiler:: |
private | property | ||
SassCompiler:: |
private | property | ||
SassCompiler:: |
public | function | ||
SassCompiler:: |
public | function | ||
SassCompiler:: |
public | function | ||
SassCompiler:: |
public | function | ||
SassCompiler:: |
public | function | ||
SassCompiler:: |
public | function |