[Checkins] SVN: Sandbox/malthe/chameleon.core/ Make default symbol available to dynamic attribute evaluations.
Malthe Borch
mborch at gmail.com
Mon Nov 17 07:03:43 EST 2008
Log message for revision 93040:
Make default symbol available to dynamic attribute evaluations.
Changed:
U Sandbox/malthe/chameleon.core/CHANGES.txt
U Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py
U Sandbox/malthe/chameleon.core/src/chameleon/core/config.py
U Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt 2008-11-17 12:03:21 UTC (rev 93039)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt 2008-11-17 12:03:43 UTC (rev 93040)
@@ -4,6 +4,9 @@
HEAD
~~~~
+- Make `default` symbol available to dynamic attribute
+ evaluations. [malthe]
+
- Visit evaluation before assignment in order to support assignments
that rely on the same name in the dynamic variable scope. [malthe]
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py 2008-11-17 12:03:21 UTC (rev 93039)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py 2008-11-17 12:03:43 UTC (rev 93040)
@@ -488,6 +488,18 @@
>>> _out.getvalue()
'<div alt="Hello World!">Hello Universe!</div>'
+ Attribute default value is available under the `default` symbol.
+
+ >>> _out, _write, stream = testing.setup_stream('utf-8')
+ >>> tag = Tag('div', dict(alt=testing.pyexp('default')),
+ ... defaults=dict(alt='Hello World!'))
+ >>> tag.begin(stream)
+ >>> stream.out('Hello Universe!')
+ >>> tag.end(stream)
+ >>> exec stream.getvalue()
+ >>> _out.getvalue()
+ '<div alt="Hello World!">Hello Universe!</div>'
+
Verify that unicode data is handled correctly.
>>> _out, _write, stream = testing.setup_stream()
@@ -531,9 +543,10 @@
'<br />'
"""
- def __init__(self, tag, attributes=None,
- selfclosing=False, expression=None, cdata=False):
+ def __init__(self, tag, attributes=None, selfclosing=False,
+ expression=None, cdata=False, defaults={}):
self.tag = tag.split('}')[-1]
+ self.defaults = defaults
self.selfclosing = selfclosing
self.attributes = attributes or {}
self.expression = expression and Assign(expression)
@@ -592,9 +605,16 @@
stream.outdent()
for attribute, value in dynamic:
+ default = self.defaults.get(attribute)
+ if default is not None:
+ stream.write("%s = %s" % (stream.symbols.default, repr(default)))
+
assign = Assign(value)
assign.begin(stream, temp)
+ if default is not None:
+ stream.write("%s = None" % stream.symbols.default)
+
# only include attribute if expression is not ``None`` or ``False``
stream.write("if %s is not None and %s is not False:" % (temp, temp))
stream.indent()
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/config.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/config.py 2008-11-17 12:03:21 UTC (rev 93039)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/config.py 2008-11-17 12:03:43 UTC (rev 93040)
@@ -57,7 +57,8 @@
negotiate = '_negotiate'
translate = '_translate'
validate = '_validate'
-
+ default = 'default'
+
# advertised symbols
repeat = 'repeat'
language = 'target_language'
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py 2008-11-17 12:03:21 UTC (rev 93039)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py 2008-11-17 12:03:43 UTC (rev 93040)
@@ -234,7 +234,7 @@
tag = clauses.Tag(
self.element.tag, attributes,
expression=self.dict_attributes, selfclosing=selfclosing,
- cdata=self.cdata is not None)
+ cdata=self.cdata is not None, defaults=self.static_attributes)
if self.omit:
_.append(clauses.Condition(
self.omit, [tag], finalize=False, invert=True))
More information about the Checkins
mailing list