[Checkins] SVN: lovely.tal/trunk/ - fixed version number

Juergen Kartnaller juergen at kartnaller.at
Tue Jul 8 09:53:19 EDT 2008


Log message for revision 88112:
   - fixed version number
   - added "clear-html" as the first executed command
   - moved the "cut" command to the front
  

Changed:
  U   lovely.tal/trunk/CHANGES.txt
  U   lovely.tal/trunk/setup.py
  U   lovely.tal/trunk/src/lovely/tal/README.txt
  U   lovely.tal/trunk/src/lovely/tal/textformatter.py

-=-
Modified: lovely.tal/trunk/CHANGES.txt
===================================================================
--- lovely.tal/trunk/CHANGES.txt	2008-07-08 13:49:50 UTC (rev 88111)
+++ lovely.tal/trunk/CHANGES.txt	2008-07-08 13:53:18 UTC (rev 88112)
@@ -2,11 +2,19 @@
 lovely.tal
 ==========
 
+
+2008/07/08 0.4.0a1:
+===================
+
+ - fixed version number
+ - added "clear-html" as the first executed command
+ - moved the "cut" command to the front
+
 2008/03/03 0.3a:
 ================
+
  - urlparse condition added
 
-
 2007/08/29 0.2.1:
 =================
  - prepare checkin on zope.org

Modified: lovely.tal/trunk/setup.py
===================================================================
--- lovely.tal/trunk/setup.py	2008-07-08 13:49:50 UTC (rev 88111)
+++ lovely.tal/trunk/setup.py	2008-07-08 13:53:18 UTC (rev 88112)
@@ -12,7 +12,7 @@
 name='lovely.tal'
 setup(
     name = name,
-    version = '0.3a',
+    version = '0.4.0a1',
     author = "Lovely Systems GmbH",
     author_email = "office at lovelysystems.com",
     description = "the lovely tal enables new tal expressions",

Modified: lovely.tal/trunk/src/lovely/tal/README.txt
===================================================================
--- lovely.tal/trunk/src/lovely/tal/README.txt	2008-07-08 13:49:50 UTC (rev 88111)
+++ lovely.tal/trunk/src/lovely/tal/README.txt	2008-07-08 13:53:18 UTC (rev 88112)
@@ -193,11 +193,36 @@
 
 We can also cut strings to a given length::
 
+Warning: cut will not check for HTML tags and will therefore cut in the middle
+         of a tag which will make HTML unusable. Only use for plain text.
+
   >>> context = Context({'cut':20})
   >>> rendered = tf._doFormat('ein superlangerstring mit ein paar kurzen strings', context)
-  >>> len(rendered) == 20
-  True
+  >>> len(rendered)
+  20
 
+cut is done as the first operation. If it is combined with replace the
+resulting string can be longer.
+
+  >>> context = Context({'cut':20, 'replace':(('ein', 'Wrong case : ein'),)})
+  >>> rendered = tf._doFormat('ein superlangerstring mit ein paar kurzen strings', context)
+  >>> len(rendered)
+  33
+
+
+Option 'clear-html'
+===================
+
+  >>> context = Context({'clear-html':True})
+  >>> tf._doFormat('Text <strong>containing</strong> HTML', context)
+  'Text containing HTML'
+
+This is done before "cut".
+
+  >>> context = Context({'clear-html':True, 'cut':10})
+  >>> tf._doFormat('Text <strong>containing</strong> HTML', context)
+  'Text conta'
+
 Option 'attach'
 ===============
 

Modified: lovely.tal/trunk/src/lovely/tal/textformatter.py
===================================================================
--- lovely.tal/trunk/src/lovely/tal/textformatter.py	2008-07-08 13:49:50 UTC (rev 88111)
+++ lovely.tal/trunk/src/lovely/tal/textformatter.py	2008-07-08 13:53:18 UTC (rev 88112)
@@ -20,9 +20,7 @@
 
 class TextFormatter(PathExpr):
 
-
     def __call__(self, context):
-
         rendered = super(TextFormatter, self).__call__(context)
         return self._doFormat(rendered, context)
 
@@ -33,6 +31,12 @@
 
         allowAll = ('allow-all' in context.vars)
 
+        if 'clear-html' in context.vars:
+            rendered = self._clearHTML(rendered, context)
+
+        if 'cut' in context.vars:
+            rendered = self._cut(rendered, context)
+
         if 'replace' in context.vars:
             rendered = self._replace(rendered, context)
 
@@ -48,9 +52,6 @@
         if 'break-string' in context.vars:
             rendered = self._breakString(rendered, context)
 
-        if 'cut' in context.vars:
-            rendered = self._cut(rendered, context)
-
         if 'urlparse' in context.vars:
             rendered = self._urlparse(rendered, context)
 
@@ -138,6 +139,10 @@
         realText = realText[:position] + expr + realText[position:]
         return realText
 
+    def _clearHTML(self, rendered, context):
+        # remove tags
+        return re.sub('<.*?>', '', rendered)
+
     def _cut(self, rendered, context):
         cut = context.vars['cut']
         if len(rendered) <= cut:
@@ -158,7 +163,7 @@
 
         vars = context.vars['urlparse']
         parameters=""
-        
+
         if vars:
             for k, v in vars.items():
                 parameters +='%s="%s" ' % (k, v)



More information about the Checkins mailing list