Rawk. This was exactly what I was looking for. I have a unit tested
Uberspect impl for JRuby that can handle RubyObjects in the VelocityContext.

On 2/20/07, Nathan Bubna <[EMAIL PROTECTED]> wrote:

Just set the following property...

runtime.introspector.uberspect =
org.apache.velocity.util.introspection.MyUberspect

On 2/20/07, Michael <[EMAIL PROTECTED]> wrote:
> Uberspector eh? Sounds like a good direction. The jython Uberspector
link
> will be a big help.
>
> Assuming I can get the Ubspector together, how does one set a new
> Uberspector into Velocity?
>
> On 2/20/07, Will Glass-Husain < [EMAIL PROTECTED]> wrote:
> >
> > I like the Uberspector idea.  Nice and generic.  Cleanly provides a
> > bridge between Velocity and Ruby syntax.
> >
> > On 2/20/07, Nathan Bubna <[EMAIL PROTECTED]> wrote:
> > > Oh, and the other thing that might work is to implement a custom
> > > Uberspect that knows how to properly look up methods on a
RubyObject.
> > >  This would probably be more work than an event handler or simple
> > > object wrapper, but i imagine that it could turn out to be the most
> > > useful for integrating JRuby and Velocity in the long run.
> > >
> > > On 2/20/07, Michael <[EMAIL PROTECTED]> wrote:
> > > > How would  the RubyObjectWrapper work when specifying method
argument,
> >
> > > > e.g$jrubyObject.testMethod( "argument1", "argument2" ) ?
> > > >
> > > > I already start down the road of using an Event handler for
> > InvalidReference
> > > > to catch instances of RubyObject. It works for
$jrubyObject.testMethod
> > , but
> > > > I am having the same problem as above, how to handle method
arguments?
> > The
> > > > InvalidReferenceEventHandler#invalidMethod does not appear to
contain
> > the
> > > > argument information for a reference $jrubyObject.testMethod(
> > "argument1",
> > > > "argument2" )
> > > >
> > > > thanks,
> > > > Michael
> > > >
> > > > On 2/20/07, Nathan Bubna <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > > I imagine you could get pretty far by wrapping the RubyObjects
in a
> > > > > more Velocity-friendly object that takes advantage how Velocity
> > treats
> > > > > get(String) methods before putting it into the context.
> > > > >
> > > > > Perhaps something like:
> > > > >
> > > > >
> > > > > public class RubyObjectWrapper {
> > > > >    private RubyObject foo;
> > > > >    public RubyObjectWrapper(RubyObject wrapMe) {
> > > > >         this.foo = wrapMe;
> > > > >    }
> > > > >    public Object get(String methodName) {
> > > > >         return new RubyObjectWrapper(this.foo.callMethod(
> > > > > foo.getRuntime(), methodName));
> > > > >    }
> > > > > }
> > > > >
> > > > > If i understand the problem space here, this should allow you to
> > > > > traverse the object graph for you RubyObjects as you ask:
> > > > >
> > > > > $jrubyObject.testMethod
> > > > >
> > > > > I'm really not at all familiar with Ruby, much less JRuby, but
> > perhaps
> > > > > this will help you get on the right track.  I use tricks like
this
> > to
> > > > > simplify the VTL syntax for various tools in VelocityTools all
the
> > > > > time.
> > > > >
> > > > > The other thing which may help here is using Velocity's
EventHandler
> > > > > capabilities to recognize when a reference is a RubyObject and
treat
> > > > > it differently.   Will is much more experienced and
knowledgeable on
> > > > > event handlers than i am, so he may be able to tell you better
> > whether
> > > > > or not that is a dead end for this sort of thing.
> > > > >
> > > > >
> > > > > On 2/20/07, Michael <[EMAIL PROTECTED]> wrote:
> > > > > > Hello,
> > > > > >
> > > > > > I have been using Velocity for years now and find it the best
> > templating
> > > > > > language around. This has lead me to try and spread the joy by
> > > > > attempting to
> > > > > > swap out RHTML for Velocity in JRuby on Rails.
> > > > > >
> > > > > > I have a few simple Ruby test scripts that parse a templates
> > Velocity.
> > > > > > Things get messy when Velocity needs to traverse an object
graph.
> > When
> > > > > used
> > > > > > in Rails, the VelocityContext can have a mix of Java objects
and
> > > > > RubyObject
> > > > > > (these are the problematic ones).  The RubyObject is a wrapper
for
> > a
> > > > > Ruby
> > > > > > object from the JRuby runtime. The RubyObjects do not have
static
> > typed
> > > > > > methods, but everything must go through the method
'callMethod'.
> > > > > >
> > > > > > For example, to use velocity notation on the Java object
'sample'
> > to get
> > > > > the
> > > > > > method 'test':
> > > > > >    $sample.test
> > > > > >
> > > > > > would be on a RubyObject 'sample' to get the method 'test':
> > > > > >    $sample.callMethod( $sample.getRuntime(), "test" )
> > > > > >
> > > > > > Things get sticker for passing arguments to a method in
> > RubyObject, all
> > > > > > arguments must implement IRubyObject. I will just skip over
this
> > for
> > > > > now.
> > > > > >
> > > > > > Here is the crux of my question,  is it possible to extend
> > Velocity to
> > > > > add
> > > > > > support for handling RubyObjects? Ideally Velocity would be
able
> > to
> > > > > > determine whether an object is an implementation of
RubyObject, or
> > not,
> > > > > and
> > > > > > handle appropriately, i.e $jrubyObject.testMethod could be
call
> > directly
> > > > > > instead of the callMethod for a RubyObject.
> > > > > >
> > > > > >
> > > > > > thanks,
> > > > > > Michael
> > > > > > [EMAIL PROTECTED]
> > > > > >
> > > > >
> > > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > >
> > > > >
> > > >
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Forio Business Simulations
> >
> > Will Glass-Husain
> > [EMAIL PROTECTED]
> > www.forio.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to