Skip to content

Instantly share code, notes, and snippets.

@xen
Created February 29, 2012 09:29
Show Gist options
  • Select an option

  • Save xen/1939420 to your computer and use it in GitHub Desktop.

Select an option

Save xen/1939420 to your computer and use it in GitHub Desktop.
find templates/ -name '*.html'|xargs -n 1 gawk '
BEGIN {ln=0;}
{ln+=1}
ln==1 {
gsub("templates/?","",FILENAME);
label=FILENAME;
gsub("[/.]", "_", FILENAME);
cluster=label;
sub("/[^/]*$", "", cluster);
print "###CLUSTER " cluster;
sub("^.*/", "", label);
print "f_" FILENAME "[label=\"" label "\"]";
}
/{%[[:space:]]*extends[[:space:]]*[[:punct:]][^%]+%}/ {
gsub("[/.]", "_");
match($0, /{%[[:space:]]*extends[[:space:]][[:punct:]](.*)[[:punct:]][[:space:]]%}/, ary);
print "f_" FILENAME " -> f_" ary[1] " [arrowhead = empty]; ";
}
/{%[[:space:]]*include[^%]+%}/ {
gsub("[/.]", "_");
match($0, /{%[[:space:]]*include[[:space:]][[:punct:]]([a-zA-Z0-9_/.]*)[[:punct:]][[:space:]](with|%)/, ary);
print "f_" FILENAME " -> f_" ary[1] " [style = dotted, constraint = false, color = gray]; ";
}'|gawk '
BEGIN {
cur_cluster=""; theend=""
print "digraph G \{rankdir=LR;"
print "node[shape=box, style=filled]"
}
END {
if (cur_cluster) print "}";
print theend
print "\}";
}
/^###CLUSTER / {
sub("^###CLUSTER ", "");
if (cur_cluster!=$0) {
if (cur_cluster) print "}";
cluster = $0
gsub("[/.]", "_", cluster);
if ($0) print "subgraph cluster" cluster " { label=\"" $0 "\"";
cur_cluster = $0;
}
$0="";
}
/->/ {
theend = theend $0;
$0=""
}
{if ($0) print}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment