[Grok-dev] Re: regebro-guido-templates: comments

Lennart Regebro regebro at gmail.com
Mon Oct 22 17:42:45 EDT 2007


On 10/22/07, Brandon Craig Rhodes <brandon at rhodesmill.org> wrote:
> I've taken a brief look already, and will take a deeper one either
> tonight or tomorrow night.  My big issue at the moment is that I'm
> still skeptical about whether different template languages need
> different default namespaces.  It seems to me that namespace should
> depend on the framekwork, not the template language.

I thought so too. But on the other hand it seems so far that the only
languages that actually have use of the same default namespace are the
ones that should have none at all, the 100% pure push languages (from
now on abbreviated 100ppp (tm)) like Kid and Templess. If you push
context or view to them they can't do anything with them, as they
don't understand attribute access. Genshi and ZPT both can use the
same standard namespace, but Genshi should really have some support
for traversing with a "path" function (not yet implemented).

So it seems to me, that in fact, the namespace does depend just as
much on the template language as on the framework.

> Martijn has asked the question: how can a developer who wants to
> "push" template data write code so as to be sure that nothing leaks
> through because he accidentially adds to a default Zope namespace
> rather than creating one from scratch?  At least two answers have been
> proposed:
>
>  1. The rule would be: "use the correct extension on your templates."
>     For example, if they always used ".gr" instead of ".gt", then they
>     would be running "restricted Genshi" and instead of getting their
>     "view", "context", etcetera, they would only get what their own
>     "view.namespace()" method defined, or, if they forgot to supply
>     it, a safely empty dictionary.
>
>  2. The rule would be: "always define namespace() methods returning
>     dictionaries instead of update() methods setting attributes."  If
>     a namespace method were present, then the default namespace would
>     be thrown out in favor of calling the user's namespace().

Actually, I would prefer a third option:

3. If you want 100-percent-pure-push, then use a 100ppp template
system. Genshi is designed to allow you to do ANYTHING. So is Cheetah,
really, you write python in the templates. If you don't want to allow
that, you shouldn't use Genshi or Cheetah.

But yes, we could let the rendering call view.namespace(), and let the
view.namespace() call template.namespace(), and that way allow
overriding of the template.namespace() on a per view basis. I think
that's a rather minor usecase, but it's only one redirection, and if
we document it properly, then that would be OK I guess.

>  d) The default, globally-registered IDefaultNamespace builds the
>     standard Zope namespace.

This doesn't allow for per-template-class namespaces, which we really need.

>  e) The user can create, as a local utility on any app he pleases, the
>     grok.templates.EmptyNamespace utility, which just returns an empty
>     dictionary.  (Or, of course, a utility of his own devising.)

Hmm. That would then be used for all templates, and if you use this to
remove something from the namespace, every template you haven't
written would instantly fail... Unless you put it on a layer, but then
it has to be a view, and then we are really making a supremely complex
story to support a non-existant usecase. :-)

That said, I kinda like the idea of globally *extending* the
namespace. Just look at how the standard macro in plone a CPS pushes
in common tool into the namespace to be used by all templates... Worth
thinking about.

> Besides looking at the Genshi code, what else should I be doing?
> Let's list the sorts of things I should try to accomplish soon:

Wow. I don't envy you. Note: You rule! :-)

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64


More information about the Grok-dev mailing list