[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] Table Helper for Ruby on Rails

Bauduin Raphael

11/22/2004 6:19:00 PM

Hi all,

I have put the initial release (0.1) of a table helper for Ruby on Rails
at http://tablehelper.rub... , with an demo page at
http://www.raphinou.com/rails/table_... .
This component is designed to display data from an Array into an HTML table.
It is possible to display an array data in a simple html table, but also
to use more advanced features like:
- displaying certain fields of the table as links (links that can be
built thanks to the data from other fields in the row, like adding
parameters to the URL)
- displaying column headers to sort the displayed data
- manipulate the data before it gets displayed (useful for translations eg)
- styling each part of the table with CSS
- display navigation links when the number of rows is too big to be
displayed on one page
- give an id to the table and each row (for CSS or javascript
manipulation eg)


The simplest example (also available at the demo page) is like this:
simple_array = [ [ 1, "Ruby", "http://www.ruby-lang...],
[ 2, "Python", "http://www.python...],
[ 3, "Java", "http://www.java.sun...],
[ 4, "Perl", "http://www.perl...],
[ 5, "lua", "http://www.lua...]
]

#controller
@e = { "array" => simple_array }
#view
<%= table(@e1, "display" => :default) %>

All further parameters are passed to the helper by instantiating the
TableFields class.

To give an id to the table, we can do this:
#controller
fields = TableFields.new(:table_id => "example")
@e = { "array" => simple_array , "fields" => fields}


We can set the column names:
fields.field_names = [ "id", "name", "homepage"]

Links are defined thanks to the LinkSpec class. Eg:

ror_link_spec = LinkSpec.new
ror_link_spec.href = "http://www.rubyonrails...

fields.add_link("column_name", ror_link_spec)

A link built with the data in the array is also simple, but I'll let you
discover this and the other features at the demo page. Feedback and
comments are welcome.

Raph