[albatross-users] Some questions and my albatross wrapper....
Gabriel Cooper
gabriel.cooper at mediapulse.com
Fri Feb 24 09:23:39 EST 2006
>
> <al-for expr="[('bob','smith'),('jane','doe'),]"
> iter="iter"
> expand="(first_name,last_name)">
> ...
>
> where the "expand" parameter expands the list given into locals.
>
> Seems to work pretty well. I suppose we could make naming the iterator
> optional as well... I've found use for it on count() and so on, so I
> like to keep it around. =D
Continuing that thought process.... Hm. One could combine the iter and
expand parameters where, instead of being joined to locals, the names
given in the expand parameter would become attributes of the iterator or
perhaps dictionary keys, like so:
iter.first_name
iter.last_name
or
iter['first_name']
iter['last_name']
then we'd still have access to
iter.value()
iter.count()
etc.
Heck we could easily implement both the dictionary and attribute method
by using this class here:
class DictObj(dict):
'''
DictObj is a normal dictionary that allows you to access its members
via the standard ``var[key]`` method as well as the
more-readable ``var.key``.
'''
def __init__(self,dic={}):
dict.__init__(self,dic)
self.__dict__ = self
Mostly I enjoy the attribute implementation (iter.name) because it
removes so much confusion with regard to quoting inside HTML code. i.e.
onclick="window.open('<al-value expr="someDictionary['key']"/>',
'windowname');"
A syntax hilighter that can make it through that mess of quotes would be
mighty impressive. Compare to:
onclick="window.open('<al-value expr='iter.key'/>', 'windowname');"
Much easier for syntax highlighters as it would consider the al-value
nonsense a jumble of characters inside a double-quoted (") string, as
opposed to a syntax-breaking bit of code inside an anchor tag. And also,
the Designers here don't do much by way of programming, but they can do
a bit by example. Dictionaries aren't as easy to remember from one month
of disuse to the next (or how to do them) as the attribute
implementation, since it's so much more readable and memorable.
We also wouldn't have to worry about muddying locals with for-loop refuse.
Gabriel.
More information about the Albatross-users
mailing list