标签: lessphp

使用PHP为Bootstrap 3编译更少的CSS

我知道PHP中有两个LessCSS编译器:

两者都声称与Bootstrap(版本3)兼容.然而,考虑到这三个方面的陡峭学习曲线,我正在努力获得任何进展.简而言之,我只想实现以下目标:

在PHP中一起编译多个.less文件:

  1. bootstrap.less
  2. my.less

编译单个文件leafo.net/lessphp很简单,我发现:

require_once 'lessc.inc.php'; 
$less = new lessc;
$less->checkedCompile("my.less", "mainless.css");
Run Code Online (Sandbox Code Playgroud)

但是我不确定该库是否适用于多个文件.(如果是这样,怎么可能/应该怎么做?)

我决定转到另一个库,它明确地演示了如何编译bootstrap : lessphp.gpeasy.com. 然而他们的示例片段让我挠头(从这里开始):

<?php
require 'less.php/LessCache.php';
$files = array( '/var/www/mysite/bootstrap.less' => '/mysite/' );
Less_Cache::$cache_dir = '/var/www/writable_folder';
$css_file_name = Less_Cache::Get( $to_cache );
$compiled = file_get_contents( '/var/www/writable_folder/'.$css_file_name );
Run Code Online (Sandbox Code Playgroud)

看着他们的其他例子之后,我意识到,$files$to_cache是一个错字:他们的意思是相同的变量.但在阅读文档并查看源代码后,我放弃了尝试解决以下字符串是否准确传达其目的:

  1. /var/www/mysite/bootstrap.less - 这是少编译的文件吗?
  2. /mysite/ - 这个是来做什么的??
  3. /var/www/writable_folder - 这是写入css的地方吗?

请有人给我一个可以使用PHP 编译bootstrap.lessmy.less进入css文件的片段吗?

php less lessphp twitter-bootstrap-3 less.php

10
推荐指数
1
解决办法
1万
查看次数

在@import之后覆盖Bootstrap LESS变量

我试图在编译之前覆盖一些bootstrap LESS变量

// Core variables
@import "variables.less";

// Trying to override @white from variables.less
@white: #de1de1;

// other bootstrap @imports....
Run Code Online (Sandbox Code Playgroud)

上面的代码没有覆盖@white,但如果我@white在variables.less文件的末尾添加,它可以正常工作.

看来变量只能在同一个文件中覆盖.但这对我来说没有意义,因为我认为LESS没有这样的工作.例如,其他@import文件(上面的代码中省略)使用该@white变量.如果他们能够在variables.less文件之外使用它,为什么我不能在文件外覆盖它?

我使用Less Php 0.3.9来编译我的代码.

注意:我刚刚尝试了以下代码:

// Core variables
@import "variables.less";
@import "variables-custom.less";
Run Code Online (Sandbox Code Playgroud)

现在值@white取自variables-custom.less(这有点解决了我的问题).它仍然无法解释为什么我的原始代码不起作用.会很感激的答案.

php less twitter-bootstrap lessphp

9
推荐指数
1
解决办法
7673
查看次数

覆盖LESS变量

我有以下堆栈:

  1. Symfony2的
  2. 安装了lessphp过滤器的Twig.
  3. Twitter Boostrap

在base.css我有:

// base.less
@import '/path/to/bootstrap.less'
@linkColor: 13px;
Run Code Online (Sandbox Code Playgroud)

变量名称根本不重要.它可以是bootstrap中使用的任何其他变量.它只是没有被覆盖.但是,如果我将变量放入单独的.less文件并将其导入base.less,一切都按预期工作:

// base.less
@import '/path/to/bootstrap.less'
@import '/path/to/variables.less'
Run Code Online (Sandbox Code Playgroud)

// variables.less
@linkColor: 13px;
Run Code Online (Sandbox Code Playgroud)

为什么这样做而另一个没有?查找文档(less/lessphp)但找不到与此相关的任何内容.(或者我不知道在哪里看).

有人能解释为什么会这样吗?

less symfony twitter-bootstrap lessphp

7
推荐指数
2
解决办法
2275
查看次数

assetic:dump失败,显示".pull-right is undefined:line:60"

我试图在本地安装glyphicons,而不是从CDN(已经停止显示它们,因为我没有调查的原因)拉出来.现在运行assetic:dump导致异常我不知道如何修复:

me@server:/var/www/blah$ php app/console assetic:dump -vvv
Dumping all dev assets.
Debug mode is on.

20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular.eot
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.eot
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular_glyphicons-halflings-regular_1.eot
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.eot
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular.svg
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.svg
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular_glyphicons-halflings-regular_1.svg
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.svg
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular.ttf
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.ttf
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular_glyphicons-halflings-regular_1.ttf
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.ttf
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular.woff
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff
20:26:32 [file+] /var/www/blah/app/../web/fonts/glyphicons-halflings-regular_glyphicons-halflings-regular_1.woff
        /var/www/blah/app/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff
20:26:32 [file+] /var/www/blah/app/../web/css/bootstrap.css
        /var/www/blah/app/../vendor/twbs/bootstrap/less/bootstrap.less

  [Exception]
  .pull-right is undefined: line: 60

Exception trace:
 () at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:3465
 lessc_parser->throwError() at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:2008
 lessc->throwError() at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:685
 lessc->compileProp() at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:282
 lessc->compileProps() at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:220
 lessc->compileCSSBlock() at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:194
 lessc->compileBlock() at /var/www/blah/vendor/leafo/lessphp/lessc.inc.php:656
 lessc->compileProp() …
Run Code Online (Sandbox Code Playgroud)

symfony assetic lessphp symfony-2.3 twitter-bootstrap-3

0
推荐指数
1
解决办法
1497
查看次数