[![Continuous Integration](https://github.com/wikimedia/less.php/workflows/PHP%20Test/badge.svg)](https://github.com/wikimedia/less.php/actions)
[Less.php](http://lessphp.typesettercms.com)
========
This is the Wikimedia fork of a PHP port of the official LESS processor <http://lesscss.org>.
* [About](#about)
* [Installation](#installation)
* [Basic Use](#basic-use)
* [Caching](#caching)
* [Source Maps](#source-maps)
* [Command Line](#command-line)
* [Integration with other projects](#integration-with-other-projects)
* [Transitioning from Leafo/lessphp](#transitioning-from-leafolessphp)
* [Credits](#credits)
About
---
The code structure of less.php mirrors that of the official processor which helps us ensure compatibility and allows for easy maintenance.
Please note, there are a few unsupported LESS features:
- Evaluation of JavaScript expressions within back-ticks (for obvious reasons).
- Definition of custom functions.
Installation
---
You can install the library with Composer or manually.
#### Composer
1. [Install Composer](https://getcomposer.org/download/)
2. Run `composer require wikimedia/less.php`
#### Manually From Release
Step 1. [Download a release](https://github.com/wikimedia/less.php/releases) and upload the PHP files to your server.
Step 2. Include the library:
```php
require_once '[path to less.php]/lib/Less/Autoloader.php';
Less_Autoloader::register();
```
Basic Use
---
#### Parsing Strings
```php
$parser = new Less_Parser();
$parser->parse( '@color: #4D926F; #header { color: @color; } h2 { color: @color; }' );
$css = $parser->getCss();
```
#### Parsing LESS Files
The parseFile() function takes two arguments:
1. The absolute path of the .less file to be parsed
2. The url root to prepend to any relative image or @import urls in the .less file.
```php
$parser = new Less_Parser();
$parser->parseFile( '/var/www/mysite/bootstrap.less', 'http://example.com/mysite/' );
$css = $parser->getCss();
```
#### Handling Invalid LESS
An exception will be thrown if the compiler encounters invalid LESS.
```php
try{
$parser = new Less_Parser();
$parser->parseFile( '/var/www/mysite/bootstrap.less', 'http://example.com/mysite/' );
$css = $parser->getCss();
}catch(Exception $e){
$error_message = $e->getMessage();
}
```
#### Parsing Multiple Sources
less.php can parse multiple sources to generate a single CSS file.
```php
$parser = new Less_Parser();
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$parser->parse( '@color: #4D926F; #header { color: @color; } h2 { color: @color; }' );
$css = $parser->getCss();
```
#### Getting Info About The Parsed Files
less.php can tell you which .less files were imported and parsed.
```php
$parser = new Less_Parser();
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$css = $parser->getCss();
$imported_files = $parser->allParsedFiles();
```
#### Compressing Output
You can tell less.php to remove comments and whitespace to generate minimized CSS files.
```php
$options = array( 'compress'=>true );
$parser = new Less_Parser( $options );
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$css = $parser->getCss();
```
#### Getting Variables
You can use the getVariables() method to get an all variables defined and
their value in a php associative array. Note that LESS has to be previously
compiled.
```php
$parser = new Less_Parser;
$parser->parseFile( '/var/www/mysite/bootstrap.less');
$css = $parser->getCss();
$variables = $parser->getVariables();
```
#### Setting Variables
You can use the ModifyVars() method to customize your CSS if you have variables stored in PHP associative arrays.
```php
$parser = new Less_Parser();
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$parser->ModifyVars( array('font-size-base'=>'16px') );
$css = $parser->getCss();
```
#### Import Directories
By default, less.php will look for @imports in the directory of the file passed to parseFile().
If you're using parse() or if @imports reside in different directories, you can tell less.php where to look.
```php
$directories = array( '/var/www/mysite/bootstrap/' => '/mysite/bootstrap/' );
$parser = new Less_Parser();
$parser->SetImportDirs( $directories );
$parser->parseFile( '/var/www/mysite/theme.less', '/mysite/' );
$css = $parser->getCss();
```
Caching
---
Compiling LESS code into CSS is a time consuming process, caching your results is highly recommended.
#### Caching CSS
Use the Less_Cache class to save and reuse the results of compiled LESS files.
This method will check the modified time and size of each LESS file (including imported files) and regenerate a new CSS file when changes are found.
Note: When changes are found, this method will return a different file name for the new cached content.
```php
$less_files = array( '/var/www/mysite/bootstrap.less' => '/mysite/' );
$options = array( 'cache_dir' => '/var/www/writable_folder' );
$css_file_name = Less_Cache::Get( $less_files, $options );
$compiled = file_get_contents( '/var/www/writable_folder/'.$css_file_name );
```
#### Caching CSS With Variables
Passing options to Less_Cache::Get()
```php
$less_files = array( '/var/www/mysite/bootstrap.less' => '/mysite/' );
$options = array( 'cache_dir' => '/var/www/writable_folder' );
$variables = array( 'width' => '100px' );
$css_file_name = Less_Cache::Get( $less_files, $options, $variables );
$compiled = file_get_contents( '/var/www/writable_folder/'.$css_file_name );
```
#### Parser Caching
less.php will save serialized parser data for each .less file if a writable folder is passed to the SetCacheDir() method.
Note: This feature only caches intermediate parsing results to improve the performance of repeated CSS generation.
Your application should cache any CSS generated by less.php.
```php
$options = array('cache_dir'=>'/var/www/writable_folder');
$parser = new Less_Parser( $options );
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$css = $parser->getCss();
```
You can specify the caching technique used by changing the ```cache_method``` option. Supported methods are:
* ```php```: Creates valid PHP files which can be included without any changes (default method).
* ```var_export```: Like "php", but using PHP's ```var_export()``` function without any optimizations.
It's recommended to use "php" instead.
* ```serialize```: Faster, but pretty memory-intense.
* ```callback```: Use custom callback functions to implement your own caching method. Give the "cache_callback_get" and
"cache_callback_set" options with callables (see PHP's ```call_user_func()``` and ```is_callable()``` functions). less.php
will pass the parser object (class ```Less_Parser```), the path to the parsed .less file ("/some/path/to/file.less") and
an identifier that will change every time the .less file is modified. The ```get``` callback must return the ruleset
(an array with ```Less_Tree``` objects) provided as fourth parameter of the ```set``` callback. If something goes wrong,
return ```NULL``` (cache doesn't exist) or ```FALSE```.
Source Maps
---
Less.php supports v3 sourcemaps
#### Inline
The sourcemap will be appended to the generated CSS file.
```php
$options = array( 'sourceMap' => true );
$parser = new Less_Parser($options);
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$css = $parser->getCss();
```
#### Saving to Map File
```php
$options = array(
'sourceMap' => true,
'sourceMapWriteTo' => '/var/www/mysite/writable_folder/filename.map',
'sourceMapURL' => '/mysite/writable_folder/filename.map',
);
$parser = new Less_Parser($options);
$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' );
$css = $parser->getCss();
```
Command li
没有合适的资源?快使用搜索试试~ 我知道了~
【WordPress主题】2022年最新版完整功能demo+插件v2.1.0.zip
共556个文件
php:238个
less:93个
css:79个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 90 浏览量
2022-04-07
15:58:30
上传
评论
收藏 10.02MB ZIP 举报
温馨提示
"【WordPress主题】2022年最新版完整功能demo+插件v2.1.0 Cleanstart - Corporate Business WordPress Theme CleanStart - 公司业务WordPress主题" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、opencart主题、PHP项目源码、安卓项目源码、ios项目源码,更有超10000个资源可供选择,如有需要请站内联系。
资源推荐
资源详情
资源评论
收起资源包目录
【WordPress主题】2022年最新版完整功能demo+插件v2.1.0.zip (556个子文件)
Less.php.combine 243B
Less.php.combine 243B
style.css 127KB
bootstrap.css 124KB
bootstrap.min.css 98KB
cleanstart_style.min.css 83KB
cleanstart_custom_bootstrap.css 71KB
animate.css 58KB
font-awesome.css 28KB
woocommerce.css 22KB
font-awesome.min.css 21KB
bootstrap-theme.css 15KB
bootstrap-theme.min.css 13KB
mainmenu.css 9KB
imagelightbox.css 7KB
twentytwenty.css 6KB
pace-theme-bounce.css 5KB
pace-theme-bounce.tmpl.css 5KB
pace-theme-center-atom.css 4KB
pace-theme-center-atom.tmpl.css 4KB
flexslider_original.css 4KB
flexslider_original.css 4KB
flexslider.css 4KB
flexslider.css 4KB
simpletextrotator.css 3KB
pace-theme-mac-osx.tmpl.css 3KB
pace-theme-mac-osx.css 3KB
pace-theme-barber-shop.css 3KB
pace-theme-barber-shop.tmpl.css 3KB
pace-theme-flash.tmpl.css 2KB
pace-theme-flash.css 2KB
pace-theme-center-circle.css 2KB
pace-theme-center-circle.tmpl.css 2KB
pace-theme-loading-bar.css 2KB
pace-theme-loading-bar.tmpl.css 2KB
pace-theme-corner-indicator.css 2KB
style.css 2KB
pace-theme-corner-indicator.tmpl.css 2KB
colors.css 2KB
icon-picker.css 2KB
site_demos.css 1KB
pace-theme-center-radar.css 1KB
pace-theme-center-radar.tmpl.css 1KB
mixins.css 1KB
misc.css 1KB
pace-theme-center-simple.css 1KB
pace-theme-center-simple.tmpl.css 1KB
attributes.css 1KB
builtins.css 1KB
style.css 1003B
media.css 999B
math.css 997B
import.css 840B
keyframes.css 816B
pattern_matching.css 792B
pace-theme-flat-top.css 749B
pace-theme-big-counter.css 741B
mixin_merging.css 704B
nested.css 693B
pace-theme-flat-top.tmpl.css 677B
pace-theme-big-counter.tmpl.css 671B
pace-theme-fill-left.css 516B
pace-theme-fill-left.tmpl.css 460B
guards.css 440B
variables.css 405B
ie.css 385B
pace-theme-minimal.css 374B
compile_on_mixin.css 366B
directives.css 363B
interpolation.css 343B
font_family.css 340B
arity.css 332B
escape.css 308B
pace-theme-minimal.tmpl.css 302B
selector_expressions.css 255B
nesting.css 226B
accessors.css 217B
scopes.css 134B
mixin_functions.css 114B
hacks.css 64B
hi.css 36B
mixin_merging.less.disable 892B
accessors.less.disable 585B
fontawesome-webfont.eot 55KB
glyphicons-halflings-regular.eot 20KB
.gitignore 79B
favicon.ico 31KB
ignore_prefixes 26B
ignore_prefixes 26B
404.jpg 53KB
vc_template_about_us.jpg 5KB
vc_template_services.jpg 4KB
vc_template_contact.jpg 4KB
vc_template_home.jpg 4KB
video.js 1.76MB
video.min.js 465KB
jquery-1.10.2.min.js 91KB
cleanstart_libs.js 64KB
jquery.flexslider.js 56KB
bootstrap.js 56KB
共 556 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Lee达森
- 粉丝: 969
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功