Skip to content

Commit b654fad

Browse files
Add a note about events emitted and how to bind handlers to it to perform tasks before of after compilation is happening
1 parent f7a054c commit b654fad

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,44 @@ return [
127127

128128
This would also copy the directory under **src/assets/fonts** to **build/assets/fonts**.
129129

130-
TODO : **elephfront-bootstrap.php**
130+
### Events and bootstrap
131+
132+
When compiling SASS et JS assets, Elephfront emits two events : one before the compilation and one after. When these events are emitted, they are given the current source map (the array containing the source and destination files to compile), the current configuration and more importantly, the current Robo instance, allowing you to run custom tasks before or after these tasks are done.
133+
134+
If you need to perform actions before or after (for instance, you might want to copy a folder from the vendor directory to your source directory before the compilation takes place if you are loading the Foundation CSS framework with composer) the compilation takes place, you can register handlers for those events using the **elephfront-bootstrap.php** files. It should be located on the same directory as the **RoboFile.php** file.
135+
136+
Let's say you are loading the Foundation CSS framework with composer, you could add the following to your **elephfront-bootstrap.php** to include it in your **src** directory :
137+
138+
```php
139+
<?php
140+
use Cake\Event\EventManager;
141+
142+
EventManager::instance()->on('Elephfront.Scss.beforeCompile', function(\Cake\Event\Event $event) {
143+
$robo = $event->getSubject();
144+
$robo
145+
->taskCopyDir([
146+
'vendor/zurb/foundation/scss' => 'src/assets/css/libs/foundation',
147+
'vendor/zurb/foundation/_vendor/normalize-scss' => 'src/assets/css/libs/normalize-scss',
148+
'vendor/zurb/foundation/_vendor/sassy-lists' => 'src/assets/css/libs/sassy-lists',
149+
])
150+
->run();
151+
152+
$robo->taskReplaceInFile('src/assets/css/libs/foundation/foundation.scss')
153+
->from('../_vendor')
154+
->to('../')
155+
->run();
156+
});
157+
```
158+
159+
For the SASS compilation, here are the events emitted :
160+
161+
- Elephfront.Scss.beforeCompile
162+
- Elephfront.Scss.afterCompile
163+
164+
For the JS compilation, here are the events emitted :
165+
166+
- Elephfront.Js.beforeCompile
167+
- Elephfront.Js.afterCompile
131168

132169
## Commands
133170

0 commit comments

Comments
 (0)