From: Karsten Meier Date: 2005-04-17T23:04:34+09:00 Subject: Html Tag Generation Hello Ruby People I'm working on a project which translates programming examples from the perl cookbook to several other languages (http://pleac.sourceforge.net/) There is a problem for which I currently have only a ugly solution: (Section "19.8 Formatting Lists and Tables with HTML Shortcuts") To create the following html: #
  1. red
  2. blue
  3. green
in perl you can write: use CGI qw(:standard :html3) print ol( li([ qw(red blue green)]) ); With the ruby cgi module, I need to write: require 'cgi' cgi = CGI.new('html4') print cgi.ol{ %w(red blue green).collect{|color| cgi.li{color}} } There ruby solution has two problems: 1) because the methods like CGI::li() take a block as parameter, we can not use a list as content parameter: cgi.li{%w(red blue green)} returns "
  • redbluegreen
  • " instead of "
  • red
  • blue
  • green
  • " 2) we need to write cgi.li{..} instead of just li(..) The result is that the scripts looks more confusing than the solution with perls cgi module. (In most other cases the ruby solutions looks better) So my questions are: Are there better ways to use the cgi module which I'm not aware of? Or is there a better module to use for html generation, preferable in the standard lib? Regards Karsten Meier