ZF2 CoffeeScript Module
About
This module provides inline support for CoffeeScript in ZF2 views using alxlit's
PHP CoffeeScript Compiler., (*1)
Installation
Installing this modul is quite simple using Composer. First, add this to your
composer.json:, (*2)
"require": {
...
"blake/coffeescript": "0.*"
}
Set this requirement up with the usual composer.phar install
command. And finally,
you need to add this to your ZF2 application.config.php
:, (*3)
// ...
'modules' => array(
// ...
'Blake\CoffeeScript',
// ...
),
// ...
Usage
With this installed, you can call appendCoffeeScript()
off of the HeadScript
or InlineScript
view helpers., (*4)
$this->inlineScript()->appendCoffeeScript(<<<COFFEESCRIPT
console.log 'Hello, syntax.'
COFFEESCRIPT
);
Additionally, there is a dedicated CoffeeScript
invokable view helper that will simply
compile CoffeeScript., (*5)
echo $this->coffeeScript(<<<COFFEESCRIPT
console.log 'Another lame example.'
COFFEESCRIPT
);
Compiler Options
Both of the helpers illustrated above take a second, optional, argument that is a array of options
to pass on to the CoffeeScript compiler. You can see a list of these options on the official
PHP CoffeeScript documentation., (*6)
By default, the options passed to the compiler are:, (*7)
$options = array(
'bare' => true,
'header' => false,
);
These can be overriden by passing your own options., (*8)