• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Less_Parser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: filterLoad

 /**
  * Filters an asset after it has been loaded.
  *
  * @param  \Assetic\Asset\AssetInterface  $asset
  * @return void
  */
 public function filterLoad(AssetInterface $asset)
 {
     $max_nesting_level = ini_get('xdebug.max_nesting_level');
     $memory_limit = ini_get('memory_limit');
     if ($max_nesting_level && $max_nesting_level < 200) {
         ini_set('xdebug.max_nesting_level', 200);
     }
     if ($memory_limit && $memory_limit < 256) {
         ini_set('memory_limit', '256M');
     }
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $dirs = array();
     $lc = new \Less_Parser(array('compress' => true));
     if ($root && $path) {
         $dirs[] = dirname($root . '/' . $path);
     }
     foreach ($this->loadPaths as $loadPath) {
         $dirs[] = $loadPath;
     }
     $lc->SetImportDirs($dirs);
     $url = parse_url($this->getRequest()->getUriForPath(''));
     $absolutePath = str_replace(public_path(), '', $root);
     if (isset($url['path'])) {
         $absolutePath = $url['path'] . $absolutePath;
     }
     $lc->parseFile($root . '/' . $path, $absolutePath);
     $asset->setContent($lc->getCss());
 }
开发者ID:cartalyst,项目名称:assetic-filters,代码行数:35,代码来源:LessphpFilter.php


示例2: process

 /**
  * @param string $sourceFilePath
  * @return string
  */
 public function process($sourceFilePath)
 {
     $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
     try {
         $parser = new \Less_Parser($options);
         $parser->parseFile($sourceFilePath, '');
         return $parser->getCss();
     } catch (\Exception $e) {
         $messagePrefix = 'CSS compilation from LESS ';
         $this->logger->critical($messagePrefix . $e->getMessage());
         return $messagePrefix . $e->getMessage();
     }
 }
开发者ID:kid17,项目名称:magento2,代码行数:17,代码来源:Oyejorge.php


示例3: CompareFile

 /**
  * Compare the parser results with the expected css
  *
  */
 function CompareFile($expected_file)
 {
     $less_file = $this->TranslateFile($expected_file);
     $expected_css = trim(file_get_contents($expected_file));
     // Check with standard parser
     echo "\n  " . basename($expected_file);
     echo "\n    - Standard Compiler";
     $parser = new Less_Parser();
     $parser->parseFile($less_file);
     $css = $parser->getCss();
     $css = trim($css);
     $this->assertEquals($expected_css, $css);
     // Check with cache
     if ($this->cache_dir) {
         $options = array('cache_dir' => $this->cache_dir);
         $files = array($less_file => '');
         echo "\n    - Regenerating Cache";
         $css_file_name = Less_Cache::Regen($files, $options);
         $css = file_get_contents($this->cache_dir . '/' . $css_file_name);
         $css = trim($css);
         $this->assertEquals($expected_css, $css);
         // Check using the cached data
         echo "\n    - Using Cache";
         $css_file_name = Less_Cache::Get($files, $options);
         $css = file_get_contents($this->cache_dir . '/' . $css_file_name);
         $css = trim($css);
         $this->assertEquals($expected_css, $css);
     }
 }
开发者ID:Flesh192,项目名称:magento,代码行数:33,代码来源:FixturesTest.php


示例4: CssPreprocessor

function CssPreprocessor($content, $type)
{
    if ($type == 'css') {
    } else {
        if ($type == 'less') {
            try {
                $parser = new Less_Parser();
                $parser->parse($content);
                $content = $parser->getCss();
            } catch (Exception $e) {
                var_dump($e->getMessage());
            }
        } else {
            if ($type == 'sass') {
                $scss = new scssc();
                $content = $scss->compile($content);
            } else {
                if ($type == 'stylus') {
                    $stylus = new Stylus();
                    $content = $stylus->fromString($content)->toString();
                }
            }
        }
    }
    return $content;
}
开发者ID:juijs,项目名称:store.jui.io,代码行数:26,代码来源:bootstrap.php


示例5: parse_less

function parse_less($filename, $file)
{
    global $less_file, $is_dev;
    $options = array();
    if ($is_dev) {
        $options['sourceMap'] = true;
        $options['sourceMapWriteTo'] = '../css/' . $file . '.map';
        $options['sourceMapURL'] = '../css/' . $file . '.map';
    } else {
        $options['compress'] = true;
    }
    $options['cache_dir'] = '../css_cache';
    try {
        $parser = new Less_Parser($options);
        $parser->parseFile($less_file, '../css/');
        ob_start();
        echo $parser->getCss();
        $css = ob_get_contents();
        ob_end_clean();
        header("Content-type: text/css");
        @file_put_contents('../css/' . $file . '.css', $css);
        return $css;
    } catch (Exception $e) {
        header("Content-type: text/css");
        echo '/* LESS ERROR : ' . "\n\n" . $e->getMessage() . "\n\n" . '*/';
        showError($file . '.less');
    }
}
开发者ID:CamilleBouliere,项目名称:LESS-PHP---Out-of-the-box,代码行数:28,代码来源:less_compiler.php


示例6: getFile

 /**
  * @return string
  */
 public function getFile()
 {
     // TODO use caching from plugin instead of custom caching to avoid import errors
     // Create less parser
     $parser = new \Less_Parser();
     try {
         // Parse file using direct file path
         $parser->parseFile($this->file['path'], '/');
         // Turn less into css
         $contents = $parser->getCss();
         // get all parsed files
         $parsed_files = $parser::AllParsedFiles();
         // reformat to make them the same format as the scss result parsed files list
         $new_list = array();
         foreach ($parsed_files as $parse_file) {
             $new_list[$parse_file] = filemtime($parse_file);
         }
         // store the new list
         $this->cache->save($this->file['hash'] . "parsed_files", $new_list);
     } catch (\Exception $e) {
         return false;
     }
     // fix absolute paths
     $contents = str_replace(array('../'), str_replace(ROOT, "", dirname($this->file['path'])) . '/../', $contents);
     // return css
     return $contents;
 }
开发者ID:Crecket,项目名称:dependency-manager,代码行数:30,代码来源:Less.php


示例7: processContent

 /**
  * @inheritdoc
  * @throws ContentProcessorException
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         $tmpFilePath = $this->temporaryFile->createFile($path, $content);
         gc_disable();
         $parser->parseFile($tmpFilePath, '');
         $content = $parser->getCss();
         gc_enable();
         if (trim($content) === '') {
             $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
             $this->logger->critical($errorMessage);
             throw new ContentProcessorException(new Phrase($errorMessage));
         }
         return $content;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         throw new ContentProcessorException(new Phrase($errorMessage));
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:30,代码来源:Processor.php


示例8: compile

 public function compile($source, $pathname)
 {
     $less = new \Less_Parser();
     $less->SetImportDirs(array(dirname($pathname) => './'));
     $less->parse($source);
     return $less->getCss();
 }
开发者ID:nagumo,项目名称:Phest,代码行数:7,代码来源:CompilerLess.php


示例9: compile_botstrap_less_adm

 function compile_botstrap_less_adm($theme, $input, $output = '', $compress = false)
 {
     global $cfg;
     $output = empty($output) ? $input : $output;
     $output = $cfg['themes_dir'] . '/admin/' . $theme . '/css/' . $output . '.css';
     $input = $cfg['themes_dir'] . '/admin/' . $theme . '/less/' . $input . '.less';
     if (file_exists($output) && file_exists($input)) {
         $filetimecss = filemtime($output);
         $filetimeless = filemtime($input);
         //	cot_print('css', cot_date('datetime_full', $filetimecss), 'less', cot_date('datetime_full', $filetimeless), cot_date('datetime_full'), $filetimecss > $filetimeless);
         if ($filetimecss > $filetimeless) {
             return false;
         } else {
             unlink($output);
             //	cot_print("deleted");
         }
     }
     $options = array('relativeUrls' => false);
     if ($compress) {
         $options['compress'] = true;
     }
     $parser = new Less_Parser($options);
     $parser->SetImportDirs(array($cfg['themes_dir'] . '/admin/' . $theme . '/less' => $cfg['themes_dir'] . '/admin/' . $theme . '/less', $cfg['plugins_dir'] . "/bootstrap/bootstrap/less" => $cfg['plugins_dir'] . "/bootstrap/bootstrap/less"));
     $parser->parseFile($input);
     $css = $parser->getCss();
     if (!file_exists($cfg['themes_dir'] . '/admin/' . $theme . '/css')) {
         mkdir($cfg['themes_dir'] . '/admin/' . $theme . '/css');
     }
     file_put_contents($output, $css);
     return true;
 }
开发者ID:esclkm,项目名称:cot-admintheme-comaterial,代码行数:31,代码来源:comaterial.php


示例10: process

 /**
  * @param string $sourceFilePath
  * @return string
  */
 public function process($sourceFilePath)
 {
     $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
     $parser = new \Less_Parser($options);
     $parser->parseFile($sourceFilePath, '');
     return $parser->getCss();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:Oyejorge.php


示例11: Cache

 public static function Cache(&$less_files, $parser_options = array())
 {
     //prepare the processor
     if (!class_exists('Less_Parser')) {
         include_once 'Less.php';
     }
     $parser = new Less_Parser($parser_options);
     $parser->SetCacheDir(self::$cache_dir);
     $parser->SetImportDirs(self::$import_dirs);
     // combine files
     try {
         foreach ($less_files as $file_path => $uri_or_less) {
             //treat as less markup if there are newline characters
             if (strpos($uri_or_less, "\n") !== false) {
                 $parser->Parse($uri_or_less);
                 continue;
             }
             $parser->ParseFile($file_path, $uri_or_less);
         }
         $compiled = $parser->getCss();
     } catch (Exception $e) {
         self::$error = $e;
         return false;
     }
     $less_files = $parser->allParsedFiles();
     return $compiled;
 }
开发者ID:Tommar,项目名称:remate,代码行数:27,代码来源:lesscache.php


示例12: compileFile

 /**
  * @param string $themeName
  * @param string $lessFile
  * @return string
  */
 public function compileFile($themeName, $lessFile)
 {
     $model = Model::instance();
     $theme = $model->getTheme($themeName);
     $options = $theme->getOptionsAsArray();
     $configModel = ConfigModel::instance();
     $config = $configModel->getAllConfigValues($themeName);
     $less = "@import '{$lessFile}';";
     $less .= $this->generateLessVariables($options, $config);
     $css = '';
     try {
         require_once ipFile('Ip/Lib/less.php/Less.php');
         $themeDir = ipFile('Theme/' . $themeName . '/assets/');
         $ipContentDir = ipFile('Ip/Internal/Core/assets/ipContent/');
         // creating new context to pass theme assets directory dynamically to a static callback function
         $context = $this;
         $callback = function ($parseFile) use($context, $themeDir) {
             return $context->overrideImportDirectory($themeDir, $parseFile);
         };
         $parserOptions = array('import_callback' => $callback, 'cache_dir' => ipFile('file/tmp/less/'), 'relativeUrls' => false, 'sourceMap' => true);
         $parser = new \Less_Parser($parserOptions);
         $directories = array($themeDir => '', $ipContentDir => '');
         $parser->SetImportDirs($directories);
         $parser->parse($less);
         $css = $parser->getCss();
         $css = "/* Edit {$lessFile}, not this file. */" . "\n" . $css;
     } catch (\Exception $e) {
         ipLog()->error('Less compilation error: Theme - ' . $e->getMessage());
     }
     return $css;
 }
开发者ID:Umz,项目名称:ImpressPages,代码行数:36,代码来源:LessCompiler.php


示例13: Compile

 public function Compile($less_files, $out_name, $modify_vars = [], $bootstrap_less = "mixins", $mediawiki_less = "mixins")
 {
     $lessphp = new \Less_Parser($this->cache_dir);
     switch ($bootstrap_less) {
         case "mixins":
             $lessphp->parseFile($this->bootstrap_dir . "/variables.less", "");
             $lessphp->parseFile(__DIR__ . "/custom_variables.less", "");
             $lessphp->parseFile($this->bootstrap_mixin, $this->bootstrap_mixin_url);
             break;
         case "full":
             $lessphp->SetImportDirs([$this->bootstrap_dir]);
             $lessphp->parseFile(__DIR__ . "/bootstrap.less", "");
             break;
         case "off":
             break;
     }
     switch ($mediawiki_less) {
         case "mixins":
             $lessphp->parseFile($this->mediawiki_mixin, $this->mediawiki_mixin_url);
             break;
         case "off":
             break;
     }
     foreach ($less_files as $less => $url) {
         $lessphp->parseFile($less, $url);
     }
     if ($modify_vars) {
         $lessphp->ModifyVars($modify_vars);
     }
     $css = $lessphp->getCss();
     file_put_contents($out_name, $css);
 }
开发者ID:iamchenxin,项目名称:bootstraplessc,代码行数:32,代码来源:BootstrapLessc.php


示例14: compile

 /**
  * Convert LESS to CSS
  * @param string $string
  * @return string
  */
 public static function compile($string)
 {
     self::init();
     $parser = new \Less_Parser();
     $parser->SetOptions(['compress' => !Debugger::isEnabled()]);
     $parser->parse($string);
     return $parser->getCss();
 }
开发者ID:difra-org,项目名称:difra,代码行数:13,代码来源:Less.php


示例15: compile

 public static function compile($source, $path, $todir, $importdirs)
 {
     $parser = new Less_Parser();
     $parser->SetImportDirs($importdirs);
     $parser->parse($source, CANVASLess::relativePath($todir, dirname($path)) . basename($path));
     $output = $parser->getCss();
     return $output;
 }
开发者ID:shamsbd71,项目名称:canvas-framework,代码行数:8,代码来源:less.php


示例16: compile

 /**
  * Compile the asset and return true on success
  *
  * @throws \Exception
  */
 protected function compile()
 {
     require_once TL_ROOT . '/' . $this->getParserPath();
     $parser = new \Less_Parser();
     $parser->parseFile(TL_ROOT . '/' . $this->getSourceFile()->path);
     $file = $this->getTemporaryFile();
     $file->write($parser->getCss());
 }
开发者ID:codefog,项目名称:contao-assets_manager,代码行数:13,代码来源:LessAsset.php


示例17: compile

 public static function compile($source, $importdirs)
 {
     $parser = new Less_Parser();
     $parser->SetImportDirs($importdirs);
     $parser->parse($source);
     $output = $parser->getCss();
     return $output;
 }
开发者ID:grlf,项目名称:eyedock,代码行数:8,代码来源:less.php


示例18: generateCombinedBootstrapFontAwesomeCSS

 /**
  * This function generates from the customized bootstrap.less und font-awesome.less a combined css file
  *
  * @param string|null $writeTo Where to dump the generated file.
  */
 public static function generateCombinedBootstrapFontAwesomeCSS($writeTo = null)
 {
     // Also change build.xml if you change the default writeTo path here!
     $writeTo = is_string($writeTo) ? $writeTo : 'src/web/bootstrap-font-awesome.css';
     $parser = new \Less_Parser();
     $parser->setOptions(array('relativeUrls' => false, 'compress' => true));
     $parser->parseFile('src/style/bootstrap-font-awesome.less');
     file_put_contents($writeTo, $parser->getCss());
 }
开发者ID:Silwereth,项目名称:core,代码行数:14,代码来源:LessGenerator.php


示例19: execute

 /**
  * Execute this filter.
  *
  * @param FilterChain The filter chain.
  *
  * @return void
  *
  * @throws <b>FilterException</b> If an erro occurs during execution.
  */
 public function execute($filterChain)
 {
     static $loaded;
     if (!isset($loaded)) {
         // load the filter
         $start_time = microtime(true);
         $need_to_rebuild = true;
         $loaded = true;
         $css_file = $this->getParameter('css_file', null);
         $less_file = $this->getParameter('less_file', null);
         if (!is_null($css_file) && !is_null($less_file)) {
             if (file_exists($less_file)) {
                 if (file_exists($css_file)) {
                     if (filemtime($css_file) >= filemtime($less_file)) {
                         // css file is newer, so skip to the next filter
                         $filterChain->execute();
                         $need_to_rebuild = false;
                     }
                 }
                 if ($need_to_rebuild) {
                     if (file_exists(MO_WEBAPP_DIR . "/vendor/oyejorge/less.php/lib/Less/Autoloader.php")) {
                         \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . sprintf("Building new CSS file because date is %s and less file date is %s", filemtime($css_file), filemtime($less_file)));
                         try {
                             require_once MO_WEBAPP_DIR . "/vendor/oyejorge/less.php/lib/Less/Autoloader.php";
                             \Less_Autoloader::register();
                             $parser = new \Less_Parser(array('compress' => true));
                             $parser->parseFile($less_file, '/');
                             $css = $parser->getCss();
                             file_put_contents($css_file, $css);
                             \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . sprintf("Generated less file in %ss", number_format(microtime(true) - $start_time, 4)));
                         } catch (\Exception $e) {
                             \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . $e->getMessage());
                         }
                         // completed the caching, move on to the next filter
                         $filterChain->execute();
                     } else {
                         // we already loaded this filter, skip to the next filter
                         \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . "Missing Less vendor library, use composer require oyejorge/less.php");
                         $filterChain->execute();
                     }
                 }
             } else {
                 // less file doesn't exist so skip to the next filter
                 \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . "Cannot find less file to compile: " . $less_file);
                 $filterChain->execute();
             }
         } else {
             // less file or css file is not defined, so skip to the next filter
             \Mojavi\Logging\LoggerManager::error(__METHOD__ . " :: " . "less_file or css_file parameter is not defined");
             $filterChain->execute();
         }
     } else {
         // we already loaded this filter, skip to the next filter
         $filterChain->execute();
     }
 }
开发者ID:hiveclick,项目名称:mojavi,代码行数:65,代码来源:LessFilter.php


示例20: main

 /**
  * main() method.
  *
  * @return bool|int Success or error code.
  */
 public function main()
 {
     $config = ['custom_bootstrap_less' => Configure::read('App.webroot') . '/css/vendor/bootstrap/less/custom_bootstrap.less', 'target_css' => Configure::read('App.webroot') . '/css/vendor/bootstrap/css/bootstrap_custom.css', 'compress' => false];
     $this->out('Using custom bootstrap.less: ' . $config['custom_bootstrap_less']);
     $lessPhpOptions = ['compress' => $config['compress']];
     $parser = new \Less_Parser($lessPhpOptions);
     $parser->parseFile($config['custom_bootstrap_less']);
     file_put_contents($config['target_css'], $parser->getCss());
     $this->out('Wrote compiled file to: ' . $config['target_css']);
 }
开发者ID:codekanzlei,项目名称:cake-bootstrap3,代码行数:15,代码来源:BuildBootstrapShell.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Lesson类代码示例发布时间:2022-05-23
下一篇:
PHP Less_Environment类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap