Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative @imports within isolated engine not found #137

Closed
rymohr opened this issue Feb 28, 2013 · 12 comments
Closed

Relative @imports within isolated engine not found #137

rymohr opened this issue Feb 28, 2013 · 12 comments

Comments

@rymohr
Copy link

rymohr commented Feb 28, 2013

Given an engine like the following

module Foo
  class Engine < ::Rails::Engine
    isolate_namespace Foo # corrected namespace from original post
  end
end

And the corresponding namespaced folder structure

app
  assets
    stylesheets
      foo
        application.css.scss
        style.css.scss

Relative imports within the engine don't appear to be working. For example:

# app/stylesheets/application.css.scss (host)
@import "foo/application"

# app/stylesheets/foo/application.css.scss (engine)
@import "style"     # not found
@import "foo/style" # works

Sass appears to be checking relative to the host file instead of relative to application.css.scss itself. Is this the intended behavior? I always thought @import was relative to the current file.

Just want to make sure I'm not doing something stupid. Feels dirty having to namespace the relative requires within the engine itself.

@jhilden
Copy link

jhilden commented Feb 28, 2013

I'm pretty sure this is intendet behavior with the folder structure you have.

You can read about Sprockets load_path here: https://github.com/sstephenson/sprockets#the-load-path

@rymohr
Copy link
Author

rymohr commented Feb 28, 2013

Using Sprockets directly I can easily load the relative file using

#= require ./style

But then I lose all the inherited goodness @import provides. Seems funny I can't just do the following instead of having to use the full logical path:

@import "./style"

@rafaelfranca
Copy link
Member

@import is a sass feature. We don't change it on this project.

@rymohr
Copy link
Author

rymohr commented Feb 28, 2013

I take it this project is responsible for supplying the load paths then?

From: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import

Sass looks for other Sass files in the current directory, and the Sass file directory under Rack, Rails, or Merb. Additional search directories may be specified using the :load_paths option, or the --load-path option on the command line.

@rymohr
Copy link
Author

rymohr commented Feb 28, 2013

I've opened a similar issue on the SASS project: sass/sass#672

We'll see what they say.

@rymohr
Copy link
Author

rymohr commented Mar 2, 2013

The guys at SASS say this is a sass-rails issue and that SASS by default will always search relative to the current file first.

@rafaelfranca
Copy link
Member

Right. @guilleiguaran thoughts?

@glebm
Copy link

glebm commented Feb 5, 2014

This appears to have been fixed at some point. The bug is not present in the current gem, but still there in the latest release for Rails 3. Would be awesome if a version with the fix could be released for rails3, as this bug makes it very hard to provide x-platform Sass code (see twbs/bootstrap-sass#523).

@rafaelfranca
Copy link
Member

@glebm I did some investigation about this here: https://github.com/radar/rafael/pull/1

I uses bootstrap-sass as example of right usage of the import path but seems it is changed now.

TL;DR, a workaround is always use absolute path if you want to make possible users to override. The propex fix is change sass-rails/sass to put the current folder at the end of the load path. I could not work on this yet, sorry.

@glebm
Copy link

glebm commented Feb 5, 2014

@rafaelfranca Sass is probably not it because I'm using the same sass in Rails 4 and it just works.

Nothing relevant seems to have changed in sass-rails between versions either.
This narrows it to sprockets / sprockets-rails. Looking through the recent changes in sprockets, this commit may be relevant asset pipeline is like an onion 😢

Absolute path workaround breaks it for bower, composer, and standalone sass.

@glebm
Copy link

glebm commented Feb 5, 2014

Looks like sprockets no longer modifies Sass path resolution since this commit 2 years ago, which may be why this works in Rails 4. sstephenson/sprockets@d9ba0d4

@glebm
Copy link

glebm commented Feb 6, 2014

bootstrap-sass now uses relative paths that resolve both from load_path and from the file's location for older sprockets compatibility.

benlangfeld added a commit to powerhome/bootstrap-sass that referenced this issue Oct 25, 2016
In 2e1ca4e, all imports in _bootstrap.scss were namespaced to support older Rails/Sprockets (see rails/sass-rails#137 (comment)). Unfortunately, this wasn't also applied to the mixins sub-directory, causing failures like twbs#806.

See twbs#806 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants