lib/sprockets/sass/importer.rb in sprockets-sass-1.1.0 vs lib/sprockets/sass/importer.rb in sprockets-sass-1.2.0
- old
+ new
@@ -58,11 +58,11 @@
# a glob of files.
def engine_from_glob(glob, base_path, options)
context = options[:custom][:sprockets_context]
imports = resolve_glob(context, glob, base_path).inject('') do |imports, path|
context.depend_on path
- relative_path = path.relative_path_from Pathname.new(context.root_path)
+ relative_path = path.relative_path_from Pathname.new(base_path).dirname
imports << %(@import "#{relative_path}";\n)
end
return nil if imports.empty?
::Sass::Engine.new imports, options.merge(
:filename => base_path.to_s,
@@ -95,16 +95,21 @@
# Returns all of the possible paths (including partial variations)
# to attempt to resolve with the given path.
def possible_files(context, path, base_path)
path = Pathname.new(path)
base_path = Pathname.new(base_path).dirname
- root_path = Pathname.new(context.root_path)
paths = [ path, partialize_path(path) ]
+ # Find base_path's root
+ env_root_paths = context.environment.paths.map {|p| Pathname.new(p) }
+ root_path = env_root_paths.detect do |env_root_path|
+ base_path.to_s.start_with?(env_root_path.to_s)
+ end
+ root_path ||= context.root_path
+
# Add the relative path from the root, if necessary
if path.relative? && base_path != root_path
relative_path = base_path.relative_path_from(root_path).join path
-
paths.unshift(relative_path, partialize_path(relative_path))
end
paths.compact
end