source: sandbox/newExpressoMail/newExpressoMail/Assetic/Filter/CoffeeScriptFilter.php @ 7265

Revision 7265, 1.7 KB checked in by gustavo, 12 years ago (diff)

Ticket #0000 - Criado novo modulo para o desenvolvimento do novo ExpressoMail?

  • Property svn:executable set to *
Line 
1<?php
2
3/*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2012 OpenSky Project Inc
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Assetic\Filter;
13
14use Assetic\Asset\AssetInterface;
15use Assetic\Exception\FilterException;
16use Symfony\Component\Process\ProcessBuilder;
17
18/**
19 * Compiles CoffeeScript into Javascript.
20 *
21 * @link http://coffeescript.org/
22 * @author Kris Wallsmith <kris.wallsmith@gmail.com>
23 */
24class CoffeeScriptFilter implements FilterInterface
25{
26    private $coffeePath;
27    private $nodePath;
28
29    // coffee options
30    private $bare;
31
32    public function __construct($coffeePath = '/usr/bin/coffee', $nodePath = '/usr/bin/node')
33    {
34        $this->coffeePath = $coffeePath;
35        $this->nodePath = $nodePath;
36    }
37
38    public function setBare($bare)
39    {
40        $this->bare = $bare;
41    }
42
43    public function filterLoad(AssetInterface $asset)
44    {
45        $input = tempnam(sys_get_temp_dir(), 'assetic_coffeescript');
46        file_put_contents($input, $asset->getContent());
47
48        $pb = new ProcessBuilder(array(
49            $this->nodePath,
50            $this->coffeePath,
51            '-cp',
52        ));
53
54        if ($this->bare) {
55            $pb->add('--bare');
56        }
57
58        $pb->add($input);
59        $proc = $pb->getProcess();
60        $code = $proc->run();
61        unlink($input);
62
63        if (0 < $code) {
64            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
65        }
66
67        $asset->setContent($proc->getOutput());
68    }
69
70    public function filterDump(AssetInterface $asset)
71    {
72    }
73}
Note: See TracBrowser for help on using the repository browser.