Created
January 9, 2014 19:48
-
-
Save chriseppstein/8340689 to your computer and use it in GitHub Desktop.
A ruby class for analyzing the dependencies in a sass file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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