Skip to content

Instantly share code, notes, and snippets.

@benjaminkott
Created April 27, 2015 21:35
Show Gist options
  • Save benjaminkott/eaa577aaaa7140a099d1 to your computer and use it in GitHub Desktop.
Save benjaminkott/eaa577aaaa7140a099d1 to your computer and use it in GitHub Desktop.
Convert Boostrap variables less file to typoscript constants
<?php
$contents = file('variables.less', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$data = array();
$categoryName = "bootstrap package: styling";
$defaultType = "string";
$categoryOffset = 300;
$currentCategory = false;
for($i = 0; $i < count($contents); $i++){
$line = $contents[$i];
// find categorys
if((strpos($line, '//==') !== false || strpos($line, '//--') !== false) && strpos($line, '//===') !== 0){
$name = trim(str_replace('//==','',$line));
$name = trim(str_replace('//--','',$name));
if(strpos(str_replace(' ','',$contents[$i+2]), '//##') !== false){
$description = trim(str_replace('//##','',$contents[$i+2]));
$description = trim(str_replace('// ##','',$description));
}else{
$description = "";
}
$data[] = array(
'name' => $name,
'description' => $description
);
$currentCategory = count($data)-1;
}
if($currentCategory === false) continue;
if(strpos($line, '//') !== 0){
if(strpos($line, '@') === 0){
$values = explode(':', $line);
if(strpos($contents[$i-1], '//**') !== false){
$description = trim(str_replace('//**','',$contents[$i-1]));
}else{
$description = "";
}
$value = explode('//',$values[1]);
$value = substr(trim($value[0]), 0, -1);
$item = array(
'constant' => str_replace('@','',trim($values[0])),
'value' => $value,
'name' => trim($values[0]),
'description' => $description
);
}
$data[$currentCategory]['items'][] = $item;
}
}
echo "############################
### CUSTOM SUBCATEGORIES ###
############################
";
foreach($data as $key => $categorys){
echo "# customsubcategory=".($categoryOffset+$key)."=".$categorys['name']."\n";
}
echo "
plugin.bootstrap_package {
settings {
less {
";
foreach($data as $key => $categorys){
foreach($categorys['items'] as $item){
echo " # cat=".$categoryName."/".($categoryOffset+$key)."/".$item['constant']."; type=string; label=".$item['name'].": ".$item['description']."\n";
echo " ".$item['constant']." = ".$item['value']."\n";
}
}
echo "
}
}
}
";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment