[#407] New feature for Ruby? — Clemens.Hintze@...

Hi all,

27 messages 1999/07/01
[#413] Re: New feature for Ruby? — matz@... (Yukihiro Matsumoto) 1999/07/01

Hi Clemens,

[#416] Re: New feature for Ruby? — Clemens Hintze <c.hintze@...> 1999/07/01

On Thu, 01 Jul 1999, Yukihiro Matsumoto wrote:

[#418] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/01

Hi

[#426] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/02

Hi,

[#440] Now another totally different ;-) — Clemens Hintze <c.hintze@...>

Hi,

21 messages 1999/07/09
[#441] Re: Now another totally different ;-) — matz@... (Yukihiro Matsumoto) 1999/07/09

Hi,

[#442] Re: Now another totally different ;-) — Clemens Hintze <c.hintze@...> 1999/07/09

On Fri, 09 Jul 1999, you wrote:

[#443] — Michael Hohn <hohn@...>

Hello,

26 messages 1999/07/09
[#444] interactive ruby, debugger — gotoken@... (GOTO Kentaro) 1999/07/09

Hi Michael,

[ruby-talk:00520] Re: CGI.rb

From: OZAWA Sakuro <crouton@...>
Date: 1999-07-24 19:59:12 UTC
List: ruby-talk #520
> I am using CGI.rb. It's very nice.
> But, is it possible to create tables with it?

Assuming you mention 'cgi-lib.rb', its CGI class defines no method for
table generation.

For some very simple cases, following code might help.
It asumes no spanning(holds two or more) columns/rows, and handles
little cosmetics.

It would be nice to have servlet classes for ruby...:-)

-- 
OZAWA Sakuro
<mailto:crouton@duelists.org>
<http://www.duelists.org/~crouton/>

------------------------( C U T   H E R E )---------------------------
# require 'cgi-lib.rb'
class CGI
  def table(headings, rows, border=nil)
    if border
      if border.kind_of?(String) and /^\d+[a-zA-Z]*/ =~ border
        result = "<table border=\"#{border}\">\n"
      else
	result = "<table border>\n"
      end	 
    else
      result = "<table>\n"
    end
    result << "<tr>"
    headings.each do |item|
      result << "<th>#{item}</th>"
    end
    result << "</tr>\n"
    rows.each do |row|
      result << "<tr>"
      row.each do |item|
        result << "<td>#{item}</td>"
      end
      result << "</tr>\n"
    end
    result << "</table>\n"
  end
end

# sample
headings = [ "Name",  "Age" , "Sex" ]
rows = [
         [ "Jack", "30", "M" ],
         [ "Betty", "29", "F" ]
       ] 

# x = CGI.new
print x.table(headings, rows)
print x.table(headings, rows, true)
print x.table(headings, rows, "5px")

In This Thread