K
Karsten Meier
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:
# <OL><LI>red</LI> <LI>blue</LI> <LI>green</LI></OL>
in perl you can write:
use CGI qwstandard :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 "<LI>redbluegreen</LI>" instead of
"<LI>red</LI> <LI>blue</LI> <LI>green</LI>"
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
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:
# <OL><LI>red</LI> <LI>blue</LI> <LI>green</LI></OL>
in perl you can write:
use CGI qwstandard :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 "<LI>redbluegreen</LI>" instead of
"<LI>red</LI> <LI>blue</LI> <LI>green</LI>"
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