cypresslab / compass-elephant
用于管理PHP compass项目的库
Requires
- php: >=5.3.3
- symfony/finder: ~2.1
- symfony/process: ~2.1
Requires (Dev)
- phpunit/phpunit: ~4.3
README
PHP编写的compass二进制包装器
要求
- php >= 5.3
- *nix系统,已安装compass
依赖
用于测试
安装
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
还有一个方便的autoload文件可以包含在你的项目中,即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 为您完成工作