Created
March 7, 2012 00:59
-
-
Save cbfrance/1990199 to your computer and use it in GitHub Desktop.
Visualize a Sass project
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'graphviz' | |
class Visualizer | |
def initialize | |
@g = GraphViz.new( "G", :type => "graph", :rankdir => "LR", :bgcolor => "#808080", :aspect => 1 ) | |
end | |
def prune(file) | |
file.gsub(/\S+\/(\S+)\.scss/, '\\1').gsub(/@import ['"](\S+\/)?(\S+)['"];/, '\\2') | |
end | |
def process_files( files ) | |
files.each do |file| | |
puts "Opening: #{file} ..." | |
@g.add_nodes( prune(file) ) | |
lines = File.open(file).readlines | |
lines.each do |l| | |
if l =~ /@import/ | |
puts prune(l) | |
@g.add_nodes(prune(l)) | |
@g.add_edges(prune(l), prune(file)) | |
end | |
end | |
end | |
end | |
def save | |
@g.output(:dot => "hi.dot") | |
end | |
end | |
v = Visualizer.new | |
v.process_files(Dir["scss/*.scss"]) | |
v.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment