Wiki External Filter Plugin の導入と blockdiag への対応

redmineのwikiで図が書けるよう、wikiのプラグインを追加した。

Wiki External Filter Plugin Install

# gem install --remote --include-dependencies POpen4
# cd /var/lib/redmine/
# cd vendor/plugins/
# ls
acts_as_activity_provider  acts_as_tree        gravatar
acts_as_attachable         acts_as_versioned   open_id_authentication
acts_as_customizable       acts_as_watchable   prepend_engine_views
acts_as_event              awesome_nested_set  rfpdf
acts_as_list               classic_pagination  ruby-net-ldap-0.0.4
acts_as_searchable         engines
# git clone https://github.com/ndl/wiki_external_filter.git
# ls
acts_as_activity_provider  acts_as_tree        gravatar
acts_as_attachable         acts_as_versioned   open_id_authentication
acts_as_customizable       acts_as_watchable   prepend_engine_views
acts_as_event              awesome_nested_set  rfpdf
acts_as_list               classic_pagination  ruby-net-ldap-0.0.4
acts_as_searchable         engines             wiki_external_filter
# chown -R apache:apache wiki_external_filter/
# cd /var/lib/redmine/
# cp vendor/plugins/wiki_external_filter/config/wiki_external_filter.yml config/
# chown apache:apache config/wiki_external_filter.yml
  • redmineに管理者権限でログインし、「管理」→「プラグイン」に「Wiki External Filter Plugin」が追加されていることを確認する。
# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
  • 「Wiki External Filter Plugin」の「設定」をクリックし、「Cache expiration time」に適宜秒数を設定する。(とりあえず 600 seconds で設定した)

Redmine にパッチを適用

# cd /var/lib/redmine
# ls
README.rdoc  app     db   extra  lib  public  test  vendor
Rakefile     config  doc  files  log  script  tmp
# wget http://www.ndl.kiev.ua/downloads/redmine-1.0.2-macros-escaping.patch
# ls
README.rdoc  config  extra  log                                  script  vendor
Rakefile     db      files  public                               test
app          doc     lib    redmine-1.0.2-macros-escaping.patch  tmp
# patch -p1 -i redmine-1.0.2-macros-escaping.patch
patching file lib/redmine/wiki_formatting.rb

Graphviz のインストール

# wget -O /etc/yum.repos.d/graphviz-rhel.repo http://www.graphviz.org/graphviz-rhel.repo
# yum install graphviz

Transaction Check Error:
  file /usr/bin/gxl2dot conflicts between attempted installs of graphviz-2.12-8.el5.i386 and graphviz-2.26.3-1.el5.x86_64

# yum install graphviz.x86_64
# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

使い方

サンプルのとおりですが、Wiki で

{{graphviz(
digraph G {
    node1 -> node2[label="矢印"]
}
)}}

のように書くと、そこに図が埋め込まれるはずです。(日本語も OK です)Firefox や Chrome だと SVG で表示して、IE だと PNG で表示する形みたいですね。

blockdiag の Install

# yum install python-setuptools python-imaging fonts-japanese

# yum install python-devel

# touch /usr/lib/python2.4/site-packages/PIL-1.1.7-py2.4-linux-x86_64.egg-info

# easy_install blockdiag

# vi /usr/lib/python2.4/site-packages/sitecustomize.py
import sys
sys.setdefaultencoding('utf-8')

# vi /var/lib/redmine/config/wiki_external_filter.yml

# diff -U5 wiki_external_filter.yml.org wiki_external_filter.yml
 --- wiki_external_filter.yml.org        2011-04-21 22:33:22.000000000 +0900
 +++ wiki_external_filter.yml    2011-04-21 23:06:41.000000000 +0900
 @@ -48,10 +48,21 @@
      cache_seconds: 0
      outputs:
        - command: "/usr/bin/fortune"
          content_type: "text/plain"

 +  blockdiag:
 +    description: "Constructs block-diagram image from its textual description in blockdiag language, see http://tk0miya.bitbucket.org/blockdiag/build/html/index.html"
 +    template: svg
 +    outputs:
 +      - command: "/usr/bin/blockdiag -Tsvg -o/dev/stdout /dev/stdin"
 +        content_type: "image/svg+xml"
 +      - command: "/usr/bin/blockdiag -Tpng -o/dev/stdout /dev/stdin"
 +        content_type: "image/png"
 +      #- command: "/usr/bin/blockdiag -Tpng -f /usr/share/fonts/japanese/TrueType/sazanami-gothic.ttf -a -o/dev/stdout /dev/stdin"
 +      #  content_type: "image/png"
 +
  test:
    type: mock

  production:
    <<: *development

netdiag の install

# easy_install netdiag
# vi /var/lib/redmine/config/wiki_external_filter.yml
# diff -U5 wiki_external_filter.yml.old wiki_external_filter.yml
--- wiki_external_filter.yml.old        2011-04-22 12:30:43.000000000 +0900
+++ wiki_external_filter.yml    2011-04-22 12:31:47.000000000 +0900
@@ -60,10 +60,19 @@
       - command: "/usr/bin/blockdiag -Tpng -o/dev/stdout /dev/stdin"
         content_type: "image/png"
       #- command: "/usr/bin/blockdiag -Tpng -f /usr/share/fonts/japanese/TrueType/sazanami-gothic.ttf -a -o/dev/stdout /dev/stdin"
       #  content_type: "image/png"

+  netdiag:
+    description: "Constructs block-diagram image from its textual description in blockdiag language, see http://tk0miya.bitbucket.org/netdiag/build/html/index.html"
+    template: svg
+    outputs:
+      - command: "/usr/bin/netdiag -Tsvg -o/dev/stdout /dev/stdin"
+        content_type: "image/svg+xml"
+      - command: "/usr/bin/netdiag -Tpng -o/dev/stdout /dev/stdin"
+        content_type: "image/png"
+

 test:
   type: mock

 production:
2011/05/02 追記:
その後netdiagの作者 @tk0miya さんがパッケージ名を netdiag から nwdiag に変更したので、本手順については後日訂正予定です。 ひとまず、新規にインストールする方は netdiag を nwdiag に読み替えて頂きたい。

actdiag の install

なぜか Download error: (110, ‘Connection timed out’) となるので、実施していない .. code-block:: bash

# easy_install actdiag