From: MoonWolf Date: 2002-07-21T23:18:08+09:00 Subject: [ruby-list:35602] [ANN] tmplc-0.1.0 released MoonWolfです。 テンプレートコンパイラ tmplc-0.1.0 をリリースしました。 http://www.ruby-lang.org/en/raa-list.rhtml?name=tmplc :::〜:::形式のタグは使いにくいので、eRuby風の<%〜%>,<%=〜%>に変更しました。 使い方 以下の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).to_s io << "\n\n

" io << (title).to_s io << "

\n" io << (footer).to_s 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 ------------------------------------------------- -- MoonWolf