notrix / compass-elephant
一个用于使用PHP管理compass项目的库
Requires
- php: >=5.3.3
- symfony/finder: ~2.1
- symfony/process: ~2.1
Requires (Dev)
- phpunit/phpunit: ~4.3
README
Compass二进制文件的PHP包装器
要求
- php >= 5.3
- 已安装compass的*nix系统
依赖项
用于测试
安装
composer
要使用composer安装CompassElephant,你只需在你的项目根目录中创建一个composer.json文件,并添加
{ "require": { "cypresslab/compass-elephant": ">=0.1.0" } }
然后运行
$ wget -nc https://getcomposer.org.cn/composer.phar $ php composer.phar install
现在CompassElephant已安装在vendor/cypresslab/compasselephant
并在vendor/.composer/autoload.php中包含了一个方便的自动加载文件
pear
添加Cypresslab频道
$ pear channel-discover pear.cypresslab.net
然后安装该包。由于CompassElephant目前处于alpha状态,所以请记住在库名称中包含-alpha
$ pear install cypresslab/CompassElephant-alpha
在Cypresslab pear频道主页上可以找到其他有用的信息
测试
该库已使用PHPUnit进行全面测试。
进入基本库文件夹并运行测试套件
$ phpunit
代码风格
- CompassElephant遵循Symfony2编码标准
- 我使用gitflow,因此,如果你想做出贡献,请向develop分支发送pull-request
如何使用
请记住,给用户赋予访问文件系统的权限。如果你正在使用web服务器,请给用户和web服务器用户都赋予权限。
构造函数
<?php $project = new CompassProject("/path/to/compass"); // create the base class, only the path is mandatory.... // Here is a full customized project $path = "/path/to/compass"; $name = "blog"; // a project name. Not used in the library...but useful if you have more than one project $binary = new CompassBinary('/usr/local/bin/compass'); // use this to set a custom path for the executable. If blank the library try with "which compass" before showing an error $stalenessChecker = 'finder'; // or native. More on this later $configFile = 'config_prod.rb'; // the name of the ruby config file. Defaults to config.rb $autoInit = false; // if true, when given a folder without a config file inside, CompassElephant will try to initialize a compass project $project = new CompassProject($path, $name, $binary, $stalenessChecker, $configFile, $autoInit); // Here is the full constructor signature /** * Class constructor * * @param string $projectPath the path to the compass project * @param null $name the project name * @param \CompassElephant\CompassBinary|null $compassBinary a CompassBinary instance * @param mixed $stalenessChecker a StalenessCheckerInterface instance * @param string $configFile the compass config file name * @param bool $autoInit whether to call init() on an empty folder project * * @internal param \CompassElephant\CommandCaller $commandCaller a CommandCaller instance */ public function __construct($projectPath, $name = null, CompassBinary $compassBinary = null, $stalenessChecker = null, $configFile = 'config.rb', $autoInit = true) { // ... }
管理compass项目
<?php // if the project do not contains a config file, CompassElephant assumes it isn't initialized. See autoInit parameters for skip this step if (!$project->isInitialized()) { $project->init(); // call the "compass create" command } // return false if the project needs to be recompiled. In other words if you changed something in config.rb, sass or scss files after the last sylesheets generation if (!$project->isClean()) { $project->compile(); // compile the project echo $project->isClean(); // return true now }
陈旧性检查器
Compass以两种不同的方式检查项目是否需要编译
finder 此方法使用惊人的 Symfony Finder 组件。它解析config.rb文件中的sass路径和样式表路径。然后检查样式表的修改时间是否早于config文件或sass文件的修改。这是默认方法。
native 使用命令 "compass compile --dry-run" 并解析输出以查看是否有与sass不匹配的样式表。此方法不是很酷,因为它真的很慢。即使仅在开发环境中使用它,每次检查也会增加400-500毫秒的延迟。因此,仅在无法使用finder方法时才使用它
你是在重新发明轮子吗?
我使用 Assetic 来管理我的资产...你也应该使用它。
但是,目前的Compass实现没有按预期工作。Assetic基于单个资产编译的概念。并且 它没有意识到依赖性
向Assetic发送pull-request并不容易,因为它应该改变整个库的结构。我知道作者正在处理它。
我承诺,当问题得到解决时,我将删除这个库并返回到Assetic。到目前为止,你可以(应该)使用它来重写/压缩CompassElephant生成的样式表。这正是我现在正在做的事情。
Symfony2
CompassElephantBundle 让symfony为你做工作