[stringtemplate-interest] Renderer "modes"
Jeremy Gray
jgray at siberra.com
Fri Jun 16 09:10:08 PDT 2006
This kind of functionality sounds pretty good to me, and I wouldn't be
opposed to the syntax and attribute you're suggesting. This would prove
especially useful in cases where, by example, we need to format various
DateTime instances in different ways in a single template run (or
percentages different from other fractional numbers, etc.)
Now, I could easily see someone then suggesting that ST support
something akin to:
$order.OrderDate; format="D"$
where:
class DateTimeRenderer : IAttributeRenderer
{
public string ToString(object data, string format) { return
((DateTime)data).ToString(format); }
}
but, to be clear, I only raise this example in order to cut it off at
the pass, as it would start us down a slippery slope that Terrence would
surely want to avoid and that I, as much as I like the possibilities it
would present as a programmer geek, also would want to avoid.
Jeremy
________________________________
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Sean St.
Quentin
Sent: Thursday, June 15, 2006 7:55 PM
To: stringtemplate-interest at antlr.org
Subject: [stringtemplate-interest] Renderer "modes"
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/a1ec5fbb/attachment.html
More information about the stringtemplate-interest
mailing list