https://github.com/czproject/css-tools
CSS tools for PHP
https://github.com/czproject/css-tools
Last synced: over 1 year ago
JSON representation
CSS tools for PHP
- Host: GitHub
- URL: https://github.com/czproject/css-tools
- Owner: czproject
- License: other
- Created: 2013-04-22T11:17:22.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-02-05T08:58:28.000Z (over 2 years ago)
- Last Synced: 2024-04-24T03:13:42.512Z (over 2 years ago)
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license.md
Awesome Lists containing this project
README
# CzProject\CssTools
[](https://github.com/czproject/css-tools/actions)
[](https://packagist.org/packages/czproject/css-tools)
[](https://github.com/czproject/css-tools/releases)
[](https://github.com/czproject/css-tools/blob/master/license.md)
CSS tools for PHP.
## Installation
[Download a latest package](https://github.com/czproject/css-tools/releases) or use [Composer](http://getcomposer.org/):
```
composer require czproject/css-tools
```
CzProject\CssTools requires PHP 7.4 or later.
## Usage
### CSS compiler
Expands `@import` rules in file.
``` php
$compiler = new CzProject\CssTools\CssCompiler;
$compiler->compileFile(__DIR__ . '/styles.css'); // overwrite styles.css with compiled version
$compiledStyles = $compiler->processFile(__DIR__ . '/styles2.css');
$compiledStyles = $compiler->processContent(
'@import "mystyles.css";',
$stylesheetsRootDirectory
);
```
### CSS generator
``` php
$file = new CzProject\CssTools\CssFile;
$file->addRule('.button', [
'color' => CssTools\Color::hex('#F8A'),
'font-size' => CssTools\Number::px2rem(48),
'background-color' => NULL,
]);
echo $file->render();
```
### CSS minifier
``` php
$minifier = new CzProject\CssTools\CssMinifier;
$result = $minifier->minify("body {
color: #333;
background: #fff;
}");
var_dump($result); // Output: body{color:#333;background:#fff}
```
------------------------------
License: [New BSD License](license.md)
Author: Jan Pecha, https://www.janpecha.cz/