Hello, as discussed briefly with Malte on #repoze, I'd like to add XInclude support to the ZPT Chameleon templates. As it turned out, it is quite simple and the patch is attached to this message.
Opinions? Suggestions? Fabio
diff --git a/src/chameleon/zpt/language.py b/src/chameleon/zpt/language.py index 0a06ddf..37cd809 100644 --- a/src/chameleon/zpt/language.py +++ b/src/chameleon/zpt/language.py @@ -46,6 +46,8 @@ class ZopePageTemplateElement(translation.Element): return True if self.element.metal_use or self.element.metal_extend: return True + if self.element.xi_href: + return True @property def define(self): @@ -160,6 +162,12 @@ class ZopePageTemplateElement(translation.Element): return self.element.meta_cdata @property + def include(self): + href = self.element.xi_href + if href is not None: + return types.join(self.element.translator.split(href)) + + @property def text(self): text = self.element.text if text is not None: @@ -251,6 +259,8 @@ class ZopePageTemplateElement(translation.Element): meta_interpolation_escaping = utils.attribute( utils.meta_attr('interpolation-escaping'), default='true', recursive=True) + xi_href = None + class XHTMLElement(ZopePageTemplateElement): """XHTML namespace element.""" @@ -335,6 +345,9 @@ class METALElement(XHTMLElement): class TextElement(XHTMLElement): meta_interpolation_escaping = False +class XiIncludeElement(XHTMLElement): + xi_href = utils.attribute("href") + class Parser(etree.Parser): """Zope Page Template parser.""" @@ -342,7 +355,8 @@ class Parser(etree.Parser): config.XHTML_NS: {None: XHTMLElement}, config.META_NS: {None: MetaElement}, config.TAL_NS: {None: TALElement}, - config.METAL_NS: {None: METALElement}} + config.METAL_NS: {None: METALElement}, + config.XI_NS: {'include': XiIncludeElement}} fallback = XHTMLElement diff --git a/src/chameleon/zpt/template.txt b/src/chameleon/zpt/template.txt index a599bab..ddbf5fa 100644 --- a/src/chameleon/zpt/template.txt +++ b/src/chameleon/zpt/template.txt @@ -811,3 +811,18 @@ Variable definition: ^ ... SyntaxError: invalid syntax + +XInclude-support +---------------- + +Test the XInclude support in ZPT templates: + + >>> t = PageTemplateFile(os.path.join(path, 'xinclude1.pt'), None) + >>> print t() + <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude"> + <BLANKLINE> + <div xmlns:test="http://test/ns"> + <span test:attr="test">Hello, world!</span> + </div> + <BLANKLINE> + </html>
_______________________________________________ Repoze-dev mailing list Repoze-dev@lists.repoze.org http://lists.repoze.org/listinfo/repoze-dev