Skip to content

Commit

Permalink
Merge pull request #1 from aequasi/master
Browse files Browse the repository at this point in the history
This PR was merged into bldr-io:master branch.

Discussion
----------

Adding Sass/Scss compiler

                   
|Q            |A  |
|---          |---|
|Bug Fix?     |n  |
|New Feature? |y  |
|BC Breaks?   |n  |
|Deprecations?|n  |
|Tests Pass?  |n  |
|Fixed Tickets|   |
|License      |MIT|
|Doc PR       |   |
                   



Commits
-------

f5043c2 Adding sass call aequasi
2f325de Fixing issue with sass compielr aequasi
  • Loading branch information
cryptiklemur committed Jul 21, 2014
2 parents 136e215 + 2f325de commit ef6cf25
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 0 additions & 1 deletion src/Call/LessCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
96 changes: 96 additions & 0 deletions src/Call/SassCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* This file is part of frontend-block
*
* (c) Aaron Scherer <aequasi@gmail.com>
*
* 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 <aequasi@gmail.com>
*/
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)
{
$fileSet = [];
foreach ($files as $file) {
if ($this->getOutput()->isVerbose()) {
$this->getOutput()->writeln("Compiling ".$file);
}
$fileSet[] = (string) $file;
}

$output = $this->sass->toCss($fileSet);

if ($this->getOutput()->isVerbose()) {
$this->getOutput()->writeln("Writing to ".$destination);
}

$fs = new Filesystem;
$fs->mkdir(dirname($destination));
$fs->dumpFile($destination, $output);
}
}
1 change: 1 addition & 0 deletions src/FrontendBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ef6cf25

Please sign in to comment.