From: Makoto Kuwata Date: 2004-03-20T06:30:46+09:00 Subject: Re: [ANN] Kwartz (2004-03-19) released Andreas, Thanks for your suggestions. Andreas wrote: > >1) > >#{username}# > > >results in > >if logged_in then > print username, "\n" >end > >But according to >http://www.kuwata-lab.com/webtech/kwartz/users-guide.en.03.html#directive-if >the result should look like this: > >if logged_in then > print "\n" > print username, "\n" > print "\n" >end Tag or
are deleted if they have only directives. If you don't want to delete them, use or
, or add other attributes like . See http://www.kuwata-lab.com/webtech/kwartz/users-guide.en.03.html#directive-notes > >2) >IMO something like this would be much cleaner than eval()'ing the code >generated by kwarts, because the ruby file has to be parsed only once, >and it isn't always wanted to send the output to STDOUT. > >template = Kwartz.new(File.read('template.html')) >string = template.expand(data) You should use ERB if you want to get result as string. ------------------ s = File.open('file.eruby') { |f| f.read() } require 'erb' erb = ERB.new(s) # or ERB.new(s, $SAFE, '%') str = erb.result(binding()) ------------------ And executing the output script is enough fast. See http://www.io.com/~egabriel/bench/results.html The benchmark shows that eruby (= ERuby::import()) is faster than any other template system in Ruby. (ERB works almost as fast as eruby.) It is one of the reasons why I adopted the current way in Kwartz. If you want to get more speed, try erbscan. http://raa.ruby-lang.org/list.rhtml?name=erbscan I have not tried it yet, but I heared that erbscan makes ERB very very fast. > >3) >ruby output could also support sanitizing (CGI::escapeHTML). > Yes, you are right. I do that in the future release. -- regards, kwa