On Wed, Nov 19, 2008 at 9:17 PM, Jorge Vargas <[EMAIL PROTECTED]> wrote:
>
> two questions one email
>
> 1- how can I add whitespace in html building, I find literal(' ')
> ugly. The use case two tags inside a div
> HTML.span('Welcome %s' % identity['repoze.who.userid'])+literal('
> ')+link_to('logout','/logout_handler')
Yes, mixing whitespace with HTML builder is not very elegant. I came
across the same problem but couldn't think of a solution. You can
minimize repetitive whitespace with variables; e.g., SPACE, NL. HTML
builder was mainly written to support the other helpers.
> 2- why does link_to works as it does?
>
>>>> link_to('foo')
> literal(u'<a href="">foo</a>')
>>>> link_to('foo','bar')
> literal(u'<a href="bar">foo</a>')
>>>> link_to(url='bar')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: link_to() takes at least 1 non-keyword argument (0 given)
>
> that is totally unpythonic doesn't this seems a lot better?
>
>>>> link_to('foo')
> literal(u'<a href="foo">foo</a>')
>>>> link_to('foo','bar')
> literal(u'<a href="foo">bar</a>')
>>>> link_to(url='bar')
> literal(u'<a href="bar">bar</a>')
>
> in fact the second form reads like english link to foo named bar
>
> the second form just requires a change of signature.
> def link_to(url, label='', **attrs):
It was ported that way from Rails, and remained unchanged in
WebHelpers 0.6 because I thought that's how people liked it. I also
had plans to create a link() helper combining link_to and url_for (the
way redirect_to implicitly calls url_for), which would require one
argument for the label and several for the URL. In that case the
label would have to be first to keep the URL parts together. That
didn't end up working out due to the evolution of url_for() to url(),
which in Pylons 0.9.7 has multiple methods and thus can't be called
solely by positional and keyword arguments.
Also, this order is parallel to link_to_if and link_to_unless, which
always show the label but only sometimes make it a link, so the label
belongs first.
Perhaps the URL argument should be mandatory, but it was intended to
default to href="", which is generally the default link target. In
any case, there have been so many changes to WebHelpers syntax the
past six months that I don't want to make people go through another
change.
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---