This module provides inline support for CoffeeScript in ZF2 views using alxlit's PHP CoffeeScript Compiler.
Installing this modul is quite simple using Composer. First, add this to your composer.json:
"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
:
// ...
'modules' => array(
// ...
'Blake\CoffeeScript',
// ...
),
// ...
With this installed, you can call appendCoffeeScript()
off of the HeadScript
or InlineScript
view helpers.
$this->inlineScript()->appendCoffeeScript(<<<COFFEESCRIPT
console.log 'Hello, syntax.'
COFFEESCRIPT
);
Additionally, there is a dedicated CoffeeScript
invokable view helper that will simply
compile CoffeeScript.
echo $this->coffeeScript(<<<COFFEESCRIPT
console.log 'Another lame example.'
COFFEESCRIPT
);
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.
By default, the options passed to the compiler are:
$options = array(
'bare' => true,
'header' => false,
);
These can be overriden by passing your own options.