petebrowne / sprockets-sass

Better Sass integration with Sprockets 2.x
MIT License
90 stars 29 forks source link

Can't pass sass options #30

Closed pablox-cl closed 9 years ago

pablox-cl commented 9 years ago

I'm using sprockets-sass outside rails/sinatra... (actually on nanoc). And while sprockets-sass it's actually working, I can't make the sass options to pass, and in the end I always get a compressed css.

# lib/helper.rb
Sprockets::Sass.options[:line_comments] = true
#Sprockets::Sass.options[:line_comments] = true # tried with this too

I tried to debug where the problem is, and I found that

# sass.template.rb
def evaluate
....
::Sass::Engine.new(data, sass_options).render

it indeed renders correctly (output style, line_comments, ecc), but somewhere along the way, it gets everything squashed. Looks like sprockets it's doing it thing regardless where these options are set.

The "BundledAsset" I got from the find_asset sprockets method, returns the squashed file. Maybe the problem has to do with that?

petebrowne commented 9 years ago

Ok, I'll take a look - it might take me awhile to debug. If you figure it out, please submit a pull request

pablox-cl commented 9 years ago

I tried to narrow this, and it seems that is because in BundledAsset#initialize, the context.evaluate line:

@source = context.evaluate(pathname, :data => @source, :processors => environment.bundle_processors(content_type))

...calls

Sprockets::SassCompressor#evaluate

instead of

Sprockets::Sass::SassTemplate#evaluate

This leads to:

sprockets-2.12.2/lib/sprockets/sass_compressor.rb @ line 19 Sprockets::SassCompressor#evaluate:

    18: def evaluate(context, locals, &block)
 => 19:   binding.pry
    20:   ::Sass::Engine.new(data, {
    21:     :syntax => :scss,
    22:     :cache => false,
    23:     :read_cache => false,
    24:     :style => :compressed
    25:   }).render
    26: end

And therefore Sprockets::Sass.options are discarded.

PS.- By mistake I deleted the previous comment =/

petebrowne commented 9 years ago

Are you setting the css_compressor option? If so, that could certainly be overriding the output. If not, I don't see why the Sass::Compressor would be evaluated. Which version of Sprockets are you using?

pablox-cl commented 9 years ago

oh my lol. You are right... I had it set it up in a nasty place, and I totally forgot about it. Sorry for the noise :/. When debugging, I never stumbled into any check for css_compressor, how did you find it out?

petebrowne commented 9 years ago

Just remembered that's generally how the Sass::Compressor is configured