CodeSleeve / asset-pipeline

This Laravel 4 package provides a very simple and easy to use asset pipeline. It was heavily inspired by the Rails asset pipeline. We make use of the wonderful Assetic package to help with pre-compliation!
http://www.codesleeve.com
MIT License
489 stars 53 forks source link

[Proposal] sass support #156

Closed kdocki closed 10 years ago

kdocki commented 10 years ago

Looks like the guys over at https://github.com/richthegeek/phpsass are maintaining a fork of phamlp. I tried this out and have successfully gotten sass to work. I will bring this into pipeline once I do some more testing.

<?php namespace Codesleeve\AssetPipeline\Filters;

use Assetic\Asset\AssetInterface;
use Assetic\Filter\FilterInterface;

class SassFilter implements FilterInterface
{
    public function filterLoad(AssetInterface $asset)
    {

    }

    public function filterDump(AssetInterface $asset)
    {
        $file = $asset->getSourceRoot() . '/' . $asset->getSourcePath();

        $options = array(
            'style'=>'nested',
        );

        $sass = new SassParser($options);

        $parsed = $sass->toCss($file);

        $asset->setContent($parsed);
    }
}

I am having to use the real file path though in order to compile because it cannot find @import statements otherwise.

kdocki commented 10 years ago

this is done ... will update docs later once this has been tested some more.

kdocki commented 10 years ago

looks like if we have errors in our sass it gives us an ErrorException Undefined offset: 1 ...

aheissenberger commented 10 years ago

This is my hack to use Libsass which is much faster:

Sass ah$ diff SassFilter.php.bak SassFilter.php
47c47
<     public function __construct($sassPath = '/usr/bin/sass', $rubyPath = null)
---
>     public function __construct($sassPath = '/usr/local/bin/sassc', $rubyPath = null)
122,130c122
<             $pb->add('--load-path')->add(dirname($root.'/'.$path));
<         }
< 
<         if ($this->unixNewlines) {
<             $pb->add('--unix-newlines');
<         }
< 
<         if (true === $this->scss || (null === $this->scss && 'scss' == pathinfo($path, PATHINFO_EXTENSION))) {
<             $pb->add('--scss');
---
>             $pb->add('-I')->add(dirname($root.'/'.$path));
134,138c126
<             $pb->add('--style')->add($this->style);
<         }
< 
<         if ($this->quiet) {
<             $pb->add('--quiet');
---
>             $pb->add('-t')->add($this->style);
142c130
<             $pb->add('--debug-info');
---
>             $pb->add('-g');
146c134
<             $pb->add('--line-numbers');
---
>             $pb->add('-l');
149,155c137
<         foreach ($this->loadPaths as $loadPath) {
<             $pb->add('--load-path')->add($loadPath);
<         }
< 
<         if ($this->cacheLocation) {
<             $pb->add('--cache-location')->add($this->cacheLocation);
<         }
---
>         $pb->add('-i')->add('/assets');
157,162c139,140
<         if ($this->noCache) {
<             $pb->add('--no-cache');
<         }
< 
<         if ($this->compass) {
<             $pb->add('--compass');
---
>         foreach ($this->loadPaths as $loadPath) {
>             $pb->add('-I')->add($loadPath);
evantishuk commented 10 years ago

Can you clarify the intent? Is because of the known issues with leafo/scssphp? Or are you looking to support the more terse sass syntax (the superset of scss)? They're both "sass" so I guess I'm just confused.