Skip to content

Instantly share code, notes, and snippets.

@rlivsey
Created January 21, 2010 17:28
Show Gist options
  • Save rlivsey/282966 to your computer and use it in GitHub Desktop.
Save rlivsey/282966 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'graphviz'
path, output = ARGV
regex = /render\W+:partial\W+=>\W+"([\w\/]+)"/
@nodes = {}
@graph = GraphViz.new( :structs, :type => :digraph )
def absolutize(container, partial)
dir = File.dirname(container)
unless partial.include? "/"
partial = File.join(dir, "_#{partial}")
else
File.join(File.dirname(partial), "_#{File.basename(partial)}")
end
end
def node(path)
@nodes[path] ||= @graph.add_node(path)
end
Dir.chdir(path) do
Dir.glob("**/*.*").each do |file|
File.open(file, 'r').each_line do |line|
if match = line.match(regex)
partial = match[1]
abs_partial = absolutize(file, partial)
abs_file = file.gsub(/\..*$/, '')
partial_node = node(abs_partial)
file_node = node(abs_file)
@graph.add_edge(partial_node, file_node)
end
end
end
end
@graph.output( :png => output )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment