Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
Created January 9, 2014 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseppstein/8340689 to your computer and use it in GitHub Desktop.
Save chriseppstein/8340689 to your computer and use it in GitHub Desktop.
A ruby class for analyzing the dependencies in a sass file.
# extracts dependencies for a file
class DependencyExtractor
class Asset < Struct.new(:filename, :importer, :children)
def initialize(*args)
super
self.children ||= []
end
# transitive dependencies. Call `children` for just the immediate dependencies.
def dependencies
children.map {|child| [child, child.dependencies] }.flatten
end
end
include Sass::Plugin
def initialize(options = {})
@options = Sass::Engine.normalize_options(options)
end
def analyze(*files)
files.map {|f| analyze_file(f) }
end
def analyze_file(f, importer = importer)
children = checker.send(:dependencies, f, importer).map{|c| analyze_file(*c) }
Asset.new(f, importer, children)
end
def importer
@importer ||= @options[:filesystem_importer].new(".")
end
def checker
@checker ||= StalenessChecker.new(@options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment