merge default doc-dc
authorDamien Correia
Mon, 09 Jul 2018 13:48:31 +0200
branchdoc-dc
changeset 277 7e4fd92a7880
parent 276 69cd0ee4546a (current diff)
parent 217 46402f73be89 (diff)
merge default
--- a/src/pyams_utils/include.py	Wed Jul 04 14:24:03 2018 +0200
+++ b/src/pyams_utils/include.py	Mon Jul 09 13:48:31 2018 +0200
@@ -68,5 +68,5 @@
     if hasattr(config, 'load_zcml'):
         config.load_zcml('configure.zcml')
 
-    PageTemplateFile.expression_types['extension'] = ExtensionExpr
-    Z3cPageTemplateFile.expression_types['extension'] = ExtensionExpr
+    PageTemplateFile.expression_types['tales'] = ExtensionExpr
+    Z3cPageTemplateFile.expression_types['tales'] = ExtensionExpr
--- a/src/pyams_utils/tales.py	Wed Jul 04 14:24:03 2018 +0200
+++ b/src/pyams_utils/tales.py	Mon Jul 09 13:48:31 2018 +0200
@@ -97,7 +97,7 @@
 
 
 class ExtensionExpr(ContextExprMixin, StringExpr):
-    """extension: TALES expression
+    """tales: TALES expression
 
     This expression can be used to call a custom named adapter providing ITALESExtension interface.
     """
--- a/src/pyams_utils/text.py	Wed Jul 04 14:24:03 2018 +0200
+++ b/src/pyams_utils/text.py	Mon Jul 09 13:48:31 2018 +0200
@@ -152,3 +152,18 @@
         terms = [SimpleTerm(name, name, translate(adapt.title).label)
                  for name, adapt in registry.getAdapters(('', request), IHTMLRenderer)]
         super(RenderersVocabulary, self).__init__(terms)
+
+
+@adapter_config(name='br', context=(Interface, Interface, Interface), provides=ITALESExtension)
+class BrTalesExtension(ContextRequestViewAdapter):
+    """extension:br(value, class) TALES expression
+
+    This expression can be used to context a given character ('|' by default) into HTML
+    breaks with given CSS class.
+    """
+
+    def render(self, context=None, css_class='', character='|'):
+        if context is None:
+            context = self.context
+        br = '<br {0} />'.format('class="{0}"'.format(css_class) if css_class else '')
+        return context.replace(character, br)