Added 'fanstatic:' TALES expression ZTK-1.1
authorThierry Florac
Sun, 20 Nov 2011 12:47:11 +0100
branchZTK-1.1
changeset 87 689eef034b00
parent 85 2f9d956952cd
child 88 37c6b51cef8b
Added 'fanstatic:' TALES expression
ztfy/utils/tal/configure.zcml
ztfy/utils/tal/fanstatic.py
--- a/ztfy/utils/tal/configure.zcml	Tue Nov 01 18:29:31 2011 +0100
+++ b/ztfy/utils/tal/configure.zcml	Sun Nov 20 12:47:11 2011 +0100
@@ -1,5 +1,6 @@
 <configure
 	xmlns="http://namespaces.zope.org/zope"
+	xmlns:tales="http://namespaces.zope.org/tales"
 	i18n_domain="ztfy.utils">
 
 	<adapter
@@ -32,4 +33,8 @@
 		provides="zope.traversing.interfaces.IPathAdapter"
 		for="zope.publisher.interfaces.browser.IBrowserRequest" />
 
+	<tales:expressiontype
+		name="fanstatic"
+		handler=".fanstatic.FanstaticTalesExpression" />
+
 </configure>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/tal/fanstatic.py	Sun Nov 20 12:47:11 2011 +0100
@@ -0,0 +1,38 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008-2011 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+__docformat__ = "restructuredtext"
+
+# import standard packages
+
+# import Zope3 interfaces
+
+# import local interfaces
+
+# import Zope3 packages
+from zope.tales.expressions import StringExpr
+
+# import local packages
+from ztfy.utils.traversing import resolve
+
+
+class FanstaticTalesExpression(StringExpr):
+
+    def __call__(self, econtext):
+        lib, res = self._expr.split('#')
+        module = resolve(lib)
+        resource = getattr(module, res)
+        resource.need()
+        return ''