[stringtemplate-interest] Multimethods
Terence Parr
parrt at cs.usfca.edu
Mon Nov 10 09:34:33 PST 2008
Hi. STdoesn't allow you to pass information from the template to the
model. however, you can register a renderer for a particular Model
class (even String) or template or group. Then it uses that renderer's
toString(o) method to convert to text. It allows you to pass a format
option. For example with dates you could past terse or verbose as a
format option.
Is there a string you can pass to a renderer that can be broken apart
to compute the proper URL? If the URL is truly computation, then it
must be a part of the controller; the controller does the mapping of
URL to executable code. This is case, then it would violate MVC
separation to compute URLs in the view.
Ter
On Nov 9, 2008, at 7:17 AM, Roman Odaisky wrote:
> Greetings,
>
> I’m developing a site using Django and StringTemplate. It has so far
> been
> wonderful.
>
> However, a question has arisen which I seem unable to solve using
> the current
> framework.
>
> Following Django conventions, I add ‘get_absolute_url’ methods to
> model
> classes. Then I use <a href="$something.absolute_url$"> to create
> links. That
> allows me to change the URL layout of the site however I like, and
> links stay
> correct. (The site is still under construction, so I don’t have to
> worry
> about dangling references.) A typical construct is:
>
> <p>You have the following gadgets and widgets:
> <ul>
> $user.allof_gadget:{g|
> <li><p>$g.title$</p>
> <ol>$g.allof_widget:{w|
> <li><a href="$w.absolute_url$">$w$</a></li>
> }$
> </li>
> }$
> </ul></p>
>
> However, some pages need URLs that refer to more than one item,
> neither of
> which is deducible from the other. This one is similar to my needs:
>
> https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.20/+bug/42160
>
> So, what I need is to call a Python function that would determine a
> URL for
> two items. How is it possible to invoke such a multimethod from within
> StringTemplate? Can ST create templates that would call user-defined
> functions, like this:
>
> stg.defineTemplate("foo", foo)
>
> def foo(**kwargs):
> ...do something
> return something
>
> and $foo(x=1, y=2)$ would call the function with the required keyword
> arguments?
>
> --
> TIA
> Roman.
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list