blake/coffeescript

Coffeescript module for ZF2.

v0.1.3 2013-08-30 15:14 UTC

This package is not auto-updated.

Last update: 2024-12-16 16:53:33 UTC


README

About

This module provides inline support for CoffeeScript in ZF2 views using alxlit's PHP CoffeeScript Compiler.

Installation

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',
	// ...
),
// ...

Usage

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
);

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.

By default, the options passed to the compiler are:

$options = array(
	'bare' => true,
	'header' => false,
);

These can be overriden by passing your own options.