Skip to content

Instantly share code, notes, and snippets.

@cbfrance
Created March 7, 2012 00:59
Show Gist options
  • Save cbfrance/1990199 to your computer and use it in GitHub Desktop.
Save cbfrance/1990199 to your computer and use it in GitHub Desktop.
Visualize a Sass project
#!/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