Skip to content

Instantly share code, notes, and snippets.

@mistergraphx
Last active August 29, 2015 14:08
Show Gist options
  • Save mistergraphx/23a7dfafbe5bf2ae3943 to your computer and use it in GitHub Desktop.
Save mistergraphx/23a7dfafbe5bf2ae3943 to your computer and use it in GitHub Desktop.
work with variables scss files and convert them to json : - the primary goal is to set variables from a form or php script and compiling with scssphp @todo - add sassmap support @todo - a color detection : name, # , rgb()
/**
* work with variables scss files and convert them to json
* the primary goal is to set variables from a form or php script and compiling with scssphp
*
* Actualy the script only extract all variables
*
* @todo generating a simple config form with the generated datas (label => input)
* @todo auto-complete with variables in text inputs
* @todo a color piker for Colors input ( rgb(), #... )
* @see http://lumadis.be/regex/test_regex.php?id=2357
*
*/
$finder = new Finder();
$paths = array('www/assets/_sass/');
// Only accept sass, scss, files. using symphony finder
$finder->files()->name('/(variable|setting?)/')->in($paths);
foreach ($finder as $fileInfos) {
$file = new \splFileObject($fileInfos);
while (!$file->eof()) {
$line = $file->fgets();
if(preg_match('/\$(.*?):(.*?);/',$line,$matches)){
$variables[trim($matches[1])] = trim($matches[2]);
}
}
}
$variables = json_encode($variables,JSON_PRETTY_PRINT);
$file = fopen('tmp/sass_variables.json',"w");
$variables = fwrite($file,$variables);
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment