[stringtemplate-interest] Renderer "modes"
Sean St. Quentin
sean.stquentin at gmail.com
Tue Jun 20 18:09:17 PDT 2006
On 21/06/06, Terence Parr <parrt at cs.usfca.edu> wrote:
>
>
> On Jun 19, 2006, at 8:06 PM, Sean St. Quentin wrote:
>
> > On 20/06/06, Kunle Odutola <Kunle_Odutola at hotmail.com> wrote:
> > Hi Sean,
> >
> > > Without knowing of an easy way to fix this (by easy I mean not
> > having two
> > > arrays of preformatted information being sent to the view, which
> > seems
> > kinda
> > > wrong), I was thinking about having rendering modes for an
> > > AttributeRenderer.
> >
> > Formatter ojects are currently the prescribed way. See the types in
> > the
> > "Antlr.StringTemplate.Utils" namespace. You wrap each entry in your
> > array.
> >
> > Hey Kunle,
> > Yeah, I considered that option, but it seems to me a little awkward.
>
> It is a pain to manually wrap each object before you inject. Using
> types is a crude instrument for rendering as you might have two Lists
> of strings that each need to be dealt with differently.
> Hmm....interesting...
>
> > For instance, formatter/renderer combination makes this easy:
> >
> > $people:{
> > <h2>$it.Name$</h2>
> >
> > $it.Relations:{<a onclick="registerRelation('$it.Value;
> > format="js"$');">$it.Value$</a> }$
> >
> > }$
> >
> > Without using formatters on renderers, it would be possible, but
> > the controller would be overly complex with several wrapper classes.
>
> Well, you'd need one for javascript but what others would you need?
The problem is that the view is displaying children of an object, so to wrap
them you need to un-nessesarily wrap the parent object too.
Say you have an array, Person[] people;
And Person itself contains Relation[] relations;
Then you're going to need class PersonWrapper { RelationWrapper[] relations;
}
You end up with something like:
foreach (Person p in people)
{
foreach(Relation r in p.Relations)
{
// wrap relation
}
// wrap person
}
Its a lot of iterations and instances, and seems a tad excessive.
ASTExpr:
>
> protected Object rawGetObjectProperty(StringTemplate self, Object
> o,
> String propertyName) {...}
>
> so that it checked for a renderer for o's type before doing anything
> else. A renderer registered for o's type would take precedence over
> anything else even if o is a Map or StringTemplate. This way we can
> automatically add properties essentially to any type of object.
>
> How does this sound? I like it.
Brilliant! The only reason I suggested the $obj;format="js"$ was so that you
dont get any conflicts between renderer methods and properties on the object
being rendered. Behind the scenes it'd still work as $obj.js$, so no
slippery slope... (afaik).
Sean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060621/d0caaa26/attachment.html
More information about the stringtemplate-interest
mailing list