pragger設定ファイルをCGI化

最近praggerを使い始めて、ちょっと思いついたことがあったのでパッチを提案してみる。

まずは以下のようなパッチをあてる。
修正内容は、

  • 「実行中プラグイン」表示を抑制するquietオプション追加
  • RSS::saveでファイル名無指定の場合に出力先を標準出力へ
Index: pragger.rb
===================================================================
--- pragger.rb  (リビジョン 82)
+++ pragger.rb  (作業コピー)
@@ -23,7 +23,7 @@
 
 def eval_pragger(command_array,data)
   command_array.inject(data) do |data, command|
-    puts "exec plugin #{command["module"]}"
+    puts "exec plugin #{command["module"]}" unless $quiet
     $plugins[command["module"]].send(command["module"].sub(/.*::/,""), command["config"] || {}, data.dup)
   end
 end
@@ -36,6 +36,7 @@
 opt.on("-u", "--pluginusage PLUGINNAME") {|v| $plugins[v].source.gsub(/^## ?(.*)/){ puts $1 }; exit }
 opt.on("-l", "--listplugin") { $plugins.keys.sort.each{|k| puts k }; exit }
 opt.on("-w", "--where") { puts(Pathname.new(__FILE__).parent + "plugin"); exit }
+opt.on("-q", "--quiet") { $quiet = true }
 opt.parse!
 
 eval_pragger(YAML.load(File.read(configFile).toutf8),[])
Index: plugin/RSS/save.rb
===================================================================
--- plugin/RSS/save.rb  (リビジョン 82)
+++ plugin/RSS/save.rb  (作業コピー)
@@ -34,7 +34,11 @@
       end
     end
   end
-  open(config["filename"],"w"){|w| w.puts rss }
+  if config["filename"]
+    open(config["filename"],"w"){|w| w.puts rss }
+  else
+    puts rss
+  end
   return data
 end

設定ファイルとして以下のようなファイルを作成して保存。この設定ファイルに実行権限を与える。(shebang行の最後に-cを書くのがポイント)

#!/usr/bin/env ruby /path/to/pragger/pragger.rb -q -c

- module: const_list
  config:
    - "Content-type: text/xml"
    - ""
- module: stdout
  config:
- module: RSS::load
  config:
    url: http://dailynews.yahoo.co.jp/fc/rss.xml
- module: RSS::save
  config:

この設定ファイルはshebangがあるので普通にシェルから実行可能なスクリプトとして扱える。

で、上記スクリプトの出力はそのままHTTPレスポンスになってるので、ローカルでWebサーバーを立ち上げてるならcgi-binディレクトリにつっこんで、そのままブラウザやRSSリーダーから呼び出すことが出来るようになって便利かなと。

いかがでしょうか?