SVN::TracWiki #1

Posted by Gosuke Miyashita Sun, 22 Apr 2007 06:07:01 GMT

SVN::TracWiki (svn repos) について、ブクマコメントで miyagawa さんから「File::Extract?」というアドバイス?を頂きましたので、テキスト抽出部分を File::Extract ベースに書き換えてみました。

おかげでプラグインまわりの処理が少しすっきりした上に、File::Extract で対応しているファイルフォーマットであれば、SVN::TracWiki 用のプラグインを書かなくてもテキスト抽出ができるようになりました。(Excel で試しましたが、ばっちり動作しました。)

SVN::TracWiki #0

Posted by Gosuke Miyashita Sat, 21 Apr 2007 19:55:57 GMT

SVN::TracWiki というツールをつくってみました。svn repos はこちら

何をするものかというと、Subversion の post-commit スクリプトとして動作して、コミットされたファイルからテキストを抽出、そのファイルの実体へのリンクを付加して、Trac の Wiki へ自動ポストするというもの。

具体的な例としては、PowerPoint ファイルをコミットしたら、そのファイルからテキストのみを抽出して Wiki へ自動ポスト。こんな感じで

これで何がうれしいかというと、Subversion で管理している PowerPoint ファイルを、Trac 上で検索ができるようになります。こんな感じですね。元ファイルへのリンクもあるので、検索して元ファイルを開いて読む、ってことが簡単にできます。

例によって YAMLで設定 and プラガブル。ファイルからテキストを抽出する部分がプラグインになっていて、簡単に拡張できるようにしています。

現在は PowerPoint 用フィルタプラグインしかないのですが、以下の様なコードになっていて、フィルタ対象ファイルの MIME タイプを register() で指定、テキスト抽出ルーチンを filter() に記述、という感じで書きます。

package SVN::TracWiki::Plugin::Filter::PowerPoint;

use strict;
use warnings;
use base qw( SVN::TracWiki::Plugin::Filter );
use Encode;

sub register {
    my $self = shift;
    $self->register_mime_types( qw! application/vnd.ms-powerpoint !);
}

sub filter {
    my ( $self, $file ) = @_;
    my $html = `/usr/local/bin/ppthtml $file`;
    my $text = $self->strip_html($html);

    $text = Encode::decode('utf8', $text);
    $text = Encode::encode('utf8', $text);

    return $text;
}

1;

とりあえず動くようになっただけで、いけてない部分盛りだくさんですが、こんなのつくってみました、ってことで。

html-tt-mode を sgml-mode のマイナーモードで動くようにしてみた

Posted by Gosuke Miyashita Mon, 09 Apr 2007 08:36:45 GMT

Clouder::Blogger: html-tt - emacsのTemplate Toolkit用のmode を html-helper-mode ではなく、sgml-mode のマイナーモードで動くようにしたパッチ。(置換しただけ。)

別に sgml-mode に思い入れはなく、Meadow でデフォルトで動いてるからそのまま使ってるだけなので、html-helper-mode にしてもいいんだけど、どうも Meadow でうまく色づけされないので、その原因追求するよりも、sgml-mode で動くようにした方がはやかったので。

本当はどっちでも動くようにするのがいいんだろうけど、それはまた今度。

=== html-tt.el
==================================================================
--- html-tt.el	(revision 193)
+++ html-tt.el	(local)
@@ -66,7 +66,7 @@
 ;; Code:
 
 (provide 'html-tt)
-(require 'html-helper-mode)
+(require 'sgml-mode)
 (require 'tempo)
 (require 'font-lock)
 
@@ -217,38 +217,38 @@
 (defun html-tt-load-hook ()
   (interactive)
   ;; define key bind
-  ;(define-key html-helper-mode-map "\C-cs"
+  ;(define-key sgml-mode-map "\C-cs"
   ;  'html-tt-insert-sequence)
-  (define-key html-helper-mode-map "\C-cs"
+  (define-key sgml-mode-map "\C-cs"
     'tempo-template-html-tt-insert-sequence)
-  (define-key html-helper-mode-map "\C-cd"
+  (define-key sgml-mode-map "\C-cd"
     'html-tt-insert-directive)
-  (define-key html-helper-mode-map "\C-cn"
+  (define-key sgml-mode-map "\C-cn"
     'tempo-template-html-tt-insert-directive)
-  (define-key html-helper-mode-map "\C-ci"
+  (define-key sgml-mode-map "\C-ci"
     'tempo-template-html-tt-insert-if)
-  (define-key html-helper-mode-map "\C-cl"
+  (define-key sgml-mode-map "\C-cl"
     'tempo-template-html-tt-insert-elsif)
-  (define-key html-helper-mode-map "\C-ce"
+  (define-key sgml-mode-map "\C-ce"
     'tempo-template-html-tt-insert-else)
-  (define-key html-helper-mode-map "\C-cf"
+  (define-key sgml-mode-map "\C-cf"
     'tempo-template-html-tt-insert-foreach)
-  (define-key html-helper-mode-map "\C-cw"
+  (define-key sgml-mode-map "\C-cw"
     'tempo-template-html-tt-insert-while)
-  (define-key html-helper-mode-map "\C-cm"
+  (define-key sgml-mode-map "\C-cm"
     'tempo-template-html-tt-insert-switch)
-  (define-key html-helper-mode-map "\C-cn"
+  (define-key sgml-mode-map "\C-cn"
     'tempo-template-html-tt-insert-include)

   ;; add hilit-set-mode-pattern, if use hilit19.
   (if (featurep 'hilit19)
-      (hilit-add-pattern "\\[%" "%\\]" 'midnightblue 'html-helper-mode)
+      (hilit-add-pattern "\\[%" "%\\]" 'midnightblue 'sgml-mode)
     )
 
   ;; set font-lock
   (make-local-variable 'font-lock-defaults)
   (setq html-tt-font-lock-keywords
-	(append html-helper-font-lock-keywords html-tt-font-lock-keywords))
+	(append sgml-font-lock-keywords html-tt-font-lock-keywords))
   (setq font-lock-defaults '(html-tt-font-lock-keywords t t))
   ) 

.emacs での設定はこんな感じで。

(require 'html-tt)
(add-hook 'sgml-mode-hook 'html-tt-load-hook)