<commit_before><?php
/**
 * convert less files to css
 * 
 * a 'full'description
 * multilene is cool
 * and big number is more cool
 * @author <NAME> <<EMAIL>>
 * @version 0.0.1
 * @package sample
*/


function parser($dirPath = './', $fileType = 'less', $recursive = 10 , $basedir = './'){
	if($recursive == 0){
		return;
	}	
	$retval = array();
	$fileTypePattern = '/\.'. $fileType . '$/';
	if(substr($dirPath, -1) != "/"){
		$dirPath .= "/";
	} 
	if ($handle = opendir($dirPath)) {
		while (false !== ($file = readdir($handle))) {
			$fileEntry = $dirPath. $file;
			if ($file != "." && $file != "..") {
				if (is_dir($fileEntry)) {
					$retval[] = array(
						"name" => $file,
						"type" => filetype($fileEntry),
						"size" => 0,
						"lastmod" => filemtime($fileEntry),
						"content" => parser($fileEntry, $fileType, $recursive - 1, $basedir)
					);
				}else {
					if(preg_match($fileTypePattern, $file)){
						$retval[] = array(
							"name" => $file,
							"namenotype" => str_replace('.' . $fileType, '', $file),
							"pathname" => str_replace($basedir, '', str_replace($file , '', $fileEntry)),
							"type" => mime_content_type($fileEntry),
							"size" => filesize($fileEntry),
							"lastmod" => filemtime($fileEntry)
						);
					} 
				}
			}
		}
		closedir($handle);
	}
	
	return $retval;
}
function cleaner($tree = array()){
	$cant = count($tree);
	$dummy_array = array();
	$rtree = array();
	for($i = 0; $i< $cant; $i++){
		if(isset($tree[$i]['content'])){
			if($tree[$i]['content'] === $dummy_array){
				unset($tree[$i]); /*no it is nesseray */
			}else{
				$tree[$i]['content'] = cleaner($tree[$i]['content']);
				$rtree[] = $tree[$i];
			}
		}else{
			$rtree[] = $tree[$i];
		}
	}
	return $rtree;
}
function deTree($tree, &$out = array()){
	$newTree = array();
	foreach($tree as $file){
		if(isset($file['content'])){
			deTree($file['content'], $out);
		}else{
			$out[] = $file;
		}
	}
	return $out;
}
function generate($fileName = 'generado.html', $templateDir = 'templates/basic/', $basePath = './', $fileType = 'pdf', $recursive = 10){
	$header = new coSimpleTemplate($templateDir . 'header.tpl');
	#$header->set('value', 'data');
	$footer = new coSimpleTemplate($templateDir . 'footer.tpl');
	$footer->set('copy', 'This page are generated by CoGenerate &copy; 2011');
	$file = fopen($basePath . 'generado.html', 'w');
	$html = $header->output();
	$tree = parser($basePath, $fileType, $recursive, $basePath);
	$cleanTree = cleaner($tree);
	for($i = 0; $i< 5; $i++){
		$cleanTree = cleaner($cleanTree); /*for truely clean the tree*//*WTF? really not know this code*/
	}
	$html .= painter($cleanTree, $templateDir);
	$html .= $footer->output();
	fwrite($file, html_nicer($html));
	fclose($file);
	copier($templateDir, $basePath);
}



/*generate('generado.html', 'templates/basic/', basedir, fileType, max_recursive);
var_dump($argv);
var_dump($argc);*/
/*echo('Usage generador.php fileToGenerate routeToTemplate baseDir fileTypeToCatalog maxRecursive');
$var = array();
if(isset($argv[1])){
	$var[1] = $argv[1];
}else{
	$var[1] = 'generado.html';
}
if(isset($argv[2])){
	$var[2] = $argv[2];
}else{
	$var[2] = 'templates/basic/';
}
if(isset($argv[3])){
	$var[3] = $argv[3];
}else{
	$var[3] = basedir;
}
if(isset($argv[4])){
	$var[4] = $argv[4];
}else{
	$var[4] = fileType;
}
if(isset($argv[5])){
	$var[5] = $argv[5];
}else{
	$var[5] = max_recursive;
}
generate($var[1],$var[2],$var[3],$var[4],$var[5]);*/

function genCSS(){
	require "lessc.inc.php";
	$unclean = 1;
	$tree = parser("less/", "less", 10, "less/");
	$cleanTree = array();
	while($unclean){
		if($cleanTree == $tree){
			$unclean = 0;
		}else{
			$cleanTree = cleaner($tree);
			$tree = $cleanTree;
		}
	}
	$tree = deTree($tree);
	$less = new lessc;
	foreach($tree as $file){
		$cssName = 'css/' . $file['pathname'] . $file['namenotype'] . '.css';
		$lessName = 'less/' . $file['pathname'] . $file['namenotype'] . '.less';
		$cssDir = 'css/' . $file['pathname'];
		if(!is_dir($cssDir)){
			mkdir($cssDir, 0755, TRUE);
		}
		$less->checkedCompile($lessName, $cssName);
	}
	
}


genCSS();
?><commit_msg>now gen css from less files<commit_after><?php
/**
 * convert less files to css
 * 
 * a 'full'description
 * multilene is cool
 * and big number is more cool
 * @author <NAME> <<EMAIL>>
 * @version 0.0.1
 * @package sample
*/


function parser($dirPath = './', $fileType = 'less', $recursive = 10 , $basedir = './'){
	if($recursive == 0){
		return;
	}	
	$retval = array();
	$fileTypePattern = '/\.'. $fileType . '$/';
	if(substr($dirPath, -1) != "/"){
		$dirPath .= "/";
	} 
	if ($handle = opendir($dirPath)) {
		while (false !== ($file = readdir($handle))) {
			$fileEntry = $dirPath. $file;
			if ($file != "." && $file != "..") {
				if (is_dir($fileEntry)) {
					$retval[] = array(
						"name" => $file,
						"type" => filetype($fileEntry),
						"size" => 0,
						"lastmod" => filemtime($fileEntry),
						"content" => parser($fileEntry, $fileType, $recursive - 1, $basedir)
					);
				}else {
					if(preg_match($fileTypePattern, $file)){
						$retval[] = array(
							"name" => $file,
							"namenotype" => str_replace('.' . $fileType, '', $file),
							"pathname" => str_replace($basedir, '', str_replace($file , '', $fileEntry)),
							"type" => mime_content_type($fileEntry),
							"size" => filesize($fileEntry),
							"lastmod" => filemtime($fileEntry)
						);
					} 
				}
			}
		}
		closedir($handle);
	}
	
	return $retval;
}
function cleaner($tree = array()){
	$cant = count($tree);
	$dummy_array = array();
	$rtree = array();
	for($i = 0; $i< $cant; $i++){
		if(isset($tree[$i]['content'])){
			if($tree[$i]['content'] === $dummy_array){
				unset($tree[$i]); /*no it is nesseray */
			}else{
				$tree[$i]['content'] = cleaner($tree[$i]['content']);
				$rtree[] = $tree[$i];
			}
		}else{
			$rtree[] = $tree[$i];
		}
	}
	return $rtree;
}
function deTree($tree, &$out = array()){
	$newTree = array();
	foreach($tree as $file){
		if(isset($file['content'])){
			deTree($file['content'], $out);
		}else{
			$out[] = $file;
		}
	}
	return $out;
}
function generate($fileName = 'generado.html', $templateDir = 'templates/basic/', $basePath = './', $fileType = 'pdf', $recursive = 10){
	$header = new coSimpleTemplate($templateDir . 'header.tpl');
	#$header->set('value', 'data');
	$footer = new coSimpleTemplate($templateDir . 'footer.tpl');
	$footer->set('copy', 'This page are generated by CoGenerate &copy; 2011');
	$file = fopen($basePath . 'generado.html', 'w');
	$html = $header->output();
	$tree = parser($basePath, $fileType, $recursive, $basePath);
	$cleanTree = cleaner($tree);
	for($i = 0; $i< 5; $i++){
		$cleanTree = cleaner($cleanTree); /*for truely clean the tree*//*WTF? really not know this code*/
	}
	$html .= painter($cleanTree, $templateDir);
	$html .= $footer->output();
	fwrite($file, html_nicer($html));
	fclose($file);
	copier($templateDir, $basePath);
}



/*generate('generado.html', 'templates/basic/', basedir, fileType, max_recursive);
var_dump($argv);
var_dump($argc);*/
/*echo('Usage generador.php fileToGenerate routeToTemplate baseDir fileTypeToCatalog maxRecursive');
$var = array();
if(isset($argv[1])){
	$var[1] = $argv[1];
}else{
	$var[1] = 'generado.html';
}
if(isset($argv[2])){
	$var[2] = $argv[2];
}else{
	$var[2] = 'templates/basic/';
}
if(isset($argv[3])){
	$var[3] = $argv[3];
}else{
	$var[3] = basedir;
}
if(isset($argv[4])){
	$var[4] = $argv[4];
}else{
	$var[4] = fileType;
}
if(isset($argv[5])){
	$var[5] = $argv[5];
}else{
	$var[5] = max_recursive;
}
generate($var[1],$var[2],$var[3],$var[4],$var[5]);*/

function genCSS($lessDir = 'less/', $cssDir = 'css/', $lessExt = 'less' ){
	require "lessc.inc.php";
	$unclean = 1;
	$tree = parser($lessDir, $lessExt, 10, $lessDir);
	$cleanTree = array();
	while($unclean){
		if($cleanTree == $tree){
			$unclean = 0;
		}else{
			$cleanTree = cleaner($tree);
			$tree = $cleanTree;
		}
	}
	$tree = deTree($tree);
	$less = new lessc;
	foreach($tree as $file){
		$cssName = $cssDir . $file['pathname'] . $file['namenotype'] . '.css';
		$lessName = $lessDir . $file['pathname'] . $file['namenotype'] . '.' . $lessExt;
		$cssDir = $cssDir . $file['pathname'];
		if(!is_dir($cssDir)){
			mkdir($cssDir, 0755, TRUE);
		}
		$less->checkedCompile($lessName, $cssName);
	}
	
}


genCSS();
?>
{'fraction_non_alphanumeric': 0.24217998075072183, 'fraction_numerical': 0.012271414821944177, 'mean_word_length': 3.9868026394721054, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5643393', 'n_tokens_mistral': 3600, 'n_tokens_neox': 3209, 'n_words': 634}