public function parseFile($file, $overwrite = false) { if (!$this->read_dir) { StylusException::report('No read directory specified'); } if (!$this->write_dir) { StylusException::report('No write directory specified'); } if (preg_match('~(\\.styl(?:us)$)|(^[^\\.]+$)~', $file)) { $file = preg_replace('~(\\.styl)+$~', '.styl', $file . '.styl'); $writename = $this->write_dir . '/' . preg_replace('~\\.styl$~', '.css', $file); if (file_exists($writename) && !$overwrite) { return; } $filename = $this->read_dir . '/' . $file; $file_handle = fopen($filename, 'r') or StylusException::report('Could not open ' . $filename); $contents = fread($file_handle, filesize($filename)) or StylusException::report('Could not read ' . $filename); $lines = array_values(array_filter(preg_replace('~^\\s*}\\s*$~', '', preg_split('~\\r\\n|\\n|\\r~', $contents)), 'strlen')); $this->read_file = $filename; DependancesCache::flush($filename); for ($i = 0; $i < count($lines); $i++) { $line = $lines[$i]; if ($this->isFunctionDeclaration($line)) { $this->addFunction($lines, $i); } else { if ($this->isVariableDeclaration($lines, $i)) { $this->addVariable($line); } else { if ($this->isBlockDeclaration($lines, $i)) { $this->addBlock($lines, $i); } else { if ($this->isImport($line)) { $this->import($lines, $i); } } } } } fclose($file_handle); $this->convertBlocksToCSS(); if ($this->file) { $file_handle = fopen($writename, 'w') or StylusException::report('Could not open ' . $writename); fwrite($file_handle, $this->file) or StylusException::report('Could not write to ' . $writename); fclose($file_handle); } } $this->functions = array(); $this->blocks = array(); $this->vars = array(); $this->file = ''; }
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; }