Fork me on GitHub

2008/11/13

はてな
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 19:11 in ソフトウェア::lang::perl | WriteBacks (2)
Tagged as: blog, menta, perl
Bookmarks: このエントリーのtweets add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip | add to buzzurl add to buzzurl | add to fc2bookmark add to fc2bookmark | add to Yahoo Bookmark add to Yahoo Bookmark | add to Pookmark add to Pookmark

2008/04/15

はてな
出来た。とりあえずの機能としては
  • デザインテンプレート
  • プラグイン機能
  • 検索(プラグイン実装)
  • ページング(プラグイン実装)
  • 編集(プラグイン実装)
  • コメント/トラックバック(プラグイン実装)
まで出来た。なるべくblosxomぽくなるように作ったつもり。動いてる物は
Weblog
にあります。適当にmicroformatに対応してあります。
google-app-engine-blog
この後codereposに上げる予定です。
でもどのディレクトリに上げていいか分かりません><

追記
http://coderepos.org/share/browser/websites/appspot.com/blog/trunk
にアップした。

2007/11/04

はてな
私が購読しているブログのタイトルの中に、コンピュータ用語やネットワーク用語、プログラミング用語が含まれている物がある。
今日はそのブログタイトルを勝手に妄想してしまう。
まずは...

kuさんの「ZeroMemory」
http://ido.nu/kuma/

ZeroMemory Windowsでのプログラミング経験がある方ならば、おそらく一回は使った事があるであろうWin32 API。メモリの先頭アドレス、サイズを貰いメモリをゼロクリアするAPIです。
一般的にはmemset(3)が使われますが、ZeroMemoryにはセキュリティパスを回避するロジックが入っているとかいないとか...
ブログタイトルとしてZeroMemoryという言葉を使われたあたりセンスが良い。例えば「CoInitialize」とか、「WSAStartup」とかだったら少し濃すぎるし、「curl_init」や「gtk_init」であっても少しギークすぎる。

次はご存じ...

dankogaiさんの「404 Blog Not Found」
http://blog.livedoor.jp/dankogai/

404 Blog Not Found HTTPプロトコルで、文書ファイルが見付からなかった場合にサーバから返されるステータスコード「404 Not Found」に因んで付けられた物だと思う。
こちらも「200 Blog OK」は詰まらなすぎるし、「500 Internal Blog Error」も悲しすぎる。
そして...

otsuneさんの「void GraphicWizardsLair( void ); //」
http://www.otsune.com/diary/

void GraphicWizardsLair( void ); // うーん...
分かりません。まずC言語なのかJavaなのか...。public/private等が付いていない事から推測して恐らくC言語。しかもプロトタイプ宣言。そしてコメントが「//」だけ...。意味深すぎる。
関数名は「GraphicWizardsLair」と「アートな魔法使いの隠れ家?」といった所なのだろうか...
もしくはどこかのゲームか何かのソースの一部だろうか...謎は深まる。誰か知りませんか?

人のブログタイトルって、意外と気になりますよね...
Posted at 16:00 in その他 | WriteBacks (1)
Tagged as: blog
Bookmarks: このエントリーのtweets add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip | add to buzzurl add to buzzurl | add to fc2bookmark add to fc2bookmark | add to Yahoo Bookmark add to Yahoo Bookmark | add to Pookmark add to Pookmark