Slice 4 chars from end (for less and scss)

The char position used by $fileNameExtPos is actually from the
beginning, not end, so is useless here
However, we know that 'less' and 'scss' are 4 chars, so we can just
slice off those 4 chars always
This commit is contained in:
Matt Pass
2014-10-18 20:38:31 +01:00
parent 16da2d6a88
commit 15eba478ac

View File

@@ -9,7 +9,6 @@
// Compiling Sass and LESS files (.scss and .less to .css version, with same name, in same dir)
$fileName = basename($file);
$fileNameExtPos = strrpos($fileName,".");
$filePieces = explode(".",$file);
$fileExt = $filePieces[count($filePieces)-1];
@@ -25,7 +24,7 @@ if (strtolower($fileExt) == "scss" && file_exists(dirname(__FILE__)."/../plugins
try {
$scssContent = $scss->compile('@import "'.$fileName.'"');
$fh = fopen(substr($file, 0, -$fileNameExtPos)."css", 'w');
$fh = fopen(substr($file, 0, -4)."css", 'w');
fwrite($fh, $scssContent);
fclose($fh);
} catch (Exception $e) {
@@ -44,7 +43,7 @@ if (strtolower($fileExt) == "less" && file_exists(dirname(__FILE__)."/../plugins
$less->setPreserveComments(false); // true or false
try {
$less->checkedCompile($file, substr($file, 0, -$fileNameExtPos)."css"); // Note: Only recompiles if changed
$less->checkedCompile($file, substr($file, 0, -4)."css"); // Note: Only recompiles if changed
} catch (Exception $e) {
echo ";top.ICEcoder.message('Couldn\'t compile your LESS, error info below:\\n\\n".$e->getMessage()."');";
}