Home > CoffeeGrinder

CoffeeGrinder

CoffeeGrinder is a project mainly written in PHP, based on the MIT license.

CoffeeScript Compiler Wrapper for PHP

h1. Coffee Grinder

CoffeeGrinder is a PHP compiler wrapper for "CoffeeScript":http://jashkenas.github.com/coffee-script/ compilers. It's useful for dynamically compiling CoffeeScript on the server-side before serving to a client (as opposed to manually compiling scripts).

CoffeeGrinder should be used as part of an existing asset packaging system and is provided for convenience for being part of a larger system. CoffeeGrinder is not an independent CoffeeScript compiler. By default CoffeeGrinder uses "jcoffeescript":https://github.com/yeungda/jcoffeescript, however, this can be replaced with any compiler that takes CoffeeScript on STDIN and produces compiled code on STDOUT.

h2. Requirements

  • PHP 5.3+
  • Your favorite command line CoffeeScript compiler

h2. Installation

Extract the source files into a directory in your PHP library path. Make sure that you extract the default jcoffeescript JAR to your classpath if you intend to use the default command-line compiler.

h3. Usage

 $coffee = ... // read coffeescript from a file or inline

 $grinder = new CoffeeGrinder();
 echo $grinder->parse($coffee);

You can also use a different command line compiler by passing it in to the constructor of CoffeeGrinder

 $grinder = new CoffeeGrinder('java -jar /my/path/to/jcoffeescript.jar');
Previous:getHead