コード例 #1
0
ファイル: Coffee.php プロジェクト: alle/assets-merger
 /**
  * Process asset content
  *
  * @param   string $content
  * @param   Asset  $asset
  *
  * @return  string
  */
 public static function process($content, Asset $asset)
 {
     // Set error reporting
     $old = error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT));
     // Set content
     CoffeeScript\Init::load();
     $options = array('filename' => Debug::path($asset->source_file()), 'header' => FALSE);
     $content = CoffeeScript\Compiler::compile($content, $options);
     // Set error reporting
     error_reporting($old);
     return $content;
 }
コード例 #2
0
ファイル: Coffee.php プロジェクト: boomcms/asset-merger
 /**
  * Process asset content
  *
  * @param   string  $content
  * @param   Asset   $asset
  * @return  string
  */
 public static function process($content, Asset $asset)
 {
     // Set error reporting
     $old = error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT));
     // Include the engine
     include_once Kohana::find_file('vendor/coffeescript/CoffeeScript', 'Init');
     // Set content
     CoffeeScript\Init::load();
     $options = array('filename' => Debug::path($asset->source_file()), 'header' => TRUE);
     $content = CoffeeScript\Compiler::compile($content, $options);
     // Set error reporting
     error_reporting($old);
     return $content;
 }
 /**
  * Compiles the $uncompiledFile into JS
  */
 public function compile()
 {
     if (!class_exists("CoffeeScript\\Compiler")) {
         user_error("CoffeeScript requires the PHP CoffeeScript compiler to run. You can install with \"composer require coffeescript/coffeescript\"", E_USER_ERROR);
     }
     if (MetaLanguages::within_modification_tolerance($this->uncompiledFile, $this->getCompiledPath())) {
         return;
     }
     $file = BASE_PATH . '/' . $this->uncompiledFile;
     try {
         $coffee = file_get_contents($file);
         $js = CoffeeScript\Compiler::compile($coffee, array('filename' => $file));
         $js_file = fopen(BASE_PATH . '/' . $this->getCompiledPath(), "w");
         fwrite($js_file, $js);
         fclose($js_file);
     } catch (Exception $e) {
         user_error($e->getMessage(), E_USER_ERROR);
     }
 }
コード例 #4
0
/**
 * Compiles a coffeescript file to javascript and returns the result
 * @param $coffee string Contents of a coffee script file
 * @param $do_output bool Output the result of the compile?
 * @return array The content of a javascript file and the new filename
 */
function compile_coffee($coffee, $do_output, $file)
{
    $js = CoffeeScript\Compiler::compile($coffee, array("filename" => $file, "header" => false));
    $js_file = str_replace(".coffee", ".js", $file);
    return place_file($js_file, $js, $do_output, $file);
}
コード例 #5
0
 /**
  * Process assets in group
  * @param  string $type
  * @param  string $group
  */
 private static function _process($type = null, $group = null)
 {
     if (!$group) {
         $group = self::$default_group[$type];
     }
     // Start benchmark
     if (self::$_enable_benchmark) {
         self::$_ci->benchmark->mark("Assets::process(" . $type . ", " . $group . ")_start");
     }
     // Last modified date
     if (!isset(self::$_cache_info->{$type}->{$group})) {
         $last_modified = 0;
     } else {
         $last_modified = self::last_modified($type, $group);
     }
     // Create a cache filename
     if ($group !== self::$default_group[$type]) {
         $file_prefix = $group . '.';
     } else {
         $file_prefix = '';
     }
     $file_name = self::$_assets[$type][$group]['cache_file_name'] = $file_prefix . $last_modified . "." . $type;
     // And check if we should process it
     $file_exists = file_exists(self::$cache_path . '/' . $file_name);
     if (!$file_exists or !$last_modified) {
         // Get list of assets
         $assets = self::$_assets[$type][$group];
         // Loop through all original assets
         foreach ($assets['src'] as $key => $asset) {
             // Get file contents
             $contents = read_file($asset['path']);
             // Get file info
             $asset['info'] = pathinfo($asset['file']);
             // Process imports in CSS files
             if ($type === 'css') {
                 $import_result = self::_process_imports($contents, null, $asset['file']);
                 $contents = $import_result['contents'];
                 // Update last modified time
                 if ($import_result['last_modified'] > self::$_assets[$type][$group]['last_modified']) {
                     self::$_assets[$type][$group]['last_modified'] = $import_result['last_modified'];
                     self::$_assets[$type][$group]['last_modified_human'] = date('Y-m-d H:i:s', $import_result['last_modified']);
                 }
                 // Update imported files
                 self::$_assets[$type][$group]['file_list'] = array_unique(array_merge(self::$_assets[$type][$group]['file_list'], $import_result['file_list']));
             } elseif ($type === 'js') {
                 // CoffeeScript parser
                 if (self::$enable_coffeescript and $asset['info']['extension'] === 'coffee') {
                     if (!self::$_coffeescript_loaded) {
                         self::_init_coffeescript();
                     }
                     CoffeeScript\Init::load();
                     $contents = CoffeeScript\Compiler::compile($contents);
                 } elseif (!self::$enable_coffeescript and $asset['info']['extension'] === 'coffee') {
                     $contents = '';
                 }
                 // Minify JS
                 if (self::$minify_js) {
                     self::_init_jsmin();
                     $contents = trim(JSMin::minify($contents));
                 }
             }
             // Or add to combine var (if we're combining)
             self::$_assets[$type][$group]['combined'] .= "\n" . $contents;
         }
         // New file name
         $file_name = self::$_assets[$type][$group]['cache_file_name'] = $file_prefix . self::$_assets[$type][$group]['last_modified'] . "." . $type;
         // Now minify/less if we choose so
         if ($type === 'css') {
             $output = self::$_assets[$type][$group]['combined'];
             // Less
             if (self::$enable_less and !self::$freeze) {
                 self::_init_less();
                 $output = self::$_less->parse($output);
             }
             // Minify CSS
             if (self::$minify_css and !self::$freeze) {
                 self::_init_cssmin();
                 $output = trim(CSSMin::minify($output, self::$cssmin_filters, self::$cssmin_plugins));
             }
             // Add to output
             self::$_assets[$type][$group]['output'] = $output;
             unset($output);
         } elseif ($type === 'js') {
             $output = self::$_assets[$type][$group]['combined'];
             // Minify JS
             if (self::$minify_js) {
                 self::_init_jsmin();
                 self::$_assets[$type][$group]['output'] = trim(JSMin::minify($output));
             }
             // Add to output
             self::$_assets[$type][$group]['output'] = $output;
             unset($output);
         }
         // Once it's processed remove vars we dont need
         unset(self::$_assets[$type][$group]['combined']);
         // And finnaly we create the actual cached files
         self::_cache_assets($type);
     }
     // Update cache info
     self::_update_cache_info();
     // End benchmark
     if (self::$_enable_benchmark) {
         self::$_ci->benchmark->mark("Assets::process(" . $type . ", " . $group . ")_end");
     }
 }
コード例 #6
0
ファイル: router.php プロジェクト: medo/elmasla7a
<?php

require_once "vendor/autoload.php";
$path = pathinfo($_SERVER["SCRIPT_FILENAME"]);
if ($path["extension"] == "coffee") {
    $filepath = $path["dirname"] . "/" . $path["basename"];
    $coffee = file_get_contents($filepath);
    $js = CoffeeScript\Compiler::compile($coffee, array('filename' => $filepath));
    header("Content-Type: application/javascript");
    echo $js;
} else {
    if ($path["extension"] == "scss") {
        $filepath = $path["dirname"] . "/" . $path["basename"];
        $scss_code = file_get_contents($filepath);
        $scss = new scssc();
        header("Content-Type: text/css");
        echo $scss->compile($scss_code);
    } else {
        return false;
    }
}
コード例 #7
0
ファイル: index.php プロジェクト: yashb/generator
 *
 * For each test we check two things, the tokens produced by the lexer/rewriter,
 * and the compiled JavaScript, by comparing them against references produced
 * by the original compiler.
 */
ini_set('display_errors', '1');
error_reporting(E_ALL);
// Test case to run
$case = isset($_GET['case']) ? $_GET['case'] : FALSE;
if ($case) {
    $PHP = array('coffee' => file_get_contents($case), 'error' => NULL, 'js' => NULL, 'rewrite' => !(isset($_GET['rewrite']) && $_GET['rewrite'] === 'off'), 'tokens' => array());
    require '../src/CoffeeScript/Init.php';
    CoffeeScript\Init::load();
    $options = array('filename' => $case, 'header' => FALSE, 'rewrite' => $PHP['rewrite'], 'tokens' => &$PHP['tokens']);
    try {
        $PHP['js'] = CoffeeScript\Compiler::compile($PHP['coffee'], $options);
    } catch (Exception $e) {
        $PHP['error'] = $e->getMessage();
    }
    if ($PHP['tokens']) {
        // Change the tokens to their canonical form so we can compare them against
        // those produced by the reference.
        $PHP['tokens'] = CoffeeScript\Lexer::t_canonical($PHP['tokens']);
    }
}
?>
<!doctype html>
<html>
<head>
  <link type="text/css" href="css/style.css" rel="stylesheet" />
コード例 #8
0
ファイル: big_file.php プロジェクト: kylekatarnls/sbp
 public function parse($coffeeFile)
 {
     DependancesCache::flush($coffeeFile);
     $code = CoffeeScript\Compiler::compile(static::resolveRequire($coffeeFile), array('filename' => $coffeeFile, 'bare' => true));
     if (!Config::get('app.debug')) {
         $code = preg_replace('#;(?:\\r\\n|\\r|\\n)\\h*#', ';', $code);
         $code = preg_replace('#(?:\\r\\n|\\r|\\n)\\h*#', ' ', $code);
     }
     return $code;
 }
コード例 #9
0
     $cssfile = $fileparts['dirname'] . '/' . $fileparts['filename'] . '.css';
     if (file_exists($cssfile) && filemtime($cssfile) < filemtime($file) || !file_exists($cssfile)) {
         require 'lib/lessphp/lessc.inc.php';
         $less = new lessc();
         $data = $less->compileFile($file);
         file_put_contents($cssfile, $data);
     }
     $res = str_replace('.less', '.css', $res);
 } else {
     if ($fileparts['extension'] == 'coffee') {
         $jsfile = $fileparts['dirname'] . '/' . $fileparts['filename'] . '.js';
         if (file_exists($jsfile) && filemtime($jsfile) < filemtime($file) || !file_exists($jsfile)) {
             require 'lib/CoffeeScript/Init.php';
             CoffeeScript\Init::load();
             $coffee = file_get_contents($file);
             $data = CoffeeScript\Compiler::compile($coffee, array('filename' => $file));
             file_put_contents($jsfile, $data);
         }
         $res = str_replace('.coffee', '.js', $res);
     } else {
         if ($fileparts['extension'] == 'md') {
             $htmlfile = $fileparts['dirname'] . '/' . $fileparts['filename'] . '.html';
             if (file_exists($htmlfile) && filemtime($htmlfile) < filemtime($file) || !file_exists($htmlfile)) {
                 $data = Markdown(file_get_contents($file));
                 file_put_contents($htmlfile, $data);
             }
             $res = str_replace('.md', '.css', $res);
         } else {
             if ($fileparts['extension'] == 'jpg' || $fileparts['extension'] == 'jpeg' || $fileparts['extension'] == 'png' || $fileparts['extension'] == 'gif') {
                 $preoptsplit = explode(':', $opt);
                 if (count($preoptsplit) == 2) {