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

Specs and fixes for nested partials with relative paths problem #28

Merged
merged 1 commit into from Apr 19, 2014

Conversation

kukushkin
Copy link
Contributor

This fixes "File to import not found or unreadable" problem when there are several load paths, and imported partials use relative paths:
#27

I believe context.root_path is to blame:
https://github.com/petebrowne/sprockets-sass/blob/master/lib/sprockets/sass/importer.rb#L100
https://github.com/petebrowne/sprockets-sass/blob/master/lib/sprockets/sass/importer.rb#L63

There a two problems with that.

  1. Once you start using several assets load paths, you essentially have several "roots" to build relative path from.

For example, a file A in assets/ imports a file B from vendor/. Now, if any @import directive in file B uses relative path, you would want to build this relative path from vendor/, but context.root_path points to assets/.

  1. Sprockets::Context#resolve() treats relative paths starting with '.' or '..' as if they originated from context.pathname.dirname which is the actual directory where file A resides, not from context.root_path.
    https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/context.rb#L78

Current sprockets-sass code builds relative paths from context.root_path, which in case of file A in assets/ and file B in vendor/ come in form ../vendor/. This works only when context.pathname.dirname and context.root_path are the same. I.e. if file A is at the topmost level in assets/. Placing it somewhere deeper, like in assets/folder/, breaks things.

My patch fixes these problems by finding appropriate root_path, so a relative path built from it is resolved properly by Sprockets::Context#resolve().

- fixes "File to import not found or unreadable" problem when there are several load paths, and imported partials use relative paths

petebrowne#27
petebrowne added a commit that referenced this pull request Apr 19, 2014
Specs and fixes for nested partials with relative paths problem
@petebrowne petebrowne merged commit e43a2fb into petebrowne:master Apr 19, 2014
@petebrowne
Copy link
Owner

Thanks for this!

@kukushkin
Copy link
Contributor Author

That was fast 8) thanks @petebrowne

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

Successfully merging this pull request may close these issues.

None yet

2 participants