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);
 }
 /**	@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);
 }
Beispiel #3
0
<?php

namespace CoffeeScript;

use ArrayAccess;
Init::init();
/* Driver template for the PHP_ParserGenerator parser generator. (PHP port of LEMON)
 */
/**
 * This can be used to store both the string representation of
 * a token, and any useful meta-data associated with the token.
 *
 * meta-data should be stored as an array
 */
class yyToken implements ArrayAccess
{
    public $string = '';
    public $metadata = array();
    function __construct($s, $m = array())
    {
        if ($s instanceof yyToken) {
            $this->string = $s->string;
            $this->metadata = $s->metadata;
        } else {
            $this->string = (string) $s;
            if ($m instanceof yyToken) {
                $this->metadata = $m->metadata;
            } elseif (is_array($m)) {
                $this->metadata = $m;
            }
        }
Beispiel #4
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);