[#35592] String#center — Take_tk <ggb03124@...>

 仕様拡張のお願い。と言うほどのものでもないですが・・

33 messages 2002/07/20
[#35593] Re: String#center — Kazuhiro NISHIYAMA <zn@...> 2002/07/20

西山和広です。

[#35596] Re: String#center — Take_tk <ggb03124@...> 2002/07/20

たけ(tk)です。

[#35597] Re: String#center — Kazuhiro NISHIYAMA <zn@...> 2002/07/20

西山和広です。

[#35599] Rational#to_int ← String#center — Take_tk <ggb03124@...> 2002/07/21

たけ(tk)です。

[#35601] Re: Rational#to_int ← String#center — matz@... (Yukihiro Matsumoto) 2002/07/21

まつもと ゆきひろです

[#35618] new mathn [Re: Rational#to_int ← String#center] — keiju@... (石塚圭樹) 2002/07/23

けいじゅ@日本ラショナルソフトウェアです.

[#35624] Re: new mathn [Re: Rational#to_int ← String#center] — matz@... (Yukihiro Matsumoto) 2002/07/24

まつもと ゆきひろです

[#35628] Re: new mathn [Re: Rational#to_int ← String#center] — keiju@... (石塚圭樹) 2002/07/24

けいじゅ@日本ラショナルソフトウェアです.

[#35630] Re: new mathn [Re: Rational#to_int ← String#center] — matz@... (Yukihiro Matsumoto) 2002/07/24

まつもと ゆきひろです

[ruby-list:35602] [ANN] tmplc-0.1.0 released

From: MoonWolf <moonwolf@...>
Date: 2002-07-21 14:18:08 UTC
List: ruby-list #35602
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
  <html>
  <head><title><%=title%></title></head>
  <body>
  <h1><%=title%></h1>
  <%=footer%>
  </body>
  </html>
-------------------------------------------------
template/footer.html
  <hr>
  MoonWolf <moonwolf@moonwolf.com>
-------------------------------------------------

コンパイルする。

  $ tmplc.rb template lib

以下のファイルが出力される。
ディレクトリがモジュール、ファイルがメソッドに対応しています。

-------------------------------------------------
lib/template.rb
  module Template
  def sample(arg=nil,io='')
    io << "<html>\n<head><title>"
    io << (title).to_s
    io << "</title></head>\n<body>\n<h1>"
    io << (title).to_s
    io << "</h1>\n"
    io << (footer).to_s
    io << "\n</body>\n</html>\n"
    io
  end
  def footer(arg=nil,io='')
    io << "<hr>\nMoonWolf <moonwolf@moonwolf.com>\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 <moonwolf@moonwolf.com>


In This Thread

Prev Next