Added ReStructuredText renderer to raw code portlet
authorThierry Florac <tflorac@ulthar.net>
Fri, 14 Dec 2018 23:07:52 +0100
changeset 240 cb779d7092e0
parent 239 9546fffdeeaa
child 241 e2c4b5ac1922
Added ReStructuredText renderer to raw code portlet
src/pyams_portal/portlets/html/skin/__init__.py
--- a/src/pyams_portal/portlets/html/skin/__init__.py	Fri Dec 14 18:35:55 2018 +0100
+++ b/src/pyams_portal/portlets/html/skin/__init__.py	Fri Dec 14 23:07:52 2018 +0100
@@ -9,6 +9,8 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_utils.interfaces.text import IHTMLRenderer
+
 
 __docformat__ = 'restructuredtext'
 
@@ -71,6 +73,30 @@
 
 
 #
+# ReStructuredText renderer
+#
+
+@adapter_config(name='rest',
+                context=(IPortalContext, IPyAMSLayer, Interface, IRawPortletSettings),
+                provides=IPortletRenderer)
+@template_config(template='templates/code.pt', layer=IPyAMSLayer)
+class RawPortletSourceRestRenderer(PortletRenderer):
+    """ReStructured text portlet renderer"""
+
+    label = _("ReStructured text renderer")
+    weight = 20
+
+    @property
+    def body(self):
+        code = II18n(self.settings).query_attribute('body', request=self.request)
+        if code:
+            renderer = self.request.registry.queryMultiAdapter((code, self.request), IHTMLRenderer, name='rest')
+            if renderer is not None:
+                return renderer.render()
+        return ''
+
+
+#
 # Formatted HTML renderer
 #