arnaud-lb/MtHaml — pull request #31 by ronan-gloo (2013-03-29 13:18:51+00:00)
Title: Modular Filters implementation proposal

A proposition to add user filters
----
As a proposition, i haven't wrote test right now...

Anatomy of a filter class
----
Filters should at least implements the MtHaml\Filter\FilterInterface.
The best way is to extends your filter from MtHaml\Filter\Abstract.

You'll need to set a $name, and implements the enter() and leave() methods:

````
class CssFilter extends MtHaml\Filter\Abstract {

protected $name = 'css';

public function enter()
{
$this->renderer
->write('')
}

}

// Add the filter, The filter will be available under :css
$env = new Environment('php');
$env->addFilter(new CssFilter);
````

Adding Filters
-----

1. Through environment configuration:

```
$filters = array('textile' => 'Path\To\Class', 'saas' => new Saas);
$env = new Environment('php', array('filters' => filters)
```

2. Through addFilter() method:

```
// Add filter by class name: the class will be instanciated if filter is used
$env->addFilter('saas', 'Project\\Saas');

// Add filter by instance:
env->addFilter(new Saas);
// you can override the instance filter name like this:
$env->addFilter('custom', new Saas);