From f5043c2a8f67035220cc04aba6d24e3027fc9a64 Mon Sep 17 00:00:00 2001 From: Aaron Scherer Date: Sun, 20 Jul 2014 17:29:13 -0700 Subject: [PATCH 1/2] Adding sass call --- composer.json | 4 +- src/Call/LessCall.php | 1 - src/Call/SassCall.php | 94 +++++++++++++++++++++++++++++++++++++++++++ src/FrontendBlock.php | 1 + 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 src/Call/SassCall.php diff --git a/composer.json b/composer.json index 43a8a4c..9b858a4 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "description": "Block for handling the Front End tasks (less/sass, css and js min, etc)", "require": { "oyejorge/less.php": "~1.7.0", - "leafo/scssphp": "~0.0.10", + "richthegeek/phpsass": "dev-master", "matthiasmullie/minify": "~1.2.0", "tedivm/jshrink": "~1.0.0", "coffeescript/coffeescript": "~1.3.1" }, "require-dev": { - "bldr-io/bldr": "~4.1", + "bldr-io/bldr": "~6.2@stable", "dflydev/embedded-composer": "dev-master", "composer/composer": "dev-master" }, diff --git a/src/Call/LessCall.php b/src/Call/LessCall.php index 0ecd1cf..e551860 100644 --- a/src/Call/LessCall.php +++ b/src/Call/LessCall.php @@ -95,7 +95,6 @@ private function getLessOptions() */ private function compileFiles(array $files, $destination) { - $content = ''; foreach ($files as $file) { if ($this->getOutput()->isVerbose()) { $this->getOutput()->writeln("Compiling ".$file); diff --git a/src/Call/SassCall.php b/src/Call/SassCall.php new file mode 100644 index 0000000..60e0b8c --- /dev/null +++ b/src/Call/SassCall.php @@ -0,0 +1,94 @@ + + * + * This source file is subject to the license that is bundled + * with this source code in the file LICENSE + */ + +namespace Bldr\Block\Frontend\Call; + +use Bldr\Call\AbstractCall; +use Bldr\Call\Traits\FinderAwareTrait; +use SassParser; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; + +/** + * @author Aaron Scherer + */ +class SassCall extends AbstractCall +{ + use FinderAwareTrait; + + /** + * @var SassParser $sass + */ + private $sass; + + /** + * {@inheritDoc} + */ + public function configure() + { + $this->setName('sass') + ->setDescription('Compiles the `src` sass/scss files') + ->addOption('src', true, 'Sass/Scss files to compile') + ->addOption('dest', true, 'Destination to save to') + ->addOption('compress', false, 'Should bldr remove whitespace and comments'); + } + + /** + * {@inheritDoc} + */ + public function run() + { + $this->sass = new SassParser($this->getSassOptions()); + + $source = $this->getOption('src'); + $files = $this->getFiles($source); + + $this->compileFiles($files, $this->getOption('dest')); + } + + /** + * @return array + * @throws \RuntimeException + */ + private function getSassOptions() + { + $options = []; + if ($this->getOption('compress') === true) { + $options['style'] = \SassRenderer::STYLE_COMPRESSED; + } + + return $options; + } + + /** + * @param SplFileInfo[] $files + * @param string $destination + */ + private function compileFiles(array $files, $destination) + { + if ($this->getOutput()->isVerbose()) { + foreach ($files as $file) { + $this->getOutput()->writeln("Compiling ".$file); + } + } + + $output = $this->sass->toCss($files); + + if ($this->getOutput()->isVerbose()) { + $this->getOutput()->writeln("Writing to ".$destination); + } + + $fs = new Filesystem; + $fs->mkdir(dirname($destination)); + $fs->dumpFile($destination, $output); + } +} diff --git a/src/FrontendBlock.php b/src/FrontendBlock.php index 667a14f..3328062 100644 --- a/src/FrontendBlock.php +++ b/src/FrontendBlock.php @@ -25,6 +25,7 @@ class FrontendBlock extends AbstractBlock protected function assemble(array $config, SymfonyContainerBuilder $container) { $this->addCall('bldr_frontend.less', 'Bldr\Block\Frontend\Call\LessCall'); + $this->addCall('bldr_frontend.sass', 'Bldr\Block\Frontend\Call\SassCall'); $this->addCall('bldr_frontend.coffee', 'Bldr\Block\Frontend\Call\CoffeeCall'); $this->addCall('bldr_frontend.concat', 'Bldr\Block\Frontend\Call\ConcatCall'); $this->addCall('bldr_frontend.minify.css', 'Bldr\Block\Frontend\Call\Minify\CssCall'); From 2f325de5d9ca302fa1ce9a06bfb970c779cd53dd Mon Sep 17 00:00:00 2001 From: Aaron Scherer Date: Sun, 20 Jul 2014 17:38:26 -0700 Subject: [PATCH 2/2] Fixing issue with sass compielr --- src/Call/SassCall.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Call/SassCall.php b/src/Call/SassCall.php index 60e0b8c..8060fa3 100644 --- a/src/Call/SassCall.php +++ b/src/Call/SassCall.php @@ -75,13 +75,15 @@ private function getSassOptions() */ private function compileFiles(array $files, $destination) { - if ($this->getOutput()->isVerbose()) { - foreach ($files as $file) { + $fileSet = []; + foreach ($files as $file) { + if ($this->getOutput()->isVerbose()) { $this->getOutput()->writeln("Compiling ".$file); } + $fileSet[] = (string) $file; } - $output = $this->sass->toCss($files); + $output = $this->sass->toCss($fileSet); if ($this->getOutput()->isVerbose()) { $this->getOutput()->writeln("Writing to ".$destination);