Skip to content

Instantly share code, notes, and snippets.

@mishak87
Created May 6, 2012 11:29
Show Gist options
  • Save mishak87/2621764 to your computer and use it in GitHub Desktop.
Save mishak87/2621764 to your computer and use it in GitHub Desktop.
Builds css from sass and css files - using Nette conventions for directory structure
<?php
$documentRootStyles = realpath(__DIR__ . '/../document_root/css');
$appDir = realpath(__DIR__ . '/../app');
foreach (new DirectoryIterator($appDir) as $file) {
if (!$file->isDir() || !preg_match('/.+Module/', $file->getFilename())) {
continue;
}
$module = lcfirst(substr($file->getFilename(), 0, -6));
$stylesDir = $appDir . '/' . $file->getFilename() . '/styles';
if (is_dir($stylesDir)) {
foreach (new DirectoryIterator($stylesDir) as $file) {
if (!$file->isFile()) {
continue;
}
$source = $file->getPathname();
$ext = pathinfo($source, PATHINFO_EXTENSION);
$target = $documentRootStyles . '/' . $module . '/' . substr(basename($source), 0, -strlen($ext) - 1) . '.css';
@mkdir(dirname($target));
if ($ext == 'sass' || $ext == 'scss') {
shell_exec($command = 'sass --no-cache --style expanded "' . $source . '" "' . $target . '"');
} elseif ($ext == 'css') {
copy($source, $target);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment