README

Path: README
Last Update: Thu Aug 24 20:16:57 Mountain Standard Time 2006

Description

   An interface for generating HTML Tables with Ruby.

Prerequisites

   * Ruby 1.8.0 or later
   * StrongTyping 2.0.6b or later

Installation

Manual Installation

   ruby test/ts_all.rb (optional)
   ruby install.rb

Gem Installation, Local

   ruby test/ts_all.rb (optional)
   ruby html-table.gemspec
   gem install html-table-<version>.gem

Gem Installation, Remote

   gem install html-table

Synopsis

   require "html/table"
   include HTML

   # Explicit syntax
   table = HTML::Table.new{ |t|
      t.border  = 1
      t.bgcolor = "red"
   }

   # Implicit syntax
   table = HTML::Table.new do
      border   1
      bgcolor 'red'
   end

   table.push Table::Row.new{ |r|
      r.align   = "left"
      r.bgcolor = "green"
      r.content = ["foo","bar","baz"]
   }

   row = Table::Row.new{ |r|
      r.align   = "right"
      r.bgcolor = "blue"
      r.content = "hello world"
   }

   table[1] = row

   puts table.html

   # Output
   <table border=1 bgcolor='red'>
      <tr align='left' bgcolor='green'>  # row 0
         <td>foo</td>                    # column 0
         <td>bar</td>                    # column 1
         <td>baz</td>                    # column 2
      </tr>
      <tr align='right' bgcolor='blue'>  # row 1
         <td>hello world</td>            # column 0
      </tr>
   </table>

   See the 'examples' directory under 'doc' for more examples.

Mixins

   Table is a subclass of Array, and therefore mixes in Enumerable.  The
   push, unshift and []= methods have been modified.  See below for details.

   Table also mixes in Attribute_Handler which provides methods for adding
   attributes to each of the tag types.  See attributes.rd2 for more details.

Notes

   A Table consists of Table::Row, Table::Caption, Table::ColGroup,
   Table::Body, Table::Foot, Table::Head and Table::Row objects.

   Table::Row objects in turn consist of Table::Row::Data and
   Table::Row::Header objects.

   Table::ColGroup objects consist of Table::ColGroup::Col
   objects.

   Table::Head, Table::Body and Table::Foot objects consist
   of Table::Row objects.

   String attributes are quoted.  Numeric attributes are not.

   Some attributes have type checking.  Some check for valid arguments.  In
   the latter case, it is case-insensitive.  See the documentation on
   specific methods for more details.

   Using a non-standard extension (e.g. "background") will send a warning to
   STDERR in $VERBOSE (-w) mode.

Known Bugs

   None that I'm aware of.  Please report bugs on the project page at
   http://ruby-miscutils.sf.net.

Future Plans

   Documentation improvements (include inline links to other files).

   Allow standard html tags to be added to elements as appropriate, such
   as <B>, <I>, etc.

Acknowledgements

   Anthony Peacock, for giving me ideas with his HTML::Table Perl module.

   Holden Glova and Culley Harrelson for API suggestions and comments.

License

   Ruby's

Copyright

   (C) 2003-2006 Daniel J. Berger
   All Rights Reserved

Warranty

   This package is provided "as is" and without any express or
   implied warranties, including, without limitation, the implied
   warranties of merchantability and fitness for a particular purpose.

Author

   Daniel J. Berger
   djberg96 at gmail dot com
   imperator on IRC (irc.freenode.net)

Developer’s Notes

   Some people might be a little annoyed with the fact that I required Ryan
   Pavlik's strongtyping package.  I'm not a big fan of strong typing myself. So,
   why did I do this?

   Normally when creating code, you setup your own rules as far as what is allowed
   as an argument.  You publish the API, set up a good set of tests, and don't
   bother worrying about types because you figure people can read the API and
   won't go out of their way to break it.  You certainly don't worry about it
   yourself because you're used to dynamic languages and find that you don't need
   the strong typing training wheels after all (right?).

   However, HTML tables have a predefined set of rules as far as what content is
   valid, and where it's placed in order to be HTML 4.0 compliant.  For example,
   if a caption is included, it should be at the 'top' of your table syntax, you
   can only have one foot section, and so on.  So, I chose to enforce these
   conventions and/or rules in Ruby via Ryan's module.  I could have lived
   without it, and instead chose to do a plethora of "kind_of?" checks.  However,
   Ryan's package is both faster and required less typing on my part.

[Validate]