From: Daniel Berger Date: 2003-06-12T04:08:28+09:00 Subject: Re: HTML-table Austin Ziegler wrote: > > Daniel, > > Can I suggest some changes to what you've got? I am in part > suggesting these because I have to create a Table class for my PDF > generator as well, and I think it would be good *as much as is > possible* to make them similar. What I am thinking is an overarching > Table class that implements the base functions and then an > HTML::Table that inherits from it; similarly, a PDF::Table would > inherit from it as well. Sounds interesting. I guess I would need to know more about PDF::Table. What distinguishes what you need from a regular HTML Table? > > I'm thinking: > require 'html/table' > # Create a table > table = HTML::Table.new { ... } > # Create a table row > row0 = HTML::Table::Row.new { ... } > table.add_row(row0) # or table << row0 > # or table[0] = row0 I originally was going to make Row a subclass of Table (and Data a sublcass of Row, etc), but I didn't because they don't really qualify as subclasses IMHO. It was causing to many design problems, with subclasses having access to variables/data they really shouldn't have access to. Maybe if I were a better OO programmer... However, I like the '<<' and 'table[0]' syntax. That's easy enough to add, I think. > table[1][1].configure { ... } Yep, like that idea, too. > > # Finally, print the table > puts table.to_html > > Many of the output options that you have are similar to what I need. > Note that for HTML4.01 and later, you need a Table::Header and > Table::Body as well -- the body can contain rows as well. See "Future Plans". :) > It should also be possible to create a generic table: > > table = Table.new { ... } > HTML::Table.to_html(table) > > I'm just thinking it would be nice if we have similar APIs. I'm not > there, yet, but I think this is more or less the direction that I > was headed. How about something like: table = Table.new("PDF"){ ... } This cuts it down to one line, and lets us define a default (which I would vote should be "HTML"). Another option is to make PDF a subclass of HTML::Table. I dunno enough about what you're trying to do, though. Regards, Dan