Graphviz for Windowsにかませるちょっとしたマクロ的な何か

最近、職場ではPukiwikigraphvizプラグインを使いまくっている。
あのプラグインで地味に便利なのが、マクロ定義機能。Cの#defineみたいなもので

#graphviz(define,DFD:Entity,[shape="box",style="filled",fillcolor="#FFFFDD"])

なんて定義をしておくと、graphvizで何か書こうってときに

#graphviz{{{
 digraph { node DFD:Entity; a -> b; };
}}};

なんてな具合に書くと、DFD:Entityの部分が定義に置き換わるっていう便利なもの。
これは便利なんだけど、毎回プラグインを通してプレビューするとサーバに負荷が掛かるし、遅い。
そこでGraphviz for Winに付属しているGVEdit.exeを使ってやることにした。
Tipsのページを参考にさせてもらい、GVEdit.exeにバイナリパッチをあてたものを用意した。あとはマクロを置換してくれるいんちきツールがあればいい。
それが以下。Rubyで書いた。

#!/bin/ruby

require 'nkf'

prologue = <<EOP
graph[fontname="MS GOTHIC"];
edge[fontname="MS GOTHIC"];
node[fontname="MS GOTHIC"];
EOP

conv = {
 'DFD:Entity' => '[shape="box",style="filled",fillcolor="#FFFFDD"]',
 'DFD:Process' => '[shape="circle",style="filled",fillcolor="#DDDDFF",width=0.7,fixedsize=true]',
 'DFD:IF' => '[shape="box",style="filled",fillcolor="#DDFFDD",width=0.3,height=0.3,fixedsize=true]',
 'UML:Class' => '[shape="record",fillcolor="lightyellow",style="filled"]',
 'UML:Extends' => '[arrowtail="none",arrowhead="onormal"]',
 'UML:Implements' => '[arrowtail="none",arrowhead="onormal",style="dashed"]',
 'UML:Uses' => '[arrowtail="none",arrowhead="vee",style="dashed",label="<<use>>"]',
 #その他色々マクロを定義
}

File.open('c:/progra~1/graphv~1.21/bin/__temp3.dot','w+'){|fd|
	ARGF.each{|e|
		if /digraph/.match(e)
			e.gsub!(/digraph\s+\{/, 'digraph{'+prologue)
		end
		conv.each{|k,v|
			e.gsub!(k,v)
		}
		fd.print NKF.nkf('-Sw', e)
	}
}

これをGVeditのメニューのGraphviz→Preprocessor Settings...に設定すればおk。
ただし、Path: ruby.exeのパス、Command line: 上記スクリプトを起動するバッチファイルとする必要がある。