当前位置: 首页>>代码示例>>PHP>>正文


PHP lessc::addImportDir方法代码示例

本文整理汇总了PHP中lessc::addImportDir方法的典型用法代码示例。如果您正苦于以下问题:PHP lessc::addImportDir方法的具体用法?PHP lessc::addImportDir怎么用?PHP lessc::addImportDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lessc的用法示例。


在下文中一共展示了lessc::addImportDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getEnvironment

 /**
  * Get LESS compiler (if undefined, set it with path for @import directives)
  *
  * @param boolean $reset
  */
 protected function getEnvironment($reset = false)
 {
     if ($reset === true || null === $this->lessc) {
         $this->lessc = new \lessc();
         $this->lessc->addImportDir($this->getConfigFor('phr_template_dir'));
     }
     return $this->lessc;
 }
开发者ID:lordelph,项目名称:phrekyll,代码行数:13,代码来源:Less.php

示例2: setImportPath

 /**
  * {@inheritdoc}
  */
 public function setImportPath($fullPath, $relPath = null)
 {
     $this->_initCompiler();
     if (!FS::isDir($fullPath)) {
         throw new Exception('Undefined import path: ' . $fullPath);
     }
     $fullPath = FS::getRelative($fullPath, $this->_options->get('root_path'));
     $this->_compiler->addImportDir($fullPath);
 }
开发者ID:jbzoo,项目名称:less,代码行数:12,代码来源:Leafo.php

示例3: parse_less_files

 /**
  * Parse all the less files resolving the dependencies.
  *
  * @param array $variables
  * @throws Ai1ec_File_Not_Found_Exception|Exception
  * @throws Exception
  * @return string
  */
 public function parse_less_files(array $variables = null)
 {
     // If no variables are passed, initialize from DB, config file, and
     // extension injections in one call.
     if (empty($variables)) {
         $variables = $this->get_saved_variables(false);
     }
     // convert the variables to key / value
     $variables = $this->convert_less_variables_for_parsing($variables);
     // Inject additional constants from extensions.
     $variables = apply_filters('ai1ec_less_constants', $variables);
     // Load the static variables defined in the theme's variables.less file.
     $this->load_static_theme_variables();
     $loader = $this->_registry->get('theme.loader');
     // Allow extensions to add their own LESS files.
     $this->files = apply_filters('ai1ec_less_files', $this->files);
     $this->files[] = 'override.less';
     // Find out the active theme URL.
     $option = $this->_registry->get('model.option');
     $theme = $option->get('ai1ec_current_theme');
     $this->lessc->addImportDir($theme['theme_dir'] . DIRECTORY_SEPARATOR . 'less');
     $import_dirs = array();
     foreach ($this->files as $file) {
         $file_to_parse = null;
         try {
             // Get the filename following our fallback convention
             $file_to_parse = $loader->get_file($file);
         } catch (Ai1ec_Exception $e) {
             // We let child themes override styles of Vortex.
             // So there is no fallback for override and we can continue.
             if ($file !== 'override.less') {
                 throw $e;
             } else {
                 // It's an override, skip it.
                 continue;
             }
         }
         // We prepend the unparsed variables.less file we got earlier.
         // We do this as we do not import that anymore in the less files.
         $this->unparsed_variable_file .= $file_to_parse->get_content();
         // Set the import directories for the file. Includes current directory of
         // file as well as theme directory in core. This is important for
         // dependencies to be resolved correctly.
         $dir = dirname($file_to_parse->get_name());
         if (!isset($import_dirs[$dir])) {
             $import_dirs[$dir] = true;
             $this->lessc->addImportDir($dir);
         }
     }
     $variables['fontdir'] = '~"' . $theme['theme_url'] . '/font"';
     $variables['fontdir_default'] = '~"' . $this->default_theme_url . 'font"';
     $variables['imgdir'] = '~"' . $theme['theme_url'] . '/img"';
     $variables['imgdir_default'] = '~"' . $this->default_theme_url . 'img"';
     try {
         $this->parsed_css = $this->lessc->parse($this->unparsed_variable_file, $variables);
     } catch (Exception $e) {
         throw $e;
     }
     return $this->parsed_css;
 }
开发者ID:newmight2015,项目名称:psmpsm,代码行数:68,代码来源:lessphp.php

示例4: filterAssetFile

 /**
  * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
  * @return string
  */
 public function filterAssetFile(\AssetsBundle\AssetFile\AssetFile $oAssetFile)
 {
     $oLessParser = new \lessc();
     $oLessParser->addImportDir(getcwd());
     $oLessParser->setAllowUrlRewrite(true);
     //Prevent time limit errors
     set_time_limit(0);
     return trim($oLessParser->compile($oAssetFile->getAssetFileContents()));
 }
开发者ID:as-sar,项目名称:zf2-assets-bundle,代码行数:13,代码来源:LesscAssetFileFilter.php

示例5: filterLoad

 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $lc = new \lessc();
     if ($root && $path) {
         $lc->importDir = dirname($root . '/' . $path);
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:13,代码来源:LessphpFilter.php

示例6: filterDump

 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $compiler = new \lessc();
     $this->dispatch(new LoadThemeVariables($variables = new Collection()));
     $compiler->setVariables($variables->all());
     if ($dir = $asset->getSourceDirectory()) {
         $compiler->importDir = $dir;
     }
     foreach ($this->loadPaths as $loadPath) {
         $compiler->addImportDir($loadPath);
     }
     $asset->setContent($compiler->parse($this->parser->parse($asset->getContent())));
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:18,代码来源:LessFilter.php

示例7: _initProcessor

 /**
  * @return lessc
  */
 protected function _initProcessor()
 {
     // lazy load
     if (!class_exists('lessc')) {
         require_once dirname(__FILE__) . '/class.less.leafo.php';
     }
     $less = new lessc();
     if ($this->_isDebug()) {
         $formatter = new lessc_formatter_lessjs();
         // configurate css view
         $formatter->openSingle = " { ";
         $formatter->closeSingle = "}\n";
         $formatter->close = "}\n";
         $formatter->indentChar = "    ";
         $formatter->disableSingle = true;
         $formatter->breakSelectors = true;
         $formatter->assignSeparator = ": ";
         $formatter->selectorSeparator = ", ";
     } else {
         // compress mode
         $formatter = new lessc_formatter_compressed();
         $formatter->closeSingle = "}\n";
         $formatter->close = "}\n";
     }
     // set formatter
     $less->setFormatter($formatter);
     $less->setPreserveComments(false);
     // add paths for imports
     $less->addImportDir($this->_tpl->lessFull);
     $less->addImportDir(JPATH_ROOT);
     // from php
     $less->setVariables(array('css' => str_replace($this->_tpl->baseurl, '', $this->_tpl->css), 'less' => str_replace($this->_tpl->baseurl, '', $this->_tpl->less), 'images' => str_replace($this->_tpl->baseurl, '', $this->_tpl->img), 'debug' => (int) $this->_isDebug()));
     // add custom functions
     $less->registerFunction('data-uri', array($this, 'lib_dataUri'));
     return $less;
 }
开发者ID:nikoyar,项目名称:jblank,代码行数:39,代码来源:css.less.leafo.php

示例8: filterLoad

 public function filterLoad(AssetInterface $asset)
 {
     $lc = new \lessc();
     if ($dir = $asset->getSourceDirectory()) {
         $lc->importDir = $dir;
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     if ($this->formatter) {
         $lc->setFormatter($this->formatter);
     }
     if (null !== $this->preserveComments) {
         $lc->setPreserveComments($this->preserveComments);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
开发者ID:samj1912,项目名称:repo,代码行数:17,代码来源:LessphpFilter.php

示例9: filterLoad

 public function filterLoad(AssetInterface $asset)
 {
     $lc = new \lessc();
     if ($dir = $asset->getSourceDirectory()) {
         $lc->importDir = $dir;
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     foreach ($this->customFunctions as $name => $callable) {
         $lc->registerFunction($name, $callable);
     }
     if ($this->formatter) {
         $lc->setFormatter($this->formatter);
     }
     if (null !== $this->preserveComments) {
         $lc->setPreserveComments($this->preserveComments);
     }
     if (method_exists($lc, 'setOptions') && count($this->options) > 0) {
         $lc->setOptions($this->options);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:23,代码来源:LessphpFilter.php

示例10: autoCompileLess

/**
 * Compile less to css. Creates a cache-file of the last compiled less-file.
 *
 * This code is originally from the manual of lessphp.
 *
 * @param string $inputFile  the filename of the less-file.
 * @param string $outputFile the filename of the css-file to be created.
 * @param array  $config     with configuration details.
 *
 * @return void
 */
function autoCompileLess($inputFile, $outputFile, $config)
{
    $cacheFile = $inputFile . ".cache";
    if (file_exists($cacheFile)) {
        $cache = unserialize(file_get_contents($cacheFile));
    } else {
        $cache = $inputFile;
    }
    $less = new lessc();
    // Add custom less functions
    if (isset($config['functions'])) {
        foreach ($config['functions'] as $key => $val) {
            $less->registerFunction($key, $val);
        }
    }
    // Add import dirs
    if (isset($config['imports'])) {
        foreach ($config['imports'] as $val) {
            $less->addImportDir($val);
        }
    }
    // Set output formatter
    if (isset($config['formatter'])) {
        $less->setFormatter($config['formatter']);
    }
    // Preserve comments
    if (isset($config['comments'])) {
        $less->setPreserveComments($config['comments']);
    }
    // Compile a new cache
    $newCache = $less->cachedCompile($cache);
    if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
        file_put_contents($cacheFile, serialize($newCache));
        file_put_contents($outputFile, $newCache['compiled']);
    }
}
开发者ID:fnlive,项目名称:Anax-MVC,代码行数:47,代码来源:style.php

示例11: filterLoad

 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $lc = new \lessc();
     if (basename(getcwd()) === 'public') {
         $lc->setVariable('__assetpath__', '"../"');
     } else {
         $lc->setVariable('__assetpath__', '""');
     }
     if ($root && $path) {
         $lc->importDir = dirname($root . '/' . $path);
     }
     foreach ($this->loadPaths as $loadPath) {
         $lc->addImportDir($loadPath);
     }
     if ($this->formatter) {
         $lc->setFormatter($this->formatter);
     }
     if (null !== $this->preserveComments) {
         $lc->setPreserveComments($this->preserveComments);
     }
     $asset->setContent($lc->parse($asset->getContent(), $this->presets));
 }
开发者ID:k4ml,项目名称:laravel-base,代码行数:24,代码来源:LessPhpFilter.php

示例12: parse_stylesheet

 /**
  * Lessify the stylesheet and return the href of the compiled file
  *
  * @param  string $src    Source URL of the file to be parsed
  * @param  string $handle An identifier for the file used to create the file name in the cache
  * @return string         URL of the compiled stylesheet
  */
 public function parse_stylesheet($src, $handle)
 {
     // we only want to handle .less files
     if (!preg_match('/\\.less(\\.php)?$/', preg_replace('/\\?.*$/', '', $src))) {
         return $src;
     }
     // get file path from $src
     if (!strstr($src, '?')) {
         $src .= '?';
     }
     // prevent non-existent index warning when using list() & explode()
     // Match the URL schemes between WP_CONTENT_URL and $src,
     // so the str_replace further down will work
     $src_scheme = parse_url($src, PHP_URL_SCHEME);
     $wp_content_url_scheme = parse_url(WP_CONTENT_URL, PHP_URL_SCHEME);
     if ($src_scheme != $wp_content_url_scheme) {
         $src = set_url_scheme($src, $wp_content_url_scheme);
     }
     list($less_path, $query_string) = explode('?', str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $src));
     $cache = $this->get_cached_file_data($handle);
     // vars to pass into the compiler - default @themeurl var for image urls etc...
     $this->vars['themeurl'] = '~"' . get_stylesheet_directory_uri() . '"';
     $this->vars['lessurl'] = '~"' . dirname($src) . '"';
     $this->vars = apply_filters('less_vars', $this->vars, $handle);
     // The overall "version" of the LESS file is all it's vars, src etc.
     $less_version = md5(serialize(array($this->vars, $src)));
     /**
      * Give the ability to disable always compiling the LESS with lessc()
      * and instead just use the $vars and $version of the LESS file to
      * dictate whether the LESS should be (re)generated.
      *
      * This means we don't need to run everything through the lessc() compiler
      * on every page load. The tradeoff is making a change in a LESS file will not
      * necessarily cause a (re)generation, one would need to bump the $ver param
      * on wp_enqueue_script() to cause that.
      */
     if (!get_option('wp_less_always_compile_less', true)) {
         if (!empty($cache['version']) && $cache['version'] === $less_version) {
             // restore query string it had if any
             $url = $cache['url'] . (!empty($query_string) ? "?{$query_string}" : '');
             $url = set_url_scheme($url, $src_scheme);
             return add_query_arg('ver', $less_version, $url);
         }
     }
     // automatically regenerate files if source's modified time has changed or vars have changed
     try {
         // initialise the parser
         if (!class_exists('lessc')) {
             return $url;
             //wp_die( 'the lessphp library is missing, aborting, run composer update' );
         }
         // If the cache or root path in it are invalid then regenerate
         if (empty($cache) || empty($cache['less']['root']) || !file_exists($cache['less']['root'])) {
             $cache = array('vars' => $this->vars, 'less' => $less_path);
         }
         if (empty($cache['url'])) {
             $cache['url'] = trailingslashit($this->get_cache_dir(false)) . "{$handle}.css";
         }
         // less config
         $less = new lessc();
         $less->setFormatter(apply_filters('less_compression', $this->compression));
         $less->setPreserveComments(apply_filters('less_preserve_comments', $this->preserve_comments));
         $less->setVariables($this->vars);
         // add directories to scan for imports
         $import_dirs = apply_filters('less_import_dirs', $this->import_dirs);
         if (!empty($import_dirs)) {
             foreach ((array) $import_dirs as $dir) {
                 $less->addImportDir($dir);
             }
         }
         // register and unregister functions
         foreach ($this->registered_functions as $name => $callable) {
             $less->registerFunction($name, $callable);
         }
         foreach ($this->unregistered_functions as $name) {
             $less->unregisterFunction($name);
         }
         // allow devs to mess around with the less object configuration
         do_action_ref_array('lessc', array(&$less));
         // $less->cachedCompile only checks for changed file modification times
         // if using the theme customiser (changed variables not files) then force a compile
         if ($this->vars !== $cache['vars']) {
             $force = true;
         } else {
             $force = false;
         }
         $force = apply_filters('less_force_compile', $force);
         $less_cache = $less->cachedCompile($cache['less'], $force);
         // if they have the same values but differing order, they wont match
         //sort( $cache['less'] );
         //sort( $less_cache );
         if (empty($cache) || empty($cache['less']['updated']) || md5($less_cache['compiled']) !== md5($cache['less']['compiled']) || $this->vars !== $cache['vars']) {
             // output css file name
//.........这里部分代码省略.........
开发者ID:TimeIncOSS,项目名称:wp-less,代码行数:101,代码来源:wp-less.class.php

示例13: compileLess

 protected function compileLess($string, $path)
 {
     require_once WF_ADMINISTRATOR . '/classes/lessc.inc.php';
     $less = new lessc();
     // add file directory
     $less->addImportDir($path);
     // add joomla media folder
     $less->addImportDir(JPATH_SITE . 'media');
     try {
         return $less->compile($string);
     } catch (Exception $e) {
         return "/* LESS file could not be compiled due to error - " . $e->getMessage() . " */";
     }
 }
开发者ID:creativeprogramming,项目名称:jce,代码行数:14,代码来源:packer.php

示例14: lessProcess

 /**
  * Processing less file.
  *
  * @param $path
  * @param string $cacheFolder
  * @return null|string
  * @throws \Exception
  */
 public function lessProcess($path, $cacheFolder = 'styles')
 {
     $output = null;
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     if (!$ext) {
         $path .= '.less';
     }
     $systemPath = $path;
     $segments = explode('/', $path);
     $lessFolder = ROOT . DS . 'webroot' . DS . 'less';
     list($plugin, $path) = $this->_View->pluginSplit($path, false);
     $webRoot = ROOT . DS . 'webroot' . DS;
     $isPlugin = Plugin::loaded($plugin);
     $this->_imageFull = WWW_ROOT . DS . 'img' . DS;
     //  Set data for plugin less.
     if ($plugin && $isPlugin) {
         $pluginPath = Plugin::path($plugin);
         $lessFolder = $pluginPath . 'webroot' . DS . 'less';
         $webRootPlg = $pluginPath . 'webroot' . DS;
         $this->_type = 'plugin:' . $plugin;
         $this->_imageFull = $webRootPlg . 'img' . DS;
     }
     $lessFile = $lessFolder . DS . $path;
     //  Set data for module less.
     if (strpos($segments[0], ':')) {
         list($type, $name) = explode(':', $segments[0]);
         if ($type == 'modules') {
             $modulePath = ROOT . DS . 'modules' . DS . $name . DS . 'assets' . DS;
             $lessFile = $modulePath . 'less' . DS . $segments[1];
             $this->_type = 'modules:' . $name;
             $this->_imageFull = $modulePath . 'img' . DS;
         }
     }
     if (file_exists($lessFile)) {
         $less = new \lessc();
         $fileHash = md5(serialize(md5_file($lessFile)));
         $cssFileName = $fileHash . '.css';
         $less->registerFunction('url', array($this, 'lessPhpUrl'));
         $less->addImportDir(Plugin::path('Union/Core') . 'webroot' . DS . 'less' . DS);
         if (!DEBUG) {
             $formatter = new \lessc_formatter_compressed();
             $less->setFormatter($formatter);
             $less->setPreserveComments(false);
             $cssFileName = $fileHash . '.min.css';
         }
         $updateFile = false;
         try {
             $cssFile = $webRoot . 'cache' . DS . $cacheFolder . DS . $cssFileName;
             if (file_exists($cssFile)) {
                 $cacheRes = fopen($cssFile, 'r');
                 $firstLine = fgets($cacheRes);
                 fclose($cacheRes);
                 if (!preg_match("#{$fileHash}#i", $firstLine)) {
                     $updateFile = true;
                 }
             } else {
                 $updateFile = true;
             }
             $output = '/cache/' . $cacheFolder . '/' . $cssFileName;
             if ($this->_lessCompile) {
                 $updateFile = true;
             }
             if ($updateFile) {
                 $css = $less->compileFile($lessFile);
                 $css = $this->_getLessFileComment($fileHash, $systemPath) . $css;
                 $file = new File($cssFile, true);
                 $file->write($css);
                 $file->close();
             }
         } catch (Exception $error) {
             die('<strong>' . __d('union_dev', 'Less Error:') . '</strong><br/><pre>' . $error->getMessage() . '</pre>');
         }
     }
     return $output;
 }
开发者ID:Cheren,项目名称:union,代码行数:83,代码来源:LessHelper.php

示例15: parse_stylesheet

 /**
  * Lessify the stylesheet and return the href of the compiled file
  *
  * @param  string $src    Source URL of the file to be parsed
  * @param  string $handle An identifier for the file used to create the file name in the cache
  * @return string         URL of the compiled stylesheet
  */
 public function parse_stylesheet($src, $handle)
 {
     // we only want to handle .less files
     if (!preg_match('/\\.less(\\.php)?$/', preg_replace('/\\?.*$/', '', $src))) {
         return $src;
     }
     // get file path from $src
     if (!strstr($src, '?')) {
         $src .= '?';
     }
     // prevent non-existent index warning when using list() & explode()
     // Match the URL schemes between WP_CONTENT_URL and $src,
     // so the str_replace further down will work
     $src_scheme = parse_url($src, PHP_URL_SCHEME);
     $wp_content_url_scheme = parse_url(WP_CONTENT_URL, PHP_URL_SCHEME);
     if ($src_scheme != $wp_content_url_scheme) {
         $src = set_url_scheme($src, $wp_content_url_scheme);
     }
     list($less_path, $query_string) = explode('?', str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $src));
     // output css file name
     $css_path = trailingslashit($this->get_cache_dir()) . "{$handle}.css";
     // automatically regenerate files if source's modified time has changed or vars have changed
     try {
         // initialise the parser
         $less = new lessc();
         // load the cache
         $cache_path = "{$css_path}.cache";
         if (file_exists($cache_path)) {
             $cache = unserialize(file_get_contents($cache_path));
         }
         // vars to pass into the compiler - default @themeurl var for image urls etc...
         $this->vars['themeurl'] = '~"' . get_stylesheet_directory_uri() . '"';
         $this->vars['lessurl'] = '~"' . dirname($src) . '"';
         $this->vars = apply_filters('less_vars', $this->vars, $handle);
         // If the cache or root path in it are invalid then regenerate
         if (empty($cache) || empty($cache['less']['root']) || !file_exists($cache['less']['root'])) {
             $cache = array('vars' => $this->vars, 'less' => $less_path);
         }
         // less config
         $less->setFormatter(apply_filters('less_compression', $this->compression));
         $less->setPreserveComments(apply_filters('less_preserve_comments', $this->preserve_comments));
         $less->setVariables($this->vars);
         // add directories to scan for imports
         $import_dirs = apply_filters('less_import_dirs', $this->import_dirs);
         if (!empty($import_dirs)) {
             foreach ((array) $import_dirs as $dir) {
                 $less->addImportDir($dir);
             }
         }
         // register and unregister functions
         foreach ($this->registered_functions as $name => $callable) {
             $less->registerFunction($name, $callable);
         }
         foreach ($this->unregistered_functions as $name) {
             $less->unregisterFunction($name);
         }
         // allow devs to mess around with the less object configuration
         do_action_ref_array('lessc', array(&$less));
         // $less->cachedCompile only checks for changed file modification times
         // if using the theme customiser (changed variables not files) then force a compile
         if ($this->vars !== $cache['vars']) {
             $force = true;
         } else {
             $force = false;
         }
         $less_cache = $less->cachedCompile($cache['less'], apply_filters('less_force_compile', $force));
         if (empty($cache) || empty($cache['less']['updated']) || $less_cache['updated'] > $cache['less']['updated'] || $this->vars !== $cache['vars']) {
             file_put_contents($cache_path, serialize(array('vars' => $this->vars, 'less' => $less_cache)));
             file_put_contents($css_path, $less_cache['compiled']);
         }
     } catch (exception $ex) {
         wp_die($ex->getMessage());
     }
     // restore query string it had if any
     $url = trailingslashit($this->get_cache_dir(false)) . "{$handle}.css" . (!empty($query_string) ? "?{$query_string}" : '');
     // restore original url scheme
     $url = set_url_scheme($url, $src_scheme);
     return add_query_arg('ver', $less_cache['updated'], $url);
 }
开发者ID:straczowski,项目名称:solawi_theme,代码行数:86,代码来源:wp-less.php


注:本文中的lessc::addImportDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。