mistergraphx
10/29/2014 - 11:49 AM

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 wi

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);