[stringtemplate-interest] Renderer "modes"

Sean St. Quentin sean.stquentin at gmail.com
Thu Jun 15 19:55:14 PDT 2006


Firstly, thanks everybody for ST, I love it.

I have a suggestion/question about the renderers. I'm currently facing a
situation where I need to have an attribute in both HTML formatting and
Javascript formatting, eg:

<a onclick="DoSomething('$it.Name.FullName$')>$it.Name.LastName$,
$it.Name.FirstName$</a>

And its encountering problems when the name contains a single quote, eg:
Adrian O'Conner.

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.

So I would be able to do something like this (ignoring the syntax I've
used):

<a onclick="DoSomething('$it.Name.FullName;
format="js"$'>$it.Name.LastName$, $it.Name.FirstName$</a>

with the attribute renderer for a string being (C#):

class StringRenderer : IAttributeRenderer
{
    public string ToString(object data) { return
HtmlTools.EncodeHtml((string)data);
}

    [Format("js")]
    public string AsJs (object data) { return HtmlTools.EncodeJs((string)data);
}
}

Is there something like this already available in ST?

If not, is it possible? It doesn't seem (to me) to breach the MVCR
principals, as we're not executing arbitary code, rather making the
renderers a little more flexable.

Any thoughts?
Cheers, Sean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060616/e4c54b28/attachment.html


More information about the stringtemplate-interest mailing list