Exemplo n.º 1
0
 /**
  * Process CSS code
  *
  * Available settings:
  *   'less': enable/disable LESS parser
  *   'compress': TRUE to remove whispaces and unused chars from output, FALSE to make it more human readable
  *   'absolute_path': absolute path to the file
  *   'url_path': url path to the file
  *   'cache_path': cache folder
  *   'data': variables passed to the css parser for use in the LESS code
  *
  * @param string $css
  * @param array  $settings
  *
  * @return string
  */
 public static function process($css, array $settings = array())
 {
     //Load settings
     $settings = $settings + self::default_settings();
     // 1. Process the file with LESS
     if ($settings['less']) {
         $less = new Tinyfier_CSS_LESS();
         $css = $less->process($css, $settings);
     }
     // 2. Optimize, compress and add vendor prefixes
     $optimizer = new css_optimizer(array('compress' => $settings['compress'], 'optimize' => $settings['optimize'], 'extra_optimize' => $settings['extra_optimize'], 'remove_ie_hacks' => false, 'prefix' => $settings['prefix']));
     $css = $optimizer->process($css);
     return $css;
 }
Exemplo n.º 2
0
        $cleaner->project_files = explode(PATH_SEPARATOR, $opts['p']);
        $cleaner->method = get('m', 'safe') == 'safe' ? css_cleaner::METHOD_SAFE : css_cleaner::METHOD_BEST_CLEAN;
        if (has('e')) {
            $cleaner->extensions = get('e');
        }
        if (has('r')) {
            $cleaner->report_path = get('r');
        }
        $cleaner->clean($css_doc);
    }
    //Optimize
    $optimizer = new css_optimizer();
    $optimizer->compress = get('c', true);
    $optimizer->optimize = get('o', true);
    $optimizer->prefixes = get('v', 'webkit,msie,firefox');
    $optimizer->process($css_doc);
    //Generate output
    $out = $css_doc->render($optimizer->compress);
    //Save output
    if (!($fout = array_shift($argv))) {
        echo $out;
    } else {
        //Show stats
        echo 'Optimized in ' . ReadableTime(microtime(true) - $start) . "\n";
        echo 'Input size ' . ReadableSize(strlen($data)) . ' (' . ReadableSize(strlen(gzencode($data, 9))) . ' gziped)' . "\n";
        $ratio = round(strlen($out) / strlen($data), 2) * 100;
        echo 'Output size ' . ReadableSize(strlen($out)) . " ({$ratio}% of original, " . ReadableSize(strlen(gzencode($out, 9))) . ' gziped)' . "\n";
        //Save file
        file_put_contents($fout, $out);
    }
} catch (exception $ex) {
Exemplo n.º 3
0
function optimize($css, $settings, &$errors = null)
{
    $optimizer = new css_optimizer($settings);
    $result = $optimizer->process($css);
    //$errors = $optimizer->errors();
    return $result;
}