From: MoonWolf Date: 2002-07-15T23:59:59+09:00 Subject: [ruby-list:35566] [ANN] tmplc-0.0.1 released MoonWolfです。 テンプレートコンパイラ tmplc-0.0.1 をリリースしました。 http://www.ruby-lang.org/en/raa-list.rhtml?name=tmplc テキストファイルやHTMLなどのファイルに :::〜:::でRubyのスクリプトを 埋め込むことが出来ます。 使い方 以下の2ファイル(sample.html,footer.html)を用意する。 ------------------------------------------------- template/sample.html :::title:::

:::title:::

:::footer::: ------------------------------------------------- template/footer.html
MoonWolf ------------------------------------------------- コンパイルする。 $ tmplc.rb template lib 以下のファイルが出力される。 ディレクトリがモジュール、ファイルがメソッドに対応しています。 ------------------------------------------------- lib/template.rb module Template def sample(arg=nil,io='') io << "\n" io << (title) io << "\n\n

" io << (title) io << "

\n" io << (footer) io << "\n\n\n" io end def footer(arg=nil,io='') io << "
\nMoonWolf \n" io end end # Template ------------------------------------------------- クラスにincludeして使います。 ------------------------------------------------- sample.cgi #!/usr/bin/ruby require "cgi" require "lib/template" class Page include Template def initialize(title) @title = title end def main cgi = CGI.new cgi.out { sample } end # Template#sampleから呼び出される def title CGI.escapeHTML(@title) end end ------------------------------------------------- ruby-win32の過去ログアーカイブはtmplcで作成されています。 http://www.moonwolf.com/~arcml/cgi-bin/arcml/ -- MoonWolf