jasonlewis / basset

A better asset management package for Laravel.
http://jasonlewis.me/code/basset
240 stars 76 forks source link

Compass Filter #164

Closed jallits closed 11 years ago

jallits commented 11 years ago

I know this is the wrong place, but does anyone have a working Compass Filter utilizing leafo/scss-compass.

I've been struggling with this for a good time now.

jasonlewis commented 11 years ago

Hm, I can have a go at an implementation of the filter later.

jallits commented 11 years ago

Can I suggest that in the docs we have a page of pre-defined filters. I think there was an issue where it was discussed moving the docs to Github so that the community could contribute. It would be more useful there, versus you having to support the list of all the possible filters yourself.

jasonlewis commented 11 years ago

Yeah filters need to be covered a bit more since Assetic doesn't really have solid documentation (that I could find). Basset docs are available on GitHub now.

fedeisas commented 11 years ago

I've tried to do this a few days ago.

Add a new filter definition to your config/packages/jasonlewis/basset/aliases.php

'MyCompassFilter' => array('CompassFilter', function($filter)
{
    $filter->setArguments('/usr/local/bin/compass', null);
    $filter->beforeFiltering(function($filter) 
    {
        $filter->setStyle('compressed');
        $filter->setPlugins(array('rgbapng')); //this works as require on config.rb
     });
})

Set the file on your collection with the new filter on config/packages/jasonlewis/basset/aliases.php

$directory = $collection->directory('assets/stylesheets', function($collection)
{
    $collection->stylesheet('scss/app.scss')->apply('MyCompassFilter');
});

It's a common pattern for Compass users to have a main app.scss that @imports a lot of partials (partials have underscored _filenames.scss).

My problem right now is that Basset/Assetic won't watch those partials for changes, so it won't recompile when I change a partial and leave my main app.scss the same.

Any ideas on how to solve this?

Thanks!

jallits commented 11 years ago

That works! Thanks @fedeisas!

I am going to close this issue since the matter of partials is completely different.

richardvanbergen commented 11 years ago

Just thought I'd comment on the whole partials thing because I am having the same issue and this is the first result on Google. They only way I have found to make sure LESS/SASS is compile totally on every page request is to make:

Basset\Builder\Builder::$force = true;

Unfortunately the only way to change this property without modifying the code directly is to overload the Builder class. Which I'm sure is possible but is too much hassle. I don't have time to figure out how basset does its configuration otherwise I'd submit a pull request but it seems to me at least that this should be available in the configs. Either that or do it properly but that sounds like overkill for such a small problem.