Ejemplo n.º 1
0
 public function build($script)
 {
     $dependencies = array_merge($this->dependency->getList($this->project->getPath("resources coffee {$script}.coffee")), $this->dependency->getList($this->sencha->getPath('src coffee Cti.coffee')));
     $fs = new Filesystem();
     $result = '';
     $sourceList = array();
     $stopwatch = new Stopwatch();
     foreach (array_reverse($dependencies) as $coffee) {
         $sourceList[] = $coffee;
         $local = $this->source->getLocalPath($coffee);
         $local_js = dirname($local) . DIRECTORY_SEPARATOR . basename($local, 'coffee') . 'js';
         $javascript = $this->project->getPath(sprintf('build js %s', $local_js));
         if (!file_exists($javascript) || filemtime($coffee) >= filemtime($javascript)) {
             if ($this->debug) {
                 $stopwatch->start($local);
                 echo '- compile ' . $local;
             }
             $code = \CoffeeScript\Compiler::compile(file_get_contents($coffee), array('filename' => $coffee, 'bare' => true, 'header' => false));
             if ($this->debug) {
                 $event = $stopwatch->stop($local);
                 echo ' (' . String::formatMilliseconds($event->getDuration()) . ' using ' . String::formatBytes($event->getMemory()) . ')' . PHP_EOL;
             }
             $fs->dumpFile($javascript, $code);
         } else {
             $code = file_get_contents($javascript);
         }
         $result .= $code . PHP_EOL;
     }
     $this->hash[$script] = $sourceList;
     $this->cache->set(__CLASS__, $this->hash);
     $filename = $this->project->getPath("public js {$script}.js");
     $fs->dumpFile($filename, $result);
     return $filename;
 }
Ejemplo n.º 2
0
 public function filterDump(AssetInterface $asset)
 {
     $content = $asset->getContent();
     $config = array_merge(array('filename' => $asset->getSourcePath()), $this->config);
     $content = Compiler::compile($content, $config);
     $asset->setContent($content);
 }
Ejemplo n.º 3
0
 /**
  * Compile the site's CoffeeScript into JavaScript.
  */
 public function compile()
 {
     $minify = $this->config->minify;
     // If we are concatenating files, then open a file pointer
     if ($concatenate = $this->config->concatenate) {
         $output = fopen($this->dest . '/' . $this->config->output, 'w');
     }
     // Loop through each of the input files
     foreach ($this->files as $file) {
         // Get the contents of the file
         $coffee = file_get_contents($file);
         // Convert CoffeeScript to JS
         $js = CoffeeScript::compile($coffee, ['filename' => $file]);
         // Minify if necessary
         if ($minify) {
             $js = $this->minify($js);
         }
         // If concatenating, write to the file pointer
         if ($concatenate) {
             fwrite($output, $js);
             continue;
         }
         // Replace the file extension
         $file = str_replace('.coffee', '.js', $file);
         // Write a new file to the output directory
         file_put_contents($this->dest . '/' . basename($file), $js);
     }
     // Close the file pointer
     if ($concatenate) {
         fclose($output);
     }
 }
Ejemplo n.º 4
0
 /**
  * Callback method called before filters are run
  *
  * Overriding to run the file through CoffeeScript compiler if it has a .coffee extension
  *
  * @param string $originalFile
  * @param string $cacheFile
  */
 protected function beforeFilter($originalFile, $cacheFile)
 {
     if ('coffee' == pathinfo($originalFile, PATHINFO_EXTENSION)) {
         $coffeeScript = CoffeeScript\Compiler::compile(file_get_contents($originalFile), array('header' => false));
         file_put_contents($cacheFile, $coffeeScript);
     }
 }
Ejemplo n.º 5
0
 /**
  * @param OutputInterface $output
  * @param SplFileInfo[]   $files
  * @param string          $destination
  */
 private function compileFiles(OutputInterface $output, array $files, $destination)
 {
     $code = '';
     foreach ($files as $file) {
         if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
             $output->writeln("Compiling " . $file);
         }
         $code .= $file->getContents() . "\n";
     }
     $js = $this->coffee->compile($code, $this->getParameter('options'));
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln("Writing to " . $destination);
     }
     $fs = new Filesystem();
     $fs->mkdir(dirname($destination));
     $fs->dumpFile($destination, $js);
 }
Ejemplo n.º 6
0
 function render($context = null, $vars = array())
 {
     try {
         return Compiler::compile($this->data);
     } catch (Error $e) {
         throw new \RuntimeException("coffee({$this->source}) returned an error:\n {$e->getMessage()}");
     }
 }
Ejemplo n.º 7
0
 /**
  * @param $source $string
  * @param $file bool|NULL
  * @throws \WebLoader\WebLoaderException
  * @return string
  */
 public function compileCoffee($source, $file)
 {
     try {
         return Compiler::compile($source, array('filename' => $file));
     } catch (\Exception $e) {
         throw new \WebLoader\WebLoaderException('CoffeeScript Filter Error: ' . $e->getMessage(), 0, $e);
     }
 }
Ejemplo n.º 8
0
 /**
  * Compile the CoffeeScript at the given path.
  *
  * @param  string  $path
  * @return void
  */
 public function compile($path)
 {
     $app = app();
     $options = $app['config']['vtalbot/coffee::options'];
     $contents = Coffee::compile($this->files->get($path), $options);
     if (!is_null($this->cachePath)) {
         $this->files->put($this->getCompiledPath($path), $contents);
     }
 }
 public function filterLoad(AssetInterface $asset)
 {
     $content = $asset->getContent();
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     if (!empty($content)) {
         $content = \CoffeeScript\Compiler::compile($asset->getContent(), array('filename' => $path));
     }
     $asset->setContent($content);
 }
Ejemplo n.º 10
0
 /**
  * @param string $code
  * @return string
  * @throws \Athem\Exception\InvalidClass
  */
 protected function phpProcess($code, $data = array())
 {
     if (!class_exists('\\CoffeeScript\\Compiler')) {
         throw new Exception\InvalidClass('Could nod find \\CoffeeScript\\Compiler class. If you\'re using ' . 'composer, please add "coffeescript/coffeescript" : "*" to your composer.json and run \'composer update\'.');
     }
     try {
         return \CoffeeScript\Compiler::compile(file_get_contents($code), $this->options['coffeeCompilerOptions']);
     } catch (\Exception $e) {
         throw new Code\Exception\CompileError('Code processing failed. Please see trace to understand the nature of the error.', 1, $e);
     }
 }
 public function filterDump(AssetInterface $asset)
 {
     $content = $asset->getContent();
     try {
         if (trim($content)) {
             $content = \CoffeeScript\Compiler::compile($content, array('filename' => $asset->getSourcePath()));
         }
     } catch (Exception $e) {
         $content = $e->getMessage();
     }
     $asset->setContent($content);
 }
Ejemplo n.º 12
0
 /**
  * Filters an asset after it has been loaded.
  *
  * @param Assetic\Asset\AssetInterface $asset
  */
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $presets = $this->presets;
     // If we have a root and path, set the 'file'
     // preset now, which aids in debugging should
     // something go wrong.
     if ($root and $path) {
         $presets = array_merge($presets, array('file' => $root . '/' . $path));
     }
     $asset->setContent(Compiler::compile($asset->getContent(), $presets));
 }
 protected function assetCompiler($strSourcePath)
 {
     // Javascript File - No compilation required
     if (substr($strSourcePath, -7) != '.coffee') {
         return array($strSourcePath, md5_file(TL_ROOT . '/' . $strSourcePath));
     }
     // Target File
     $strJSFile = 'assets/js/coffee-' . md5_file($strSourcePath) . '.js';
     if (!file_exists(TL_ROOT . '/' . $strJSFile)) {
         // require classes
         CoffeeScriptInit::load();
         // Compile
         $strCoffee = file_get_contents($strSourcePath);
         $strJs = CoffeeScriptCompiler::compile($strCoffee, array('filename' => $strSourcePath));
         // write css file / replace with contao framework method later
         file_put_contents(TL_ROOT . '/' . $strJSFile, $strJs);
         $this->compressAsset(TL_ROOT . '/' . $strJSFile);
     }
     return array($strJSFile, null);
 }
Ejemplo n.º 14
0
 /**
  * The abstract process method to be called whenever file needs to be handled by this pipe.
  *
  * @param $asset which should be processed by this pipe
  * @param array $options to be applied on asset (e.g. min)
  * @param string describing errors during file location process
  *
  * @return string containing the processed file's content
  */
 public function process($asset, $options = [], $errors = '')
 {
     $file = $this->_assetDirectory . DIRECTORY_SEPARATOR . $asset;
     $js = null;
     if (!$this->_hasDefaultMimeType($asset)) {
         try {
             $coffee = file_get_contents($file);
             // See available options above.
             $js = CoffeeScript\Compiler::compile($coffee, array('filename' => $file));
             if (in_array('min', $options)) {
                 $js = $this->_min($js);
             }
             $js = $this->comment($errors, $js);
         } catch (Exception $e) {
             echo $e->getMessage();
             $js = $e->getMessage();
         }
     } else {
         $js = file_get_contents($file);
     }
     return $js;
 }
Ejemplo n.º 15
0
Archivo: Coffee.php Proyecto: cti/core
 /**
  * @param $script
  * @return string
  * @throws \Cti\Core\Exception
  */
 public function build($script)
 {
     $result = '';
     $filename = $this->project->getPath("resources coffee {$script}.coffee");
     $dependencies = $this->getDependencyList($filename);
     $fs = new Filesystem();
     foreach (array_reverse($dependencies) as $coffee) {
         $local = $this->getLocalPath($coffee);
         $local = dirname($local) . DIRECTORY_SEPARATOR . basename($local, 'coffee') . 'js';
         $javascript = $this->project->getPath(sprintf('build js %s', $local));
         if (!file_exists($javascript) || filemtime($coffee) >= filemtime($javascript)) {
             $code = Compiler::compile(file_get_contents($coffee), array('filename' => $coffee, 'bare' => true, 'header' => false));
             $fs->dumpFile($javascript, $code);
         } else {
             $code = file_get_contents($javascript);
         }
         $result .= $code . PHP_EOL;
     }
     $filename = $this->project->getPath("public js {$script}.js");
     $fs->dumpFile($filename, $result);
     return $filename;
 }
Ejemplo n.º 16
0
 /**	@see ModuleConnector::init() */
 public function init(array $params = array())
 {
     // Pointer to resourcerouter
     $rr = m('resourcer');
     // If we have coffee resource in project
     if (isset($rr->cached['coffee'])) {
         // Change coffee file to js and store it as current js resource
         $newJS = str_replace('.coffee', '.js', str_replace(__SAMSON_PUBLIC_PATH, '', $rr->cached['coffee']));
         // If .coffee resource has been updated
         $file =& $rr->updated['coffee'];
         if (isset($file)) {
             try {
                 // Read coffee file
                 $coffee = file_get_contents($file);
                 // Initialize coffee compiler
                 \CoffeeScript\Init::load();
                 // Read updated .coffee resource file and compile it
                 $js = \CoffeeScript\Compiler::compile($coffee, array('filename' => $file));
                 // Compile coffee script to js and save to the same location
                 file_put_contents($file, $js);
             } catch (Exception $e) {
                 e('Ошибка обработки CoffeeScript: ' . $e->getMessage());
             }
         }
         // If regular JS has been updated or coffee script has been updated
         if (isset($rr->updated['js']) || isset($rr->updated['coffee'])) {
             // Read gathered js
             $oldJS = file_get_contents(str_replace(__SAMSON_PUBLIC_PATH, '', $rr->cached['js']));
             // Read gathered coffee
             $coffee = file_get_contents(str_replace(__SAMSON_PUBLIC_PATH, '', $rr->cached['coffee']));
             // Concatenate regular js and compiled coffee script js to a new javascript file
             file_put_contents($newJS, $oldJS . $coffee);
         }
         // Change old js resource to new one
         //$rr->cached['js'] = $newJS;
     }
     // Call parent method
     parent::init($params);
 }
Ejemplo n.º 17
0
 /**
  */
 function coffee()
 {
     require_php_lib('coffeescript_php');
     $raw = 'alert "I knew it!" if elvis?';
     $js = \CoffeeScript\Compiler::compile($raw, ['header' => false]);
     coffee($raw);
     return 'COFFEE: <pre>' . _prepare_html($raw) . '</pre>' . PHP_EOL . '<br \\>JS: <pre>' . _prepare_html($js) . '</pre>';
 }
Ejemplo n.º 18
0
 public function filterLoad(AssetInterface $asset)
 {
     $content = $asset->getContent();
     $asset->setContent(CoffeeScript::compile($content, $this->options));
 }
Ejemplo n.º 19
0
 public function fallback()
 {
     return PhpCoffeeScriptEngine::compile($this->getSource(), array('filename' => basename($this->getPath('source.coffee')), 'bare' => $this->bare, 'header' => false));
 }
Ejemplo n.º 20
0
 public function compile($source, $pathname)
 {
     return \CoffeeScript\Compiler::compile($source, array('filename' => $pathname));
 }
Ejemplo n.º 21
0
 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $asset->setContent(trim(Compiler::compile($this->parser->parse($asset->getContent()), ['filename' => $asset->getSourcePath()])));
 }
Ejemplo n.º 22
0
 /**
  * [filterDump description]
  * @param  AssetInterface $asset [description]
  * @return [type]                [description]
  */
 public function filterDump(AssetInterface $asset)
 {
     $content = $asset->getContent();
     $content = Compiler::compile($content, array('filename' => $asset->getSourcePath()));
     $asset->setContent($content);
 }
Ejemplo n.º 23
0
 /**
  */
 function coffee($content, $params = [])
 {
     $this->require_php_lib('coffeescript_php');
     return \CoffeeScript\Compiler::compile($content, ['header' => false]);
 }
Ejemplo n.º 24
0
 public function phpProcess($code)
 {
     return \CoffeeScript\Compiler::compile(file_get_contents($code));
 }
Ejemplo n.º 25
0
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/yfix/coffeescript-php.git' => 'coffeescript_php/'], 'require_once' => ['coffeescript_php/src/CoffeeScript/Init.php'], 'manual' => function () {
    \CoffeeScript\Init::load();
}, 'example' => function () {
    $coffee = 'alert "I knew it!" if elvis?';
    echo \CoffeeScript\Compiler::compile($coffee, ['header' => false]);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
Ejemplo n.º 26
0
 /**
  */
 public function get_coffee_content($params = [])
 {
     $out = [];
     $content = $this->get_content('coffee');
     if (empty($content)) {
         return [];
     }
     require_php_lib('coffeescript_php');
     foreach ((array) $content as $md5 => $v) {
         $v['content'] = \CoffeeScript\Compiler::compile($v['content'], ['header' => false]);
         $out[$md5] = $v;
     }
     return $out;
 }
Ejemplo n.º 27
0
 /**
  * Compiles the CoffeeScript content to JavaScript
  *
  * @param Node   $node    the node to be compiled
  * @param string $indent  the indentation to use on each child
  * @param string $newLine the new-line to append after each line
  *
  * @return string the wrapped JavaScript-HTML-string
  * @throws Compiler\Exception when the CoffeeScript package is not installed
  */
 public static function filterCoffeeScript(Node $node, $indent, $newLine)
 {
     if (!class_exists('CoffeeScript\\Compiler')) {
         throw new Compiler\Exception("Failed to compile CoffeeScript: " . "Please install the coffeescript/coffeescript composer package");
     }
     $js = \CoffeeScript\Compiler::compile($node->text(), ['header' => '', 'filename' => 'Imported-at-(' . $node->line . ':' . $node->offset . ').coffee']);
     return '<script>' . $newLine . $indent . $js . $newLine . $indent . '</script>';
 }
Ejemplo n.º 28
0
 public function filterLoad(AssetInterface $asset)
 {
     $asset->setContent(\CoffeeScript\Compiler::compile($asset->getContent()));
 }
Ejemplo n.º 29
0
 public function compileCoffee($file)
 {
     $target = "{$this->getManagedPath()}js/{$file}.js";
     $source = "{$this->getAssetPath()}coffee/{$file}";
     if ($this->shouldBeCompiled($source, $target)) {
         $this->ensureFileExists($target);
         $content = file_get_contents($source);
         $content = \CoffeeScript\Compiler::compile($content);
         file_put_contents($target, $content);
     }
 }
Ejemplo n.º 30
0
 /**
  * Return compiled source from a CoffeeScript file
  * @access 	public
  * @param 	string 	source
  * @return 	string 	compiled source
  * @throws 	SprocketsCoffeeCompilerException
  */
 protected function compile_coffee($source)
 {
     $options = array_merge(array('filename' => $this->file_path), $this->config["coffeescript"]);
     try {
         $coffee = \CoffeeScript\Compiler::compile($source, $options);
     } catch (\Exception $e) {
         throw new SprocketsCoffeeCompilerException($e->getMessage());
     }
     return $this->minify_js($coffee);
 }