From: Paul Brannan Date: 2002-02-12T07:28:04+09:00 Subject: choice of HTML templating system I am not a web developer, nor do I pretend to be one. However, recently I have had to develop some simple CGI scripts. It occurred to me, though, that having a CGI script that outputs HTML is probably not a good idea. Php3 and ERuby seem nice, because I can embed code inside HTML, instead of the other way around. But I can go a step further to using templates, which allows me to write HTML that includes references to data, instead of the code to generate that data; this seems to be the most flexible option of the three. Perhaps I just don't know where to look, or how to use the tools that are available to me, but it seems there are so many template systems to choose from, and nobody to tell me which way is right. What do other Ruby developers use when doing web development? Here's a summary of the templating systems I've found so far. RDG and The Ruby Way have been a very valuable source, as has the RAA. Is there anywhere else I should look? CGI (comes with ruby): - Good exception-safety (if I throw an exception, then will be correctly written to the client). - Not quite so good a way of representing the HTML part of what is to be sent to the client. RDoc templates (http://rdoc.sourceforge.net/): - The template system in rdoc is very short (50 lines or so). - Its templating system is part of rdoc, and is not a separate package. There's no guarantee that it will work separately from rdoc in future versions. ruby-tmpl (http://ruby-tmpl.sourceforge.net/): - The author appears to have reasonable knowledge of XML and has a good sense of humor. - I can't figure out how to output complex data structures like Arrays. html-template-tools (http://www.dims.or.jp/~kakeda/ruby/): - Good support for Array and Hash, but new hash-like data structures will be treated as arrays. - Uses sgml-parser for its dirty work. HTML::Template (http://www.0xfa.com/~ikechin/ruby.html): - Very simple. - Has good supports for user-defined data types, but I'm required to iterate over them myself. - Does it's parsing using regular expressions, so it might substitute the wrong thing in the wrong place. IOWA (http://www.beta4.com/iowa/): - My first experience with it was a segfault, and I haven't had time to discover the cause. - Appears to have good separation of code from html, and allows the html to be edited with a wysiwyg editor. eruby (http://www.modruby.net/): - Can I use eruby with fastcgi? Using mod_ruby has a number of security issues. - Seems to have good exception-safety. - Has a tendency to parse incorrectly (it interprets 'puts ""' incorrectly) ERb (http://www2a.biglobe.ne.jp/~seki/ruby/erb.html): - not much English documentation, but looks much like eruby. Ruby Publishing Framework (http://software.terralab.com/framework/): - An almost overwhelmingly large API. - Somewhat lacking in documentation. - XML may be a little heavy for many applications. Paul