[stringtemplate-interest] StringTemplate extension ideas
Kunle Odutola
Kunle_Odutola at hotmail.com
Mon May 1 16:22:46 PDT 2006
Ter,
> > Arrrrrggh!. Now you tell me (just spent a few hours working on
> > same) ;-)
>
> [chuckle] Been in there since 2.2; from release notes:
>
> template arguments can be anonymous templates now or simple strings.
> From the bug list:
> Template inclusion expressions won't accept a nested template
> as an argument. I'd like to be able to write <foo(bar={...})>, which
> would mean the same thing as <foo(bar="":{...})>.
> Now you can do <foo(bar={<firstName> <lastName>)>}.
Oh, that. Nevermind, just had a brainfreeze.
Only thing missing is the double eval-context. No pressing use-case for that
as I mentioned.
> > I was going with the context of the template making the foo() call
> > (like
> > caller2.st in my original mesg).
>
> Actually you'd have to bind early to do that somehow...you'd be
> forced to convert to text early; should avoid until toString() is
> called. The arg={template} is not an evaluation per se, but the
> definition of a template. Only tostring() can do the eval, which
> will happen only on the $arg$ ref.
Yeah. I was in a passing-a-big-text-block (i.e. long, literal string arg)
frame of mind. Was happy to relax
the usual lazy eval rules.
> > Anyway, an example.
> >
> > $target(t={This is an $innerAttrib$}, innerAttrib=outer.Attrib)$
> >
> > This evaluates 'outer.Attrib' in the caller's context and places it
> > in the
> > target()'s (and the anon-template's) context as 'innerAttrib'.
>
> innerAttrib=Attrib
Not really, "outer" is an attrib itself. Anyway, my point was that I wanted
to avoid having to declare the intermediate "InnerAttrib". But the following
ST idiom resolves that particular concern nicely.....
> can you do t=blort:{b | Hi, $b$} as an argument? Should be able to.
Yep. Allowing my example to be re-written as:
$target(t=outer.Attrib:{outerAtrribute | This is an $outerAtrribute$})$
Kunle
More information about the stringtemplate-interest
mailing list