diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index d7280a0..0983bd9 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -76,18 +76,26 @@ public function attachFiles($inputPath, $outputPath) } } + /** + * @return File[] + */ + public function getFiles() + { + return $this->files; + } + /** * @return string[] */ - public function concatOutput() + protected function concatOutput() { $outputMap = []; foreach ($this->files as $file) { if (!isset($outputMap[$file->getOutputPath()])) { - $outputMap[$file->getOutputPath()] = $file->getParsedContent(); - } else { - $outputMap[$file->getOutputPath()] .= $file->getParsedContent(); + $outputMap[$file->getOutputPath()] = ''; } + + $outputMap[$file->getOutputPath()] .= $file->getParsedContent(); } return $outputMap; @@ -117,26 +125,39 @@ public function saveOutput() */ public function processFiles($formatter) { + $this->sass->setFormatter($this->getFormatterClass($formatter)); + $this->io->write("use '{$formatter}' formatting"); + foreach ($this->files as $file) { $this->io->write("processing: {$file->getSourcePath()}"); $file->setSourceContentFromSourcePath(); - switch ($file->getType()) { - case File::TYPE_COMPASS: - case File::TYPE_SCSS: - case File::TYPE_SASS: - $this->sass->setFormatter($this->getFormatterClass($formatter)); - $content = $this->sass->compile($file->getSourceContent()); - break; - case File::TYPE_LESS: - $content = $this->less->compile($file->getSourceContent()); - break; - default: - throw new CompilerException('unknown compiler'); + try { + $this->processFile($file); + } catch (CompilerException $e) { + $this->io->writeError("failed to process: {$file->getSourcePath()}"); } + } + } - $file->setParsedContent($content); + /** + * @param File $file + * + * @return File + * @throws CompilerException + */ + public function processFile(File $file) + { + switch ($file->getType()) { + case File::TYPE_COMPASS: + case File::TYPE_SCSS: + case File::TYPE_SASS: + return $file->setParsedContent($this->sass->compile($file->getSourceContent())); + case File::TYPE_LESS: + return $file->setParsedContent($this->less->compile($file->getSourceContent())); } + + throw new CompilerException('unknown compiler'); } /**