rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
541 stars 97 forks source link

sass "@import" directive won't work with local files #56

Closed mdesantis closed 12 years ago

mdesantis commented 12 years ago

Hello,

in my app I have

class Web < Sinatra::Base

  Compass.configuration do |c|
    c.project_path = root
    # c.sass_dir = File.join(SINATRA_ROOT_DIR, 'public/scss')
    # c.add_import_path File.join(SINATRA_ROOT_DIR, 'public/scss')
    c.images_dir = 'public/images'
    c.http_images_path = '/images'
  end

  assets do
    serve '/css', :from => 'public/scss'
    css :screen, ['/css/screen.css']
  end

end

in public/scss/screen.scss:

@import 'partials/base'

In the Sinatra root folder:

public
  images
  scss
    screen.scss
    partials
      _base.scss

But I have this error:

Sass::SyntaxError - File to import not found or unreadable: partials/base.
Load paths:
  /home/izietto/.rvm/gems/ruby-1.9.3-p194/gems/compass-0.12.1/frameworks/blueprint/stylesheets
  /home/izietto/.rvm/gems/ruby-1.9.3-p194/gems/compass-0.12.1/frameworks/compass/stylesheets
  Compass::SpriteImporter:
    /home/izietto/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-assetpack-0.0.11/lib/sinatra/assetpack/class_methods.rb:5

I have this error also if I uncomment the Compass configuration lines

c.sass_dir = File.join(SINATRA_ROOT_DIR, 'public/scss')
c.add_import_path File.join(SINATRA_ROOT_DIR, 'public/scss')

But @import works for blueprint.

rstacruz commented 12 years ago

You need to change your Sinatra's SASS settings to point to the right load paths. See issue #14. Let me know if this helps. Cheers!

mdesantis commented 12 years ago

It worked :-) Maybe it could be useful adding this custom configuration here https://github.com/rstacruz/sinatra-assetpack/blob/master/examples/compass/app.rb , something like this:

# Customize the scss folder (optional)
# If you want to change the scss folder you have to set some configurations
# (see https://github.com/chriseppstein/compass/wiki/Sinatra-Integration for further infos):
# set :sass, Compass.sass_engine_options
# set :sass, { :load_paths => sass[:load_paths] + [ "#{App.root}/assets/stylesheets" ] }
#
# set :scss, sass
#
# assets do
#   serve '/css', :from => 'assets/stylesheets'
# end

I think it would be useful, because I found it hard to get informations about this error (I do not always open issues, but when I do, I spend two hours on Google before :D )

Oh, thanks for your library, It was just what I needed.

rstacruz commented 12 years ago

Sorry about that. I should probably add it to the readme... this is a fairly common concern afterall.

(Tech reason it works like this: AssetPack simply delegates Sass/Coffee/etc rendering to Sinatra, so you simply configure it the Sinatra way.)

rstacruz commented 12 years ago

Feel free to open a pull request to edit that file if you like, I'll merge it in. :)