Skip to content

Instantly share code, notes, and snippets.

@chrisirhc
Created February 4, 2013 01:41
Show Gist options
  • Save chrisirhc/4704595 to your computer and use it in GitHub Desktop.
Save chrisirhc/4704595 to your computer and use it in GitHub Desktop.
A function to resolve sass dependencies. Might come in handy with the grunt sass plugin. This is from guard-sass reference to: https://github.com/hawx/guard-sass/pull/31
def resolve_partials_to_owners(paths)
# Get all files that might have imports
root = (options[:input][-1] == "/" ? options[:input] : "#{options[:input]}/").reverse
search_files = Dir.glob("#{options[:input]}/**/*.s[ac]ss")
search_files = Watcher.match_files(self, search_files)
# Get owners
owners = search_files.select do |file|
# Get dependencies of file
deps = Sass::Engine.for_file(file, {}).dependencies.collect! {|dep| dep.options[:filename]}
# Find intersection with paths
deps_in_paths = deps.intersection paths
# Any paths in the dependencies?
!deps_in_paths.empty?
end
# Return our resolved set of paths to recompile
paths + owners
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment