Created
January 5, 2014 19:43
-
-
Save WardCunningham/8272845 to your computer and use it in GitHub Desktop.
Visualize the possible flows of variables within Method plugins in a Federated Wiki site.
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
# scan all methods of all pages for variables | |
# create a graphviz dot file maping cross-references | |
# scp -r fed.wiki.org:farm/mehaffy.fed.wiki.org/pages pages | |
# coffee cross-ref.coffee | |
# graphviz cross-ref.dot | |
fs = require 'fs' | |
pageDir = 'pages' | |
pageNames = fs.readdirSync pageDir | |
dot = [] | |
dotPage = (pageName) -> | |
segs = pageName.split /-+/ | |
"\"#{segs.join '\\n'}\"" | |
dotVar = (varName) -> | |
# segs = varName.split /\s+/ | |
# "\"#{segs.join '\\n'}\"" | |
newName = varName.replace /(\S+\s+\S+)\s+/g, '$1\\n' | |
"\"#{newName}\"" | |
scanForVariables = (pageName, title, lines) -> | |
set = (varName) -> | |
dot.push "#{dotVar title} [shape=box fillcolor=palegreen]" | |
dot.push "#{dotVar title} -> #{dotVar varName}" | |
get = (varName) -> | |
dot.push "#{dotVar title} [shape=box fillcolor=palegreen]" | |
dot.push "#{dotVar varName} -> #{dotVar title}" | |
for line in lines | |
if args = line.match /^([0-9.eE-]+) +([\w \.%(){},&\*\/+-]+)$/ | |
set args[2] | |
else if args = line.match /^([A-Z]+) +([\w \.%(){},&\*\/+-]+)$/ | |
set args[2] | |
else if args = line.match /^([A-Z]+)$/ | |
else if args = line.match /^[0-9\.eE-]+$/ | |
else if args = line.match /^ *([\w \.%(){},&\*\/+-]+)$/ | |
get args[1] | |
scanForMethods = (pageName) -> | |
return if pageName.match /^\./ | |
page = JSON.parse fs.readFileSync "#{pageDir}/#{pageName}", 'utf-8' | |
for item in page.story | |
if item.type is 'method' | |
scanForVariables pageName, page.title, item.text.split(/\n/) | |
for pageName in pageNames | |
scanForMethods pageName | |
text = "strict digraph {\nnode [style=filled fillcolor=gold]\n#{dot.join "\n"}\n}" | |
fs.writeFileSync 'cross-ref.dot', text, 'utf-8' | |
console.log "#{dot.length} relations" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment