public function indexAction($name) { $assets = $this->get('templating.helper.assets'); //$file = $css = "\n ul, p {\n color: \$(dark_-color);\n\n }\n"; $vars = array('dark' => array('-color' => 'white')); $vars = $this->flatten($vars); // print_r($vars); echo csscrush_string($css, array('vars' => $vars)); exit; //echo ; return $this->render('OnepagrCssBundle:Default:index.html.twig', array('name' => $name)); }
public function compileFile($in, $out) { $scss = '@charset "utf-8";'; foreach ($in as $inItem) { if (file_exists($inItem)) { $scss = $scss . PHP_EOL . file_get_contents($inItem); } } $css = $this->compile($scss); $css = csscrush_string($css, ['formatter' => 'block']); if (!file_exists($out)) { mkdir(dirname($out), 0775, true); } return file_put_contents($out, $css); }
/** * Deprecated. * * @see csscrush_string(). */ public static function string($string, $options = array()) { return csscrush_string($string, $options); }
/** * @return array|false|mixed * @throws \Exception */ public function getCollection() { if ($this->cache->contains($this->file_data['hash'])) { // On default we don't need to re-compile $compile_required = false; // get file info for all files foreach ($this->file_data['list'] as $file) { $file_info = $file->getFileInfo(); // check if a parsed_file list is stored if ($file_info['parsed_files'] !== false) { // check all parsed fields if they still exists/have changed foreach ($file_info['parsed_files'] as $parsed_file => $parsed_file_time) { if (!file_exists($parsed_file) || filemtime($parsed_file) > $parsed_file_time) { // file does not exist or filemtime is different $compile_required = true; } } } else { if ($file->requiresFileList() === true) { // check if a file list should be stored, if true we will need to recompile $compile_required = true; } } } // if no compile is required, return the cached file if ($compile_required === false) { return $this->cache->fetch($this->file_data['hash']); } } // File changed or not cached $contents = ""; foreach ($this->file_data['list'] as $file) { $contents .= $file->getFile() . "\n"; // New line to avoid comments cutting off code when combining files } // if result is css, run the file through a auto prefixer if (isset($this->response_type['css'])) { $contents = csscrush_string($contents, array('minify' => $this->minify)); } else { if (isset($this->response_type['js'])) { if ($this->minify) { // minify js $contents = Minifier::minify($contents, array('flaggedComments' => false)); } } } // store in cache $this->cache->save($this->file_data['hash'], $contents, 60 * 60 * 24 * 30); return $contents; }
} if (($showErrors || $changed) && $warnings) { stderr(message($warnings, array('type' => 'warning'))); } if ($changed && $args->stats) { stderr(message($stats, array('type' => 'stats'))); } sleep(1); } } else { $stdOutput = null; if ($args->input_file && isset($options['output_dir'])) { $options['cache'] = false; csscrush_file($args->input_file, $options); } else { $stdOutput = csscrush_string($input, $options); } $stats = csscrush_stat(); $errors = $stats['errors']; $warnings = $stats['warnings']; if ($errors) { stderr(message($errors, array('type' => 'error'))); exit(STATUS_ERROR); } elseif ($args->input_file && !empty($stats['output_filename'])) { stderr(message(fmt_fileinfo($stats, 'output'), array('type' => 'write'))); } if ($warnings) { stderr(message($warnings, array('type' => 'warning'))); } if ($args->stats) { stderr(message($stats, array('type' => 'stats')));