From: m_seki@... Date: 2002-03-20T11:53:29+09:00 Subject: Re: web templating for static sites? Hello. > But where is ERuby::Compiler defined? I see the Debian package only > installed /usr/bin/eruby and no lib file at all. Is it a 1.7 thing? > > > If you do this within a page object: > > > > class Page > > @template = "path/to/template" > > def to_html > > eval( compile_eruby(@template) ) > > end > > end > > > > Then the code in the template gets eval'd in the scope of the page, > > Do you mean that if the Page class has a ``foo'' attribute, <% =foo %> > will be translated into that? Do you know erb? You can change an eRuby script into a method by erb. I'm writing erb tutorial (in Japanese). # It'l be translated in the near future. The following samples are in the tutorial. -> http://www.jin.gr.jp/~nahi/RWiki/index.cgi?cmd=view;name=ERbMemo FYI: There is web application called Div using this. (machine translated) -> http://www.jin.gr.jp/~nahi/RWiki/index.cgi?cmd=view;name=Div -> http://www.jin.gr.jp/~nahi/RWiki/index.cgi?cmd=view;name=YourFirstDiv --batch.rb-- require 'erb/erbl' require 'erb/erbu' require 'forwardable' class Writer extend Forwardable extend ERbMethod include ERbUtil def initialize(page) @page = page end def_delegators(:@page, :title, :abstract, :content, :modified) def_delegators(:@page, :hier) def_erb_method('body', 'body.erb') def_erb_method('footer', 'footer.erb') def_erb_method('navi', 'navi.erb') def write_to_file fname = File.basename(@page.url) File.open(fname, 'w') do |fp| fp.puts(body) end end end Article = Struct.new(:url, :title, :abstract, :content, :modified, :hier) class Book extend ERbMethod include ERbUtil def initialize @url = 'index.html' @title = 'index' @index = [] end attr_accessor :url, :title attr_reader :index def add(article) @index.push(article) article.hier = [self] end def abstract; nil; end def_erb_method('content', 'index.erb') def modified; nil end def hier; nil; end end def main book = Book.new it = Article.new('hello.html', 'Hello', '
Hello, World.
', 'Test Artcile 1.
', Time.now-24*60*60, nil) book.add(it) it = Article.new('hello2.html', 'Hello2', 'Hello, World, too.
', 'Test Artcile 2.
', Time.now, nil) book.add(it) Writer.new(book).write_to_file book.index.each do |pg| Writer.new(pg).write_to_file end end main -- body.erb --