kylekatarnls/coffeescript

View on GitHub
src/NodejsPhpFallback/CoffeeScript.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace NodejsPhpFallback;

use CoffeeScript\Compiler as PhpCoffeeScriptEngine;

class CoffeeScript extends Wrapper
{
    protected $bare;

    public function __construct($file, $bare = true)
    {
        parent::__construct($file);
        $this->bare = $bare;
    }

    public function compile()
    {
        return $this->execModuleScript(
            'coffee-script',
            'bin/coffee',
            '--print ' . ($this->bare ? '--bare ' : '') . escapeshellarg($this->getPath('source.coffee'))
        );
    }

    public function fallback()
    {
        return PhpCoffeeScriptEngine::compile($this->getSource(), array(
            'filename' => basename($this->getPath('source.coffee')),
            'bare'     => $this->bare,
            'header'   => false,
        ));
    }
}