From 631f8b9471ae52188ae9ede87b224678dffaed3d Mon Sep 17 00:00:00 2001 From: Eugene Matvejev Date: Thu, 30 Jun 2016 18:20:16 +0100 Subject: [PATCH] RC10 improve file processor --- src/Processor/Processor.php | 48 +++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index b4dc79e..88b850a 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -157,25 +157,47 @@ public function processFile(FileContainer $file) { switch ($file->getType()) { case FileContainer::TYPE_SCSS: - try { - $this->sass->addImportPath(dirname($file->getInputPath())); - $content = $this->sass->compile($file->getInputContent()); - - return $file->setOutputContent($content); - } catch (ParserException $e) { - throw new CompilerException($e->getMessage(), 1, $e); - } + return $this->compileSCSS($file); case FileContainer::TYPE_LESS: - try { - return $file->setOutputContent($this->less->compileFile($file->getInputPath())); - } catch (\Exception $e) { - throw new CompilerException($e->getMessage(), 1, $e); - } + return $this->compileLESS($file); } throw new CompilerException('unknown compiler'); } + /** + * @param FileContainer $file + * + * @return $this + * @throws CompilerException + */ + protected function compileSCSS(FileContainer $file) + { + try { + $this->sass->addImportPath(dirname($file->getInputPath())); + $content = $this->sass->compile($file->getInputContent()); + + return $file->setOutputContent($content); + } catch (ParserException $e) { + throw new CompilerException($e->getMessage(), 1, $e); + } + } + + /** + * @param FileContainer $file + * + * @return $this + * @throws CompilerException + */ + protected function compileLESS(FileContainer $file) + { + try { + return $file->setOutputContent($this->less->compileFile($file->getInputPath())); + } catch (\Exception $e) { + throw new CompilerException($e->getMessage(), 1, $e); + } + } + /** * @param string $formatter *