本文整理汇总了PHP中lessc::setImportDir方法的典型用法代码示例。如果您正苦于以下问题:PHP lessc::setImportDir方法的具体用法?PHP lessc::setImportDir怎么用?PHP lessc::setImportDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lessc
的用法示例。
在下文中一共展示了lessc::setImportDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
public static function compile($source, $path, $todir, $importdirs)
{
// call Less to compile
$parser = new lessc();
$parser->setImportDir(array_keys($importdirs));
$parser->setPreserveComments(true);
$output = $parser->compile($source);
// update url
$arr = preg_split(CANVASLess::$rsplitbegin . CANVASLess::$kfilepath . CANVASLess::$rsplitend, $output, -1, PREG_SPLIT_DELIM_CAPTURE);
$output = '';
$file = $relpath = '';
$isfile = false;
foreach ($arr as $s) {
if ($isfile) {
$isfile = false;
$file = $s;
$relpath = CANVASLess::relativePath($todir, dirname($file));
$output .= "\n#" . CANVASLess::$kfilepath . "{content: \"{$file}\";}\n";
} else {
$output .= ($file ? CANVASPath::updateUrl($s, $relpath) : $s) . "\n\n";
$isfile = true;
}
}
return $output;
}
示例2: compile
/**
* Compile the Less file in $origin to the CSS $destination file
*
* @param string $origin Input Less path
* @param string $destination Output CSS path
*/
public static function compile($origin, $destination)
{
$less = new \lessc();
$less->indentChar = \Config::get('asset.indent_with');
$less->setImportDir(array(dirname($origin), dirname($destination)));
$raw_css = $less->compile(file_get_contents($origin));
$destination = pathinfo($destination);
\File::update($destination['dirname'], $destination['basename'], $raw_css);
}
示例3: less
/**
* Compile less -> css
* @param str $inputFile
* @param str $outputFile
* @return boolean
*/
public static function less($inputFile, $outputFile)
{
if (JFile::exists($inputFile)) {
$less = new lessc();
$less->setImportDir(array(dirname($inputFile)));
return $less->compileFile($inputFile, $outputFile);
}
return false;
}
示例4: compile
public static function compile($source, $importdirs)
{
// call Less to compile
$parser = new lessc();
$parser->setImportDir(array_keys($importdirs));
$parser->setPreserveComments(true);
$output = $parser->compile($source);
return $output;
}
示例5: testCheckedCachedCompile
public function testCheckedCachedCompile()
{
$server = new lessc();
$server->setImportDir(__DIR__ . '/inputs/test-imports/');
$css = $server->checkedCachedCompile(__DIR__ . '/inputs/import.less', '/tmp/less.css');
$this->assertFileExists('/tmp/less.css');
$this->assertFileExists('/tmp/less.css.meta');
$this->assertEquals($css, file_get_contents('/tmp/less.css'));
$this->assertNotNull(unserialize(file_get_contents('/tmp/less.css.meta')));
}
示例6: compile
/**
* Compiles LESS code into CSS code using <em>lessphp</em>, http://leafo.net/lessphp
*
* @param string $less Less code
* @return string CSS code
* @throws dmInvalidLessException
*/
public function compile($less, array $importDirs = array())
{
$lessCompiler = new lessc();
$lessCompiler->setImportDir($importDirs);
try {
return $lessCompiler->compile($less);
} catch (Exception $e) {
throw new dmInvalidLessException($e->getMessage());
}
}
示例7: compileTo
/**
* Compile all files into one file.
*
* @param string $filePath File location.
* @param string $format Formatter for less.
*
* @return void
*/
public function compileTo($filePath, $format = 'compressed')
{
$less = '';
foreach ($this->_files as $file) {
$less .= file_get_contents($file) . "\n\n";
}
$this->_lessc->setImportDir($this->_importDirs);
$this->_lessc->setFormatter($format);
$result = $this->_lessc->compile($less);
file_put_contents($filePath, $result);
}
示例8: lessphp
/**
* lessphp compiler
* @link https://github.com/leafo/lessphp
*
* @param string $file
*
* @return string
*/
protected function lessphp($file)
{
if (!class_exists('\\lessc')) {
return Result::errorMissingPackage($this, 'lessc', 'leafo/lessphp');
}
$lessCode = file_get_contents($file);
$less = new \lessc();
if (isset($this->compilerOptions['importDirs'])) {
$less->setImportDir($this->compilerOptions['importDirs']);
}
return $less->compile($lessCode);
}
示例9: compile
/**
* Compiles a less css file. The the compiler will create a css file output.
*
* @param array $config Array of less compile configuration
*/
public function compile($config = array())
{
$config = new KConfig($config);
$config->append(array('parse_urls' => true, 'compress' => true, 'import' => array(), 'force' => false, 'output' => null, 'input' => null));
$less = new lessc();
$less->setPreserveComments(!$config->compress);
if ($config->compress) {
$less->setFormatter('compressed');
}
$config['import'] = $config['import'];
$less->setImportDir($config['import']);
$cache_file = JPATH_CACHE . '/less-' . md5($config->input);
if (file_exists($cache_file)) {
$cache = unserialize(file_get_contents($cache_file));
} else {
$cache = $config->input;
}
$force = $config->force;
//if output doesn't exsit then force compile
if (!is_readable($config->output)) {
$force = true;
}
//check if any of the import folder have changed or
//if yes then re-compile
if (is_array($cache)) {
foreach ($config['import'] as $path) {
if (is_readable($path) && filemtime($path) > $cache['updated']) {
$force = true;
break;
}
}
}
try {
$new_cache = $less->cachedCompile($cache, $force);
} catch (Exception $e) {
print $e->getMessage();
return;
}
if (!is_array($cache) || $new_cache['updated'] > $cache['updated']) {
if ($config->parse_urls) {
$new_cache['compiled'] = $this->_parseUrls($new_cache['compiled'], $config->import);
}
//store the cache
file_put_contents($cache_file, serialize($new_cache));
//store the compiled file
//create a directory if
if (!file_exists(dirname($config->output))) {
mkdir(dirname($config->output), 0755);
}
file_put_contents($config->output, $new_cache['compiled']);
}
}
示例10: compileCss
public function compileCss(&$templateData, $cssFileName)
{
glz_importLib('lessphp/lessc.inc.php');
$less = new lessc();
$less->setImportDir(array(__DIR__ . '/less/'));
$css = file_get_contents(__DIR__ . '/less/styles.less');
$css = $this->applyCssVariables($templateData, $less, $css);
$css = $this->applyFont($templateData, $less, $css);
$css = $less->compile($css);
$css = str_replace(array('../img/', '../font/'), array('../static/movio/templates/Movio/img/', '../static/movio/templates/Movio/font/'), $css);
$css .= PHP_EOL . $templateData->customCss;
file_put_contents($cssFileName, $css);
$templateData->css = '<link rel="stylesheet" href="' . $cssFileName . '" type="text/css" media="screen" />';
}
示例11: loadcssfile
function loadcssfile($file, $cacheFile)
{
// load the cache
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $file;
}
$less = new lessc();
$less->setFormatter("compressed");
$less->setImportDir(array(__ROOT__ . DS . ".." . DS . "style" . DS . "less"));
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
@file_put_contents($cacheFile, serialize($newCache));
}
return $newCache['compiled'];
}
示例12: parseLess
protected function parseLess($input)
{
$parsed = false;
try {
//include lessc library
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'lessc.inc.php';
//setup the parser
$lessc = new lessc();
if ($this->compress) {
$lessc->setFormatter("compressed");
}
$importDir = array_merge($this->importDir, array(dirname($input)));
$lessc->setImportDir($importDir);
//parse the file
$parsed = $lessc->parse($input);
} catch (exception $e) {
throw new CException(__CLASS__ . ': Failed to compile less file with message: ' . $e->getMessage() . '.');
}
return $parsed;
}
示例13: set
public function set($content, $vars = null)
{
$less = new \lessc();
$lessContent = ($vars === null ? $this->get(true) : $vars) . "/** START CSS */\n";
$newContent = $lessContent . trim($content);
$less->setImportDir(PHPFOX_DIR . 'less/');
$content = str_replace('../../../../PF.Base/less/', '', $newContent);
$parsed = $less->compile($content);
$path = $this->_theme->getPath() . 'flavor/' . $this->_theme->flavor_folder;
file_put_contents($path . '.less', $newContent);
file_put_contents($path . '.css', $parsed);
$this->db->update(':setting', array('value_actual' => (int) \Phpfox::getParam('core.css_edit_id') + 1), 'var_name = \'css_edit_id\'');
$this->cache->del('setting');
return true;
// file_put_contents($this->_theme->getPath() . 'flavor/' . $this->_theme->flavor_folder . '.min.css', $parsed);
// if ($this->_get()) {
/*
$this->db->update(':theme_template', [
'html_data' => $parsed,
'html_data_original' => $content,
'time_stamp_update' => PHPFOX_TIME
], [
'folder' => $this->_theme->folder, 'type_id' => 'css', 'name' => $this->_theme->flavor_folder . '.css'
]);
*/
// return true;
// }
/*
$this->db->insert(':theme_template', [
'folder' => $this->_theme->folder,
'type_id' => 'css',
'name' => $this->_theme->flavor_folder . '.css',
'html_data' => $parsed,
'html_data_original' => $content,
'time_stamp' => PHPFOX_TIME
]);
*/
return true;
}
示例14: beforesave
public function beforesave()
{
$change = true;
if (!empty($_POST['bootstrap'])) {
$change = $this->cfg['bootstrap'] != $_POST['bootstrap'];
}
if ($change) {
include_once JPATH_SITE . '/components/com_acctexp/lib/lessphp/lessc.inc.php';
$less = new lessc();
$less->setImportDir(array(JPATH_SITE . '/media/com_acctexp/less/'));
//$less->setFormatter("compressed");
$less->setPreserveComments(true);
if (!isset($_POST['bootstrap'])) {
$this->cfg['bootstrap'] = true;
} else {
$this->cfg['bootstrap'] = $_POST['bootstrap'];
}
if ($this->cfg['bootstrap']) {
$less->compileFile(JPATH_SITE . "/media/com_acctexp/less/template.etacarinae.less", JPATH_SITE . '/media/com_acctexp/css/template.etacarinae.css');
} else {
$less->compileFile(JPATH_SITE . "/media/com_acctexp/less/template.etacarinae-reuse-bootstrap.less", JPATH_SITE . '/media/com_acctexp/css/template.etacarinae.css');
}
}
}
示例15: initializeLessCompiler
/**
* Initialize less compiler
* @param $formatterName
* @param $z_textColor
* @param $z_themeColor
* @param $z_themeColor2
* @param $z_themeColorBtn
* @param $z_themeColorHeader
* @param $z_path
* @return lessc
*/
protected function initializeLessCompiler($formatterName, $z_textColor, $z_themeColor, $z_themeColor2, $z_themeColorBtn, $z_themeColorHeader, $z_path)
{
$lessCompiler = new lessc();
$lessCompiler->setPreserveComments(false);
$lessCompiler->setFormatter($formatterName);
$lessCompiler->setImportDir($this->getLessFilesPath());
$lessCompiler->setVariables(array("z_textColor" => $z_textColor, "z_themeColor" => $z_themeColor, "z_themeColor2" => $z_themeColor2, "z_themeColorBtn" => $z_themeColorBtn, "z_themeColorHeader" => $z_themeColorHeader, "z_path" => $z_path));
return $lessCompiler;
}