[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] traits-0.0.0

Ara.T.Howard

5/3/2005 8:27:00 PM

5 Answers

dave

5/3/2005 9:02:00 PM

0


Magnificent !

--
>here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.


Kevin Howe

5/3/2005 10:54:00 PM

0

Very cool, this is along the lines of something I've been toying with for
the next version of Nemo (rubyforge.org/projects/nemo). Nemo tags class
attributes (traits) with display-related metadata, then later uses it to
render an html table or html edit form. The trait version might look
something like this:

class Foo
mtrait :name, :label=>'Full Name', :required=>true
mtrait :birthday, :type=>:date, :required=>true
end

foo = Foo.new
foo.name = 'Joe'
foo.birthday = Date.today

Editor.new(foo).render

This would display an html form with two required text fields labelled "Full
Name" and "Birthday". Hitting the save button updates the object instance
with the given input, assuming it passes all validations.

I've been wanting to abstract out the metadata definition into a generic
mechanism for defining metadata on any attribute, but if this were added to
traits that would pretty much be it. Thoughts?

Also, how does trains handle inheritance? Let's say we have A < B, then B
adds a few more traits, will A's @__trait data remain unaffected?

- Kevin


Ara.T.Howard

5/4/2005 2:41:00 AM

0

Kevin Howe

5/4/2005 2:31:00 PM

0

> > I've been wanting to abstract out the metadata definition into a generic
> > mechanism for defining metadata on any attribute, but if this were added
to
> > traits that would pretty much be it. Thoughts?
>
> you would want something like
>
> class Foo
> trait 'a', 'description' => 'metadata', 'fu' => 'bar'
> end
>
> p Foo::trait_opts('a')
>
> that'd be possible. or did you mean something else?

Exactly :) Then something like Foo::trait_opts.each { |trait,opts| } could
be used to loop through the ordered list of traits.

- Kevin


Gavin Kistner

5/4/2005 2:42:00 PM

0

On May 3, 2005, at 4:54 PM, Kevin Howe wrote:
> Very cool, this is along the lines of something I've been toying
> with for
> the next version of Nemo (rubyforge.org/projects/nemo). Nemo tags
> class
> attributes (traits) with display-related metadata, then later uses
> it to
> render an html table or html edit form. The trait version might look
> something like this:

I offer for consideration my ValidForm library:

http://phrogz.net/RubyLibs/rdoc/files/ValidFo...

Allows you to create fields and validation rules around them, render
them out to HTML (with client-side validation of those rules) and
then re-validate them server-side in Ruby.