[stringtemplate-interest] Multimethods
Terence Parr
parrt at cs.usfca.edu
Fri Nov 21 10:49:24 PST 2008
On Nov 14, 2008, at 6:17 AM, Roman Odaisky wrote:
> Hi,
>
>> your template could be
>>
>> blog_post(m,d,y) ::= "/y/m/d&sessionid=<session.ID>"
>> or whatever the field of the session is. would that work?
>
> That would work. But that would cause unnecessary duplication.
duplication of what?
> Django has a thing called URLconf[1] which allows one to bind URLs to
> functions by means of regular expressions. Moreover, it allows one to
> determine a URL that would cause a given function to get called with
> given
> arguments.
>
> For example, if a URLconf entry looks like this:
>
> (r"^/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)$", posts_by_date)
>
> then Django would call posts_by_date(request, year=2008, month=11,
> day=14).
> And when one calls reverse(posts_by_date, year=2008, month=11,
> day=14), one
> gets "/2008/11/14". So one line in a configuration file works both
> ways. If I
> were to create a template like the one you suggested above, it would
> duplicate the information that is already known to the application.
Well, this is really a controller issue. Technically URLs must be
computed by the controller and sent in as data to the view. However we
want to fudge this to make it convenient is fine.
> I need to have an option to use that system. Adding a
> get_absolute_url method
> to objects works as long as the URL depends only on one object, but
> recently
> I’ve encountered URLs that need more than one. At the moment I’m
> using hacks
> like $o1.url_for_o2.(o2.id)$ where get_url_for_o2() returns an
> object with
> operator [] overloaded.
Add a renderer for that object and then use a format option to select?
> Do you have anything against explicit adding of templates that call
> functions
> like I proposed in the first message?
Yes, I'm afraid, because then $f()$ can call it arbitrary function.
T
>
>
> References:
> [1] http://docs.djangoproject.com/en/dev/intro/tutorial03/#design-your-urls
>
> --
> WBR
> 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