2008/11/13


Gist GitHubが提供するコードスニペットサービス(という言い方で良いのかな?)、「Gist」をvimから扱えるvimscript「Gist.vim」を書いた。
内部はcurlコマンドを使っており
  • 一覧
  • 閲覧
  • ポスト
  • プライベートポスト
が出来る様になっています。導入にはcurlコマンドとgitコマンドが必要です(コマンドライン版gistコマンドやrubyは必要ありません)。ただし、グローバル変数に"github_user"と"github_token"さえ設定していればgitコマンドも必要ありません。
使い方は、適当にバッファを開いて :Gist
とすればポストされ、公開URLがコマンドライン上に表示されます。
またビジュアル選択して :'<,'>Gist
で部分的にポストする事も出来ます。なお引数として :Gist -p
もしくは--private
を指定するとprivateモードでポストします。 GistのIDが分かっている場合には :Gist XXXXX
とID指定でgistを開く事も出来ます。
さらに :Gist -la もしくは--listall
で全ユーザの最新gist一覧 :Gist -l mattn もしくは--list mattn
でユーザ指定一覧、といった使い方も出来ます。

現在、github上で開発を進めておりvim.orgでも公開しています。
よかったら使ってみて下さい。

Posted at by




id:tokuhiromが良い物作ってくれたので、それを使ったブログエンジン書いてみた。
MENTA というウェブアプリケーションフレームワークをかいてみた - TokuLog 改めB日記

「CGI 用のウェブアプリケーションフレームワークにはどういうものが最適か」という問いに対する自分なりの解答。

http://d.hatena.ne.jp/tokuhirom/20081111/1226418572

名前は、「MENTOS(メントス)」。
mentos-weblog-engine
実質コードは以下の量くらい。

sub read_entry {
    my $file = shift;
    my $pubdate = strftime("%y-%m-%d %H:%M:%S", localtime((stat $file)[9])),
    my $content = read_file($file);
    $file =~ s!.*?([^/]+)\.txt$!$1!;
    $content =~ /^([^\n]+)\n\n(.*)/ms;
    return {
        id => $file,
        title => $1,
        pubdate => $pubdate,
        description => $2,
    }
}

# あなたのプログラム
sub do_index {
    my $id = param('id') || '';
    my $data_dir = config()->{application}->{data_dir};

    if ($id =~ /^(\d+)$/) {
        render('entry.html', read_entry("${data_dir}/${id}.txt"));
    } else {
        my @entries;
        for my $file (glob("${data_dir}/*.txt")) {
            push @entries, read_entry($file);
        }
        render('entries.html', \@entries);
    }
}

sub do_edit {
    my $id = param('id') || '';
    my $data_dir = config()->{application}->{data_dir};
    my $msg = '';
    my $entry = {};

    if ($ENV{'REQUEST_METHOD'} eq 'POST') {
        $entry->{id} = param('id') || '';
        $entry->{title} = param('title') || '';
        $entry->{description} = param('description') || '';
        $entry->{title} =~ s!\r!!g;
        $entry->{description} =~ s!\r!!g;
        my $password = param('password') || '';
        my $admin_password = config()->{application}->{password};
        if ($entry->{id} =~ /^(\d+)$/ && $password eq $admin_password) {
            $entry->{id} = time unless $entry->{id};
            utf8::decode($entry->{title});
            utf8::decode($entry->{description});
            write_file("${data_dir}/${id}.txt", $entry->{title}."\n\n".$entry->{description});
            redirect(config()->{application}->{blog_url});
            return;
        } else {
            $msg = 'パスワードが違います';
        }
    } else {
        $entry = read_entry("${data_dir}/${id}.txt") if -f "${data_dir}/${id}.txt";
    }

    render('edit.html', $entry, $msg);
}
MENTAを使ってどれだけ小さなコード量でブログエンジンが出来上がるかを試して見たかっただけなので、ブログと言いながらカテゴリやコメント、トラックバック等はありません。一応編集機能は持ち合わせています。
コードはcodereposのこの辺に置いときますので、適当に弄って遊んで下さい。
暇があれば、id:yappoのYacafiや、id:kazuhoのNanoAでも作ってみたいなぁ。
Posted at by



2008/11/10


さらにちょこっと弄ってset-branch/commitが使える様にした。
Ditz の Mercurial プラグイン - ursmの日記

例によって Mercurial のはないみたいだったので、Git のものをちょちょいと手直しして作ってみました。

http://d.hatena.ne.jp/ursm/20080729/1217345141
これまたgit.rbからパクっただけですが... --- mercurial.rb.orig   2008-11-10 12:30:03.015625000 +0900
+++ mercurial.rb    2008-11-10 12:30:04.921875000 +0900
@@ -2,6 +2,7 @@
  
 module Ditz
   class Issue
+    field :hg_branch, :ask => false
     def hg_commits
       return @hg_commits if @hg_commits
       output = `hg log --template '{date|rfc822date}\t{author}\t{node|short}\t{desc|firstline}\n' #{pathname}`
@@ -45,5 +46,51 @@
 EOS
     end
   end
+  class Operator
+    operation :set_branch, "Set the hg feature branch of an issue", :issue, :maybe_string
+    def set_branch project, config, issue, maybe_string
+      puts "Issue #{issue.name} currently " + if issue.hg_branch
+        "assigned to hg branch #{issue.hg_branch.inspect}."
+      else
+        "not assigned to any hg branch."
 end
 
+      branch = maybe_string || ask("Mercurial feature branch name:")
+      return unless branch
+  
+      if branch == issue.hg_branch
+        raise Error, "issue #{issue.name} already assigned to branch #{issue.hg_branch.inspect}"
+      end
+  
+      puts "Assigning to branch #{branch.inspect}."
+      issue.hg_branch = branch
+    end
+  
+    operation :commit, "Runs hg-commit and auto-fills the issue name in the commit message", :issue do
+      opt :all, "commit all changed files", :short => "-a", :default => false
+      opt :verbose, "show diff between HEAD and what would be committed", \
+        :short => "-v", :default => false
+      opt :message, "Use the given <s> as the commit message.", \
+        :short => "-m", :type => :string
+    end
+  
+    def commit project, config, opts, issue
+  
+      args = {
+        :verbose => "--verbose",
+        :all => "--all",
+      }.map { |k, v| opts[k] ? v : "" }.join(" ")
+  
+      comment = "# #{issue.name}: #{issue.title}"
+      tag = "Ditz-issue: #{issue.id}"
+      message = if opts[:message]
+        "#{opts[:message]}\n\n#{tag}"
+      else
+        "#{comment}\n#{tag}"
+      end
+  
+      message = message.gsub("\"", "\\\"")
+      exec "hg commit #{args} --message=\"#{message}\""
+    end
+  end
+end
ちなみにmercurialとditzを使った開発方法はおおよそ以下の様な感じ。
# cd /path/to/my/repos/example
まず初期設定
# ditz init
# echo '- mercurial' >> .ditz-plugins
# cat > .ditz-config
--- !ditz.rubyforge.org,2008-03-06/config
mercurial_commit_url_prefix: .
^D
# ditz reconfigure
issueを追加
# ditz add
Title: 'foo' is not found in README.
Description (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> need to add 'foo'
> .
Is this a (b)ugfix, a (f)eature, or a (t)ask? t
Issue creator (enter for "mattn <mattn.jp@gmail.com>"):
Comments (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> .
Added issue example-1.
You may have to inform your SCM that the following files have been added:
  .ditz/issue-5486bdc5eeb7c4f6c2fc784a4a7c41d949d0791e.yaml

ソースを修正する
# echo 'foo' >> README
# ditz close example-1
Closing issue example-1: 'foo' is not found in README..
Choose a disposition:
  1) fixed
  2) won't fix
  3) reorganized
Disposition (1--3): 1
Comments (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> added 'foo'
> .
Closed issue test2-2 with disposition fixed.
You may have to inform your SCM that the following files have been modified:
  .ditz/issue-5486bdc5eeb7c4f6c2fc784a4a7c41d949d0791e.yaml

コミットする
# ditz commit
summary付でコミットされている
# hg log
changeset:   6:720dc3bf4ef9
tag:         tip
user:        mattn <mattn.jp@gmail.com>
date:        Mon Nov 10 12:43:21 2008 +0900
summary:     # example-1: 'foo' is not found in README.
ditzの場合は、.ditzフォルダや.ditz-configもリポジトリに格納するのが通常の使い方みたいですね。

ところでditzってバッチっぽく動く様になればいろんなツールが出始めると思うのに勿体無い気がするなぁ。
Posted at by