以前に xfy のマニュアル目次を freemind にしてみたことがある。
- http://youichi-kato.cocolog-nifty.com/blog/2006/08/xfy_freemind__efe9.html
> > katoy: cocolog: xfy のオンラインマニュアルの 目次を freemind で作ってみた
- http://youichi-kato.cocolog-nifty.com/blog/2007/08/xfy15_8c56.html
> > katoy: cocolog: xfy1.5 マニュアルのマインドマップ (デスティネーション)
- http://youichi-kato.cocolog-nifty.com/blog/2007/08/xfy15_d9cd.html
> > katoy: cocolog: xfy1.5 マニュアルのマインドマップ (チュートリアル)
そのときは、すべて手動で作業した。
マニュアル更新毎に 手動での作業するのは大変なので プログラムで生成できないかと思案中。
手始めに、grpahviz に食わせる dot 形式ファイルをつくるプログラムを作成してみた。
(項目一覧とその親子関係の取得ができるようになったら、次は これを freemidn 形式出力すればよいはず)
以下に
- graphviz で png 画像に変換した例
- dot ファイル生成プログラム (ruby で作成)
を示す。



画像データサイズが 14M と大きくなり過ぎ。また 文字も重なってしまっている。
$ cat link2.rb
# xfy マニュアルの項目関連の dot ファイルを生成する
# utf8
# 2008-01-04 katpy 試作
#
# dot ファイルの生成:
# $ ruby link2.rb > 1.dot
#
# dot ファイルから png を生成する方法:
# $ dot -KENG -Tpng 1.dot -o 1.png
# (ENGは次の中から: circo dot fdp neato nop nop1 nop2 twopi)
# $ twopi -Tpng 1.dot -o 1.png
#-------------------------------------------------
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'cgi'
require 'set'
require 'pathname'
require 'pp'
$KCODE="utf8"
class GenDot
def initialize
# 処理した URLをコレクションして、同じ node を複数 生成しないようにする
@visitedURL = Set.new;
@dquot ='"' # node 名の囲み文字
end
def start
puts 'digraph "g" {'
puts ' ranksep=6;' # 要 調整
# puts ' ratio=auto;'
end
def end
puts '}'
end
def visit(fileName, rootNode="")
doc = Hpricot(File.read(fileName))
docTitle = (doc/'title').inner_text
@visitedURL.add(fileName)
puts "#{@dquot}#{rootNode}#{@dquot} ->#{@dquot}#{docTitle}#{@dquot}" if !(rootNode== "")
# <a href ...> を処理する
(doc/'a[@href]').each { |a|
href = a.attributes['href'].strip
toText = CGI.unescapeHTML(a.inner_text).strip
begin
# file自身中への リンク
if (href.index("#") == 0)
toLinkFile = fileName
toURL = fileName + href
# xfy マニュアル中のナビゲートリンクは無視する
if !(toText=="目次へ") && !(toText =="このページの先頭へ")
if !@visitedURL.include?(toURL)
puts " #{@dquot}#{docTitle}#{@dquot} ->#{@dquot}#{toText}#{@dquot}"
@visitedURL.add(toURL)
end
end
elsif (href.index("http") == 0)
# ネット上へのリンク (http:, https)
puts " #{@dquot}#{docTitle}#{@dquot} ->#{@dquot}#{toText}#{@dquot}"
@visitedURL.add(href)
else
# 相対指定のリンクなら、再帰処理する (# 指定は無視
# 相対パスを絶対パスに変換して @visitedURL への登録内容を正規化する
toLinkFile = File.dirname(fileName) + "/" + URI.split(href)[5]
p = Pathname(toLinkFile)
toURL = p.realpath.to_s
if !@visitedURL.include?(toURL)
toTitle = visit(toURL)
puts " #{@dquot}#{docTitle}#{@dquot} ->#{@dquot}#{toTitle}#{@dquot}"
end
end
rescue => exception
$stderr.puts exception
end
}
docTitle # このファイルの title を返す
end
end
# 処理するファイルを列挙する
files = [
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/app/client/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/app/debugger/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/app/sdesigner/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/app/vdesigner/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/app/xvcd2jar/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/avcchart/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/avcdatagrid/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/avcxychart/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/calclet/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/cml/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/manifest/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/mathml/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/resource/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/svg/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/ui/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/wsr/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/xfr/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/xfyblogeditor/index.html",
"/Users/kato/Desktop/xfy-be1_5-070322 Folder/doc/jp/manual/compo/xhtml/index.html",
]
# ---- Main -----
gendot = GenDot.new
gendot.start
files.each {|f| gendot.visit(f, "root") }
gendot.end
#--- End of File ---
最近のコメント