class CoffeeScriptFilter

Compiles CoffeeScript into Javascript.

@link http://coffeescript.org/ @author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of CoffeeScriptFilter

1 file declares its use of CoffeeScriptFilter
CoffeeScriptFilterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Filter/CoffeeScriptFilterTest.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/CoffeeScriptFilter.php, line 24

Namespace

Assetic\Filter
View source
class CoffeeScriptFilter implements FilterInterface {
  private $coffeePath;
  private $nodePath;

  // coffee options
  private $bare;
  public function __construct($coffeePath = '/usr/bin/coffee', $nodePath = '/usr/bin/node') {
    $this->coffeePath = $coffeePath;
    $this->nodePath = $nodePath;
  }
  public function setBare($bare) {
    $this->bare = $bare;
  }
  public function filterLoad(AssetInterface $asset) {
    $input = tempnam(sys_get_temp_dir(), 'assetic_coffeescript');
    file_put_contents($input, $asset
      ->getContent());
    $pb = new ProcessBuilder(array(
      $this->nodePath,
      $this->coffeePath,
      '-cp',
    ));
    if ($this->bare) {
      $pb
        ->add('--bare');
    }
    $pb
      ->add($input);
    $proc = $pb
      ->getProcess();
    $code = $proc
      ->run();
    unlink($input);
    if (0 < $code) {
      throw FilterException::fromProcess($proc)
        ->setInput($asset
        ->getContent());
    }
    $asset
      ->setContent($proc
      ->getOutput());
  }
  public function filterDump(AssetInterface $asset) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CoffeeScriptFilter::$bare private property
CoffeeScriptFilter::$coffeePath private property
CoffeeScriptFilter::$nodePath private property
CoffeeScriptFilter::filterDump public function Filters an asset just before it's dumped. Overrides FilterInterface::filterDump
CoffeeScriptFilter::filterLoad public function Filters an asset after it has been loaded. Overrides FilterInterface::filterLoad
CoffeeScriptFilter::setBare public function
CoffeeScriptFilter::__construct public function