[stringtemplate-interest] Renderer "modes"
Sean St. Quentin
sean.stquentin at gmail.com
Mon Jun 19 04:32:13 PDT 2006
Cheers Jeremy, I agree.
My idea was not to have the format as an argument for ToString, as this
seems to encourage all sorts of potential bad things, even passing a basic
script to the renderer, eg $value;format="references++"$ or whatever.
I would prefer to have the format as a method, as I like the idea of ST
being in control of how to call the renderer - in the process making the
renderers more simple. ST also then knows what formats the renderer can
support, and if the format is not supported by the renderer, ST can call the
default ToString method, or even print an error message that the format is
not supported.
It also makes Renderer inheritance a bit more logical, and its not a
breaking change.
Sean.
On 17/06/06, Jeremy Gray <jgray at siberra.com > wrote:
>
> 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.
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060619/7c0b924d/attachment.html
More information about the stringtemplate-interest
mailing list