/** * Process a file, executing Compass executable. * * Execute the Compass executable, overriding the no-op function inside * WordlessPreprocessor. */ protected function process_file($file_path, $result_path, $temp_path) { $this->validate_executable_or_die($this->preference("compass.compass_path")); // On cache miss, we build the file from scratch $pb = new ProcessBuilder(array($this->preference("compass.compass_path"), 'compile', $temp_path)); $config = array("http_path" => Wordless::theme_url(), "images_dir" => "assets/images", "css_path" => $temp_path, "relative_assets" => false, "output_style" => ":" . $this->preference("compass.output_style"), "environment" => ":production", "sass_path" => dirname($file_path)); $ruby_config = array(); foreach ($config as $name => $value) { if (strpos($value, ":") === 0) { $ruby_config[] = sprintf('%s = %s', $name, $value); } else { if (is_bool($value)) { $ruby_config[] = sprintf('%s = %s', $name, $value ? "true" : "false"); } else { $ruby_config[] = sprintf('%s = "%s"', $name, addcslashes($value, '\\')); } } } $config_path = tempnam($temp_path, 'compass_config'); file_put_contents($config_path, implode("\n", $ruby_config) . "\n"); $pb->add("--config")->add($config_path); $output = $temp_path . "/" . basename($file_path, pathinfo($file_path, PATHINFO_EXTENSION)) . 'css'; $proc = $pb->getProcess(); $code = $proc->run(); if (0 < $code) { unlink($config_path); $this->die_with_error($proc->getErrorOutput()); } unlink($config_path); return file_get_contents($output); }