rstacruz / sinatra-assetpack

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

Compass example incapable of importing partials #120

Closed shamrt closed 11 years ago

shamrt commented 11 years ago

Attempting to import a SASS partial file via main.scss in your Compass example leads to a 500 error.

Adding the line @import "base"; returns the following stack trace:

Sass::SyntaxError - File to import not found or unreadable: base.
Load paths:
  /Users/[username]/.gem/gems/compass-0.12.2/frameworks/blueprint/stylesheets
  /Users/[username]/.gem/gems/compass-0.12.2/frameworks/compass/stylesheets
  Compass::SpriteImporter:
    /Users/[username]/Sites/sha.nemart.in/sinatra-assetpack/lib/sinatra/assetpack/class_methods.rb:4
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/import_node.rb:67:in `rescue in import'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/import_node.rb:45:in `import'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/import_node.rb:28:in `imported_file'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/import_node.rb:37:in `css_import?'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:217:in `visit_import'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/base.rb:37:in `visit'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:100:in `visit'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/base.rb:53:in `map'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/base.rb:53:in `visit_children'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/base.rb:37:in `block in visit'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:128:in `visit_root'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/base.rb:37:in `visit'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:100:in `visit'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/visitors/perform.rb:7:in `visit'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/tree/root_node.rb:20:in `render'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/engine.rb:315:in `_render'
    /Users/[username]/.gem/gems/sass-3.2.9/lib/sass/engine.rb:262:in `render'
    /Users/[username]/.gem/gems/tilt-1.4.1/lib/tilt/css.rb:24:in `evaluate'
    /Users/[username]/.gem/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:798:in `render'
    /Users/[username]/Sites/sha.nemart.in/sinatra-assetpack/lib/sinatra/assetpack/class_methods.rb:90:in `block (4 levels) in add_individual_routes!'
    /Users/[username]/Sites/sha.nemart.in/sinatra-assetpack/lib/sinatra/assetpack/options.rb:293:in `fetch_dynamic_asset'
    /Users/[username]/Sites/sha.nemart.in/sinatra-assetpack/lib/sinatra/assetpack/class_methods.rb:89:in `block (3 levels) in add_individual_routes!'
    /Users/[username]/.gem/gems/tilt-1.4.1/lib/tilt.rb:127:in `fetch'
    /Users/[username]/Sites/sha.nemart.in/sinatra-assetpack/lib/sinatra/assetpack/class_methods.rb:88:in `block (2 levels) in add_individual_routes!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1540:in `call'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1540:in `block in compile!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:950:in `[]'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:950:in `block (3 levels) in route!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:966:in `route_eval'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:950:in `block (2 levels) in route!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:987:in `block in process_route'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:985:in `catch'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:985:in `process_route'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:948:in `block in route!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:947:in `each'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:947:in `route!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1059:in `block in dispatch!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `block in invoke'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `catch'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `invoke'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1056:in `dispatch!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:882:in `block in call!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `block in invoke'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `catch'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `invoke'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:882:in `call!'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:870:in `call'
    /Users/[username]/.gem/gems/rack-protection-1.5.0/lib/rack/protection/xss_header.rb:18:in `call'
    /Users/[username]/.gem/gems/rack-protection-1.5.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /Users/[username]/.gem/gems/rack-protection-1.5.0/lib/rack/protection/json_csrf.rb:18:in `call'
    /Users/[username]/.gem/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /Users/[username]/.gem/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /Users/[username]/.gem/gems/rack-protection-1.5.0/lib/rack/protection/frame_options.rb:31:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/nulllogger.rb:9:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:175:in `call'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1949:in `call'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1449:in `block in call'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1726:in `synchronize'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:1449:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/lint.rb:49:in `_call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
    /Users/[username]/.gem/gems/sinatra-1.4.3/lib/sinatra/base.rb:212:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/connection.rb:81:in `block in pre_process'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/connection.rb:79:in `catch'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/connection.rb:79:in `pre_process'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/connection.rb:54:in `process'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/connection.rb:39:in `receive_data'
    /Users/[username]/.gem/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
    /Users/[username]/.gem/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/backends/base.rb:63:in `start'
    /Users/[username]/.gem/gems/thin-1.5.1/lib/thin/server.rb:159:in `start'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
    /Users/[username]/.gem/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
    /Users/[username]/.gem/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
    /Users/[username]/.gem/bin/rackup:23:in `load'
    /Users/[username]/.gem/bin/rackup:23:in `<main>'

This appears to be a problem of not setting the appropriate load path for Compass.

j15e commented 11 years ago

Try something like import "app/css/base" as the SASS import relative path might be the app.rb and not your current scss file

shamrt commented 11 years ago

No change.

Given that this issue can be created with the sinatra-assetpack repository examples, I am interested to see whether it can be reproduced by another party. As aforesaid, the only difference between the pristine repository and what I am attempting to do is the addition of @import "base"; (and its corresponding SCSS partial file) to main.scss.

I should mention that adding c.sass_dir = "app/css" to app.rb makes no difference. And, once again, the stack trace indicates that the app load path is missing, which strikes me as bizarre.

bentruyman commented 11 years ago

Look at your load paths at the top of that stacktrace @shamrt. You'll need something like this in your assets configuration:

assets {
  set :scss, { :load_paths => Compass.sass_engine_options[:load_paths] + [ "#{settings.root}/app/css" ] }
  # the rest
}
shamrt commented 11 years ago

Thank-you, @bentruyman, that suggestion worked --- with some caveats, which are explained in a gist, in case anyone else runs into this issue and is as befuddled as I was.

bentruyman commented 11 years ago

Great gist. Hope others find it too.