本文整理汇总了PHP中lessc::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP lessc::parse方法的具体用法?PHP lessc::parse怎么用?PHP lessc::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lessc
的用法示例。
在下文中一共展示了lessc::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
public function boot(Application $app)
{
// Validate this params.
$this->validate($app);
// Define default formatter if not already set.
$formatter = isset($app['less.formatter']) ? $app['less.formatter'] : self::FORMATTER_CLASSIC;
$sources = $app['less.sources'];
$target = $app['less.target'];
$targetContent = '';
$needToRecompile = false;
!is_array($sources) and $sources = array($sources);
foreach ($sources as $source) {
if (!$needToRecompile) {
$needToRecompile = $this->targetNeedsRecompile($source, $target);
}
if ($needToRecompile) {
$handle = new \lessc($source);
$handle->setFormatter($formatter);
$targetContent .= $handle->parse();
}
}
if (isset($handle)) {
if ($targetContent) {
file_put_contents($target, $targetContent);
if (isset($app['less.target_mode'])) {
chmod($target, $app['less.target_mode']);
}
} else {
throw new \Exception("No content after parsing less source files. Please check your .less files");
}
}
}
示例2: process
/**
* Process asset content
*
* @param string $content
* @param Asset $asset
*
* @return string
*/
public static function process($content, Asset $asset)
{
// Set Less
$lc = new lessc();
$lc->importDir = dirname($asset->source_file()) . DIRECTORY_SEPARATOR;
return $lc->parse($content);
}
示例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;
}
示例4: parse_less_files
/**
* Parse all the less files resolving the dependencies.
*
* @return string
*/
public function parse_less_files(array $variables = null)
{
global $ai1ec_themes_controller;
// If no variables are passed i get them from the db
if (null === $variables) {
$variables = $this->db_adapter->get_data_from_config(self::DB_KEY_FOR_LESS_VARIABLES);
// If they are not set in the db, get them from file.
// this happen when the user switched the theme and triggered a new parse.
if (false === $variables) {
$variables = $this->get_less_variable_data_from_config_file(Ai1ec_Less_Factory::create_less_file_instance(Ai1ec_Less_File::USER_VARIABLES_FILE));
}
}
// convert the variables to key / value
$variables = $this->convert_less_variables_for_parsing($variables);
// Load the variable.less file to use
$this->load_less_variables_from_file();
foreach ($this->files as $file) {
$filename = '';
/*
* @var $file Ai1ec_Less_File
*/
try {
// Get the filename following our fallback convention
$filename = $file->locate_exact_file_to_load_in_theme_folders();
} catch (Ai1ec_File_Not_Found $e) {
// We let child themes ovverride properties of vortex.
// So there is no fallback for override and we can continue.
if ($file->get_name() !== 'override') {
throw $e;
} else {
// it's override, skip it.
continue;
}
}
// if the file is a css file, no need to parse it, just serve it as usual.
if (substr_compare($filename, '.css', -strlen('.css'), strlen('.css')) === 0) {
$this->parsed_css .= file_get_contents($filename);
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.
$css_to_parse = $this->unparsed_variable_file . file_get_contents($filename);
// Set the import dir for the file. This is important as
// dependencies will be resolved correctly
$this->lessc->importDir = dirname($filename);
// Set the font & img dirs
$active_theme_url = AI1EC_THEMES_URL . '/' . $ai1ec_themes_controller->active_template_url();
$variables['fontdir'] = '~"' . $active_theme_url . "/font\"";
$variables['imgdir'] = '~"' . $active_theme_url . "/img\"";
$variables['fontdir_default'] = '~"' . $this->default_theme_url . "/font\"";
$variables['imgdir_default'] = '~"' . $this->default_theme_url . "/img\"";
try {
$this->parsed_css .= $this->lessc->parse($css_to_parse, $variables);
} catch (Exception $e) {
throw $e;
}
}
return $this->parsed_css;
}
示例5: compileLessFiles
/**
* @return void
*/
public function compileLessFiles()
{
foreach ($this->findLessFiles() as $lessFile) {
$cssNameFile = self::getCssFileName($lessFile);
$less = new lessc($lessFile);
file_put_contents(sfConfig::get('sf_root_dir') . '/' . $this->getCssPaths() . '/' . $cssNameFile, $less->parse());
}
}
示例6: __invoke
/**
* @see PreFileFilter::__invoke()
*/
public static function __invoke($code, \Lohini\WebLoader\WebLoader $loader, $file = NULL)
{
if ($file === NULL || strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'less') {
return $code;
}
$filter = new \lessc($file);
return $filter->parse();
}
示例7: filterLoad
public function filterLoad(AssetInterface $asset)
{
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$lc = new \lessc();
if ($root && $path) {
$lc->importDir = dirname($root . '/' . $path);
}
$asset->setContent($lc->parse($asset->getContent()));
}
示例8: compile_less_string
public function compile_less_string($final_string)
{
require_once 'lessphp/lessc.inc.php';
$less_parser = new lessc();
try {
$final_string = $less_parser->parse($final_string);
} catch (Exception $e) {
}
return $final_string;
}
示例9: filterLoad
public function filterLoad(AssetInterface $asset)
{
$sourceUrl = $asset->getSourceUrl();
if ($sourceUrl && false === strpos($sourceUrl, '://')) {
$baseDir = self::isAbsolutePath($sourceUrl) ? '' : $this->baseDir . '/';
$sourceUrl = $baseDir . $sourceUrl;
}
$lc = new \lessc($sourceUrl);
// the way lessc::parse is implemented, the content wins if both url and content are defined
$asset->setContent($lc->parse($asset->getContent()));
}
示例10: input
/**
* Runs `lessc` against any files that match the configured extension.
*
* @param string $filename The name of the input file.
* @param string $input The content of the file.
* @return string
*/
public function input($filename, $input)
{
if (substr($filename, strlen($this->_settings['ext']) * -1) !== $this->_settings['ext']) {
return $input;
}
App::import('Vendor', 'lessc', array('file' => $this->_settings['path']));
if (!class_exists('lessc')) {
throw new Exception(sprintf('Cannot not load filter class "%s".', 'lessc'));
}
$lc = new lessc($filename);
return $lc->parse();
}
示例11: lessphp
/**
* Parse LESS markup using the lessphp library
*
* @param string $text
* @param string|array $import_dir
* @return string
*/
public static function lessphp($text, $import_dir = null)
{
// load library
require_once ICE_LIB_DIR . '/lessphp/less.inc.php';
// new parser instance
$less = new lessc();
// set import dir if applicable
if ($import_dir) {
$less->importDir = $import_dir;
}
// parse and return it
return $less->parse($text);
}
示例12: 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())));
}
示例13: 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));
}
示例14: render_file
protected static function render_file($path)
{
$cache_path = $path . '-cache.css';
if (!file_exists($cache_path) || filemtime($cache_path) < filemtime($path)) {
$out = parent::render_file($path);
$less = new lessc();
$less->importDir = dirname($path);
//$less->registerFunction('url', array('LessCompiler', 'url'));
$css = $less->parse($out);
$css = str_replace('url("/', 'url("' . URL_ROOT . '/', $css);
file_put_contents($cache_path, $css);
}
return file_get_contents($cache_path);
}
示例15: lessifyCss
public static function lessifyCss($css)
{
if (substr_count($css, '/*#!less*/') === 0) {
return $css;
}
$less = new lessc();
try {
$lesser = $less->parse($css);
} catch (Exception $e) {
Ajde_Exception_Log::logException($e);
return $css;
}
return $lesser;
}