[Checkins] SVN: z3c.pt/trunk/ Added support for tags carrying the
'tal' prefix.
Malthe Borch
mborch at gmail.com
Fri Feb 22 15:17:11 EST 2008
Log message for revision 84146:
Added support for tags carrying the 'tal' prefix.
Changed:
U z3c.pt/trunk/setup.py
U z3c.pt/trunk/z3c/pt/translation.py
U z3c.pt/trunk/z3c/pt/translation.txt
-=-
Modified: z3c.pt/trunk/setup.py
===================================================================
--- z3c.pt/trunk/setup.py 2008-02-22 18:27:08 UTC (rev 84145)
+++ z3c.pt/trunk/setup.py 2008-02-22 20:17:11 UTC (rev 84146)
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages
-version = '0.3.2'
+version = '0.3.3'
setup(name='z3c.pt',
version=version,
Modified: z3c.pt/trunk/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/z3c/pt/translation.py 2008-02-22 18:27:08 UTC (rev 84145)
+++ z3c.pt/trunk/z3c/pt/translation.py 2008-02-22 20:17:11 UTC (rev 84146)
@@ -26,7 +26,6 @@
value = self.attrib.get(ns)
if value is not None:
return factory(value)
-
return property(get)
class Element(lxml.etree.ElementBase):
@@ -43,7 +42,7 @@
if not skip:
for element in self:
element.visit(stream)
-
+
def visit(self, stream):
self.begin(stream)
self.body(stream)
@@ -181,17 +180,22 @@
msgid = msgid.replace(' ', ' ').replace('\n', '')
return msgid
-
+
+ def _static_attributes(self):
+ attributes = {}
+
+ for key in self.keys():
+ if not key.startswith('{'):
+ attributes[key] = self.attrib[key]
+
+ return attributes
+
def _attributes(self):
"""Aggregate static, dynamic and translatable attributes."""
- attributes = {}
-
# static attributes are at the bottom of the food chain
- static = [key for key in self.keys() if not key.startswith('{')]
- for key in static:
- attributes[key] = self.attrib[key]
-
+ attributes = self._static_attributes()
+
# dynamic attributes
attrs = self.attributes
if attrs is not None:
@@ -258,15 +262,37 @@
"{http://xml.zope.org/namespaces/i18n}domain", expressions.name)
i18n_name = attribute(
"{http://xml.zope.org/namespaces/i18n}name", expressions.name)
-
+
+class TALElement(Element):
+ define = attribute("define", expressions.definitions)
+ replace = attribute("replace", expressions.value)
+ repeat = attribute("repeat", expressions.definition)
+ content = attribute("content", expressions.value)
+ omit = attribute("omit-tag", expressions.value)
+
+ def _static_attributes(self):
+ attributes = {}
+
+ for key in self.keys():
+ if key not in \
+ ('define', 'replace', 'repeat', 'content', 'omit-tag'):
+ raise ValueError(
+ u"Attribute '%s' not allowed in the namespace '%s'" %
+ (key, self.nsmap[self.prefix]))
+
+ return attributes
+
# set up namespace
lookup = lxml.etree.ElementNamespaceClassLookup()
parser = lxml.etree.XMLParser()
parser.setElementClassLookup(lookup)
-namespace = lxml.etree.Namespace('http://www.w3.org/1999/xhtml')
-namespace[None] = Element
+xhtml = lxml.etree.Namespace('http://www.w3.org/1999/xhtml')
+tal = lxml.etree.Namespace('http://xml.zope.org/namespaces/tal')
+xhtml[None] = Element
+tal[None] = TALElement
+
def translate(body, params=[]):
tree = lxml.etree.parse(StringIO(body), parser)
root = tree.getroot()
Modified: z3c.pt/trunk/z3c/pt/translation.txt
===================================================================
--- z3c.pt/trunk/z3c/pt/translation.txt 2008-02-22 18:27:08 UTC (rev 84145)
+++ z3c.pt/trunk/z3c/pt/translation.txt 2008-02-22 20:17:11 UTC (rev 84146)
@@ -28,6 +28,9 @@
... <span tal:replace="'Item ' + str(i) + ')'" />
... </li>
... </ul>
+ ... <tal:example replace="'Hello World!'" />
+ ... <tal:div content="'Hello World!'" />
+ ... <tal:multiple repeat="i range(5)" replace="i" />
... <p tal:omit-tag="">No paragraph here.</p>
... <p tal:omit-tag="True">No paragraph here either.</p>
... <p tal:omit-tag="False">A paragraph here.</p>
@@ -39,28 +42,35 @@
<div>
<span style="position: absolute" id="test" class="defabc">abcghi</span>
<ul>
- <li>
- Item 0)
- </li>
- <li>
- Item 1)
- </li>
- <li>
- Item 2)
- </li>
- <li>
- Item 3)
- </li>
- <li>
- Item 4)
- </li>
- </ul>
- No paragraph here.
- No paragraph here either.
- <p>A paragraph here.</p>
- Hello World!
+ <li>
+ Item 0)
+ </li>
+ <li>
+ Item 1)
+ </li>
+ <li>
+ Item 2)
+ </li>
+ <li>
+ Item 3)
+ </li>
+ <li>
+ Item 4)
+ </li>
+ </ul>
+ Hello World!
+ <div>Hello World!</div>
+ <BLANKLINE>
+ 1
+ 2
+ 3
+ 4
+ No paragraph here.
+ No paragraph here either.
+ <p>A paragraph here.</p>
+ Hello World!
</div>
-
+
Error handling
--------------
More information about the Checkins
mailing list