Created
May 4, 2016 10:58
-
-
Save trngon/a58a6ffd7930e047a9c20510f12e79aa to your computer and use it in GitHub Desktop.
Rebuild 1 file less phpFox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//File PF.Base/include/library/phpfox/template/template.class.php Line 1269 (my code) | |
//After include autoload.css and autoload.js from App | |
$Theme = $this->_theme->get(); | |
$css = new Core\Theme\CSS($Theme); | |
$css->buildFile('developing.less', 'developing'); | |
$sData .= '<link href="' . $sBaseUrl . 'PF.Site/themes/' . $Theme->folder . '/flavor/developing.css?v=' . Phpfox::internalVersion() . '" rel="stylesheet">'; | |
//PF.Src/Core/Theme/CSS.php Edit funciton buildFile | |
public function buildFile($fileName, $locationBuild = 'module', $themeName = 'default') | |
{ | |
switch ($locationBuild) { | |
case 'app': | |
$suffixPath = '';//check later | |
break; | |
case 'static': | |
$suffixPath = '';//check later | |
break; | |
case 'module': | |
$suffixPath = PHPFOX_DIR_MODULE; | |
break; | |
case 'developing': | |
$suffixPath = PHPFOX_DIR . 'less' . PHPFOX_DS; | |
$fileName = 'developing.less'; | |
break; | |
default: | |
$suffixPath = PHPFOX_DIR_MODULE; | |
break; | |
} | |
//get less variable and remove import | |
$variable = $this->get(true); | |
$aVariable = explode(';', $variable); | |
foreach ($aVariable as $key => $var) { | |
$string = str_replace("\r", "", $var); | |
$string = str_replace("\n", "", $string); | |
$string = trim(trim($string, '\n'), ' '); | |
if (strpos($string, '@import') !== false) { | |
$variable = str_replace($string . ';', '', $variable); | |
} | |
} | |
$less = new \lessc(); | |
//build | |
$lessContent = $variable . file_get_contents($suffixPath . $fileName); | |
// add default import dirs. | |
$less->addImportDir($this->_theme->getPath() . '/less/'); | |
$less->addImportDir(PHPFOX_DIR . 'less/'); | |
$less->addImportDir(PHPFOX_DIR); | |
// generate import and others | |
$content = '@import "init";' . PHP_EOL . $lessContent; | |
$content = str_replace('../../../../PF.Base/less/autoload', 'compatible_old_410', $content); | |
$parsed = null; | |
try { | |
$parsed = $less->compile($content); | |
} catch (\Exception $ex) { | |
if(isset($_REQUEST['debug'])){ | |
exit($fileName .':'.$ex->getMessage()); | |
} | |
if (PHPFOX_DEBUG) { | |
\Phpfox_Error::trigger($ex->getMessage(), E_USER_ERROR); | |
} | |
} | |
$path = $this->_theme->getPath() . 'flavor/' . substr(str_replace([PHPFOX_DS, '/', '\\'], ['_', '_', '_'], $fileName), 0, -4); | |
$path = trim($path, '.'); | |
file_put_contents($path . '.css', $parsed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment