Skip to content

Commit

Permalink
Write the README
Browse files Browse the repository at this point in the history
  • Loading branch information
HavokInspiration committed Jul 11, 2017
1 parent 6b0a016 commit 3831388
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
[![Build Status](https://travis-ci.org/elephfront/robo-css-minify.svg?branch=master)](https://travis-ci.org/elephfront/robo-css-minify)
[![Codecov](https://img.shields.io/codecov/c/github/elephfront/robo-css-minify.svg)](https://github.com/elephfront/robo-css-minify)

This [Robo](https://github.com/consolidation/robo) task ...
This [Robo](https://github.com/consolidation/robo) task performs a minification of your CSS content.

This task performs the minification using [matthiasmullie/minify](https://github.com/matthiasmullie/minify) library.

## Requirements

Expand All @@ -25,6 +27,65 @@ composer require elephfront/robo-css-minify

## Using the task

You can load the task in your RoboFile using the `LoadCssMinifyTasksTrait` trait:

```php
use Elephfront\RoboCssMinify\Task\Loader\LoadCssMinifyTasksTrait;

class RoboFile extends Tasks
{

use LoadCssMinifyTasksTrait;

public function minifyCss()
{
$this
->taskCssMinify([
'assets/css/main.css' => 'assets/min/css/main.min.css',
'assets/css/home.css' => 'assets/min/css/home.min.css',
])
->run();
}
}
```

The only argument the `taskCssMinify()` takes is an array (`$destinationsMap`) which maps the source files to the destination files : it will load the **assets/css/main.css**, do its magic and put the final content in **assets/min/main.min.js** and do the same for all of the other files.

## Chained State support

Robo includes a concept called the [Chained State](http://robo.li/collections/#chained-state) that allows tasks that need to work together to be executed in a sequence and pass the state of the execution of a task to the next one.
For instance, if you are managing assets files, you will have a task that compile SCSS to CSS then another one that minify the results. The first task can pass the state of its work to the next one, without having to call both methods in a separate sequence.

The **robo-css-minify** task is compatible with this feature.

All you need to do is make the previous task return the content the **robo-css-minify** task should operate on using the `data` argument of a `Robo\Result::success()` or `Robo\Result::error()` call. The passed `data` should have the following format:

```php
$data = [
'path/to/source/file' => [
'css' => '// Some CSS code',
'destination' => 'path/to/destination/file
]
];
```

In turn, when the **robo-css-minify** task is done, it will pass the results of its work to the next task following the same format.

## Preventing the results from being written

By default, the **robo-css-minify** task writes the result of its work into the destination file(s) passed in the `$destinationsMap` argument. If the **robo-css-minify** task is not the last one in the sequence, you can disable the file writing using the `disableWriteFile()` method. The files will be processed but the results will not be persisted and only passed to the response :

```php
$this
->taskCssMinify([
'assets/js/main.css' => 'assets/min/css/main.min.css',
'assets/js/home.css' => 'assets/min/css/home.min.css',
])
->disableWriteFile()
->someOtherTask()
->run();
```

## Contributing

If you find a bug or would like to ask for a feature, please use the [GitHub issue tracker](https://github.com/Elephfront/robo-css-minify/issues).
Expand Down

0 comments on commit 3831388

Please sign in to comment.