[Checkins] SVN: lovely.tal/trunk/s giving up on trying to make
cheeseshop render the README.txt correct
Jodok Batlogg
jodok.batlogg at lovelysystems.com
Mon Dec 10 09:36:57 EST 2007
Log message for revision 82229:
giving up on trying to make cheeseshop render the README.txt correct
Changed:
U lovely.tal/trunk/setup.py
U lovely.tal/trunk/src/lovely/tal/README.txt
-=-
Modified: lovely.tal/trunk/setup.py
===================================================================
--- lovely.tal/trunk/setup.py 2007-12-10 13:42:52 UTC (rev 82228)
+++ lovely.tal/trunk/setup.py 2007-12-10 14:36:57 UTC (rev 82229)
@@ -5,8 +5,7 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description=(
- read(os.path.join(os.path.dirname(__file__), 'src',
- 'lovely', 'tal', 'README.txt'))
+ read('src', 'lovely', 'tal', 'README.txt'))
+ '\n' +
read('CHANGES.txt')
+ '\n' +
Modified: lovely.tal/trunk/src/lovely/tal/README.txt
===================================================================
--- lovely.tal/trunk/src/lovely/tal/README.txt 2007-12-10 13:42:52 UTC (rev 82228)
+++ lovely.tal/trunk/src/lovely/tal/README.txt 2007-12-10 14:36:57 UTC (rev 82229)
@@ -1,141 +1,140 @@
==========
-lovely tal
+lovely.tal
==========
the lovely tal package is meant to contain new tal:expressions
+TextFormatter
+=============
+option replace:
+ takes a list of tuples, which characters or strings should be replaced by
+ what, e.g. ``replace python:[(origChar, repChar), (origChar2, repChar2),
+ ...]``
-TextFormatter
--------------
+option allow:
+ takes a list of html-tags which shall be allowed in the string e.g. ``allow
+ python:['a', 'br', 'ul', 'li']`` if this option is not set, the string is
+ restricted to contain no html-tags, therefor the ``< `` and ``>`` are
+ beeing replaced with ``< ``, ``>``
- option replace: takes a list of tuples, which characters or strings should be
- replaced by what, e.g.
- "replace python:[(origChar, repChar), (origChar2, repChar2), ...]"
-
- option allow: takes a list of html-tags which shall be allowed in the string
- e.g. "allow python:['a', 'br', 'ul', 'li']"
- if this option is not set, the string is restricted to
- contain no html-tags, therefor the < and > are replaced
- by <, >
-
- option allow-all: allow all html-tags in the string
- e. g. "allow-all: 'True'"
-
- option break-string: force the string to break after a given number of characters
- e.g. "break-string python:25" breaks the string after
- a sequence of 25 characters not containing a linebreak
+option allow-all:
+ allow all html-tags in the string e.g. ``allow-all: 'True'``
+
+option break-string:
+ force the string to break after a given number of characters e.g.
+ ``break-string python:25`` breaks the string after a sequence of 25
+ characters not containing a linebreak
- option cut: cuts a string to the given length
- option attach: works only together with option 'cut',
- attaches the given string to the expression, if this is longer than
- number of characters given in option 'cut'
-
-<span tal:define="replace python:[('\n', '<br />')];
- allow python:['a', 'br'];
- break-string python:25;
- cut python 25;
- attach '...'"
- tal:content="structure textFormatter: view/description">Description</span>
-
-
+option cut:
+ cuts a string to the given length
+option attach:
+ works only together with option ``cut``, attaches the given string to the
+ expression, if this is longer than number of characters given in option
+ ``cut``
+
+Example::
+
+ <span tal:define="replace python:[('\n', '<br />')];
+ allow python:['a', 'br'];
+ break-string python:25;
+ cut python 25;
+ attach '...'"
+ tal:content="structure textFormatter: view/description">Description</span>
+
Lets see if the TextFormatter does what we want him to.
-We have to fake a context object to call the textformatter
+We have to fake a context object to call the textformatter::
>>> class Context(object):
... vars = {}
... def __init__(self, vars):
... self.vars = vars
-
>>> from lovely.tal.textformatter import TextFormatter
>>> from zope.tales.expressions import simpleTraverse
>>> from zope.app.pagetemplate.engine import TrustedZopeEngine
- >>> tf = TextFormatter('textFormatter', 'view/title', TrustedZopeEngine(), simpleTraverse)
+ >>> tf = TextFormatter('textFormatter', 'view/title', TrustedZopeEngine(),
+ ... simpleTraverse)
>>> context = Context({})
>>> tf._doFormat('<a href="#" name="foolink">foolink</a>', context)
'<a href="#" name="foolink">foolink</a>'
- >>> tf._doFormat('<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>', context)
+ >>> tf._doFormat('<a href="#" name="foolink">foolink</a><br />'
+ ... '<form action="."><input type="text" /></form>', context)
'<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>'
-if we provide an empty context, the textformatter translates all html-tags to < >
+if we provide an empty context, the textformatter translates all html-tags to
+``< >``
Option 'allow'
==============
-We can allow certain html-tags in the text
+We can allow certain html-tags in the text::
>>> context = Context({'allow':['a']})
>>> tf._doFormat('<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>', context)
'<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>'
-
>>> context = Context({'allow':['a', 'br']})
>>> tf._doFormat('<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>', context)
'<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>'
-
>>> context = Context({'allow':['a', 'br', 'form']})
>>> tf._doFormat('<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>', context)
'<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>'
In the above example, still the content of the form tag is translated
-Lets try to write dirty html
+Lets try to write dirty html::
>>> context = Context({'allow':['a', 'br', 'form']})
>>> tf._doFormat('< a href="#" name="foolink">foolink</ a><br/>< form action="."><input type="text" /></form >', context)
'< a href="#" name="foolink">foolink</ a><br/>< form action="."><input type="text" /></form >'
Since the a-tag and the form-tag are not valid html, they are translated, although we declared them to be allowed
-We get the same result if we do not allow them
+We get the same result if we do not allow them::
>>> context = Context({'allow':['br']})
>>> tf._doFormat('< a href="#" name="foolink">foolink</ a><br/>< form action="."><input type="text" /></form >', context)
'< a href="#" name="foolink">foolink</ a><br/>< form action="."><input type="text" /></form >'
-
Option 'allow-all'
==================
-We can allow all html-tags
+We can allow all html-tags::
>>> context = Context({'allow-all':True})
>>> tf._doFormat('<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>', context)
'<a href="#" name="foolink">foolink</a><br /><form action="."><input type="text" /></form>'
-
Option 'replace'
================
We can replace characters or strings, e.g. we would like to replace the '\n' character by '<br />'
-to display the text properly.
+to display the text properly::
>>> context = Context({'replace':[('\n', '<br />')]})
>>> tf._doFormat('das Schwein, \n das aus der Wueste kam', context)
'das Schwein, <br /> das aus der Wueste kam'
-we can also replace strings
+we can also replace strings::
>>> context = Context({'replace':[('\n', '<br />'), ('Schwein', 'Kamel')]})
>>> tf._doFormat('das Schwein, \n das aus der Wueste kam', context)
'das Kamel, <br /> das aus der Wueste kam'
-
Option 'break-string'
=====================
Another option is to break strings after a given number of characters n, in case there
-was no break or '\s' in the last n characters.
+was no break or '\s' in the last n characters::
>>> context = Context({'break-string':8})
>>> tf._doFormat('das Schwein, das aus der Wueste kam', context)
'das<br />Schwein,<br />das aus<br />der<br />Wueste<br />kam'
-
>>> context = Context({'break-string':8})
>>> tf._doFormat('ein superlangerstring mit ein paar kurzen strings', context)
'ein<br />superlan<br />gerstrin<br />g mit<br />ein paar<br />kurzen<br />strings'
-Also multi line text works.
+Also multi line text works::
>>> context = Context({'break-string':40})
>>> res = tf._doFormat("""
@@ -159,7 +158,6 @@
is longer than 80 characters, hopefully
it works
<BLANKLINE>
-
>>> context = Context({'break-string':20, 'allow':['br']})
>>> text = u'eins zwei drei vier fuenf sechs sieben,<br />'
>>> text += u'in der Schule wird geschrieben,<br />'
@@ -177,30 +175,27 @@
pitschpatsch macht!
the formatter considers tags as not to be part of the text, that means that
-breaks aren't made inside tags (<...>)
+breaks aren't made inside tags (<...>)::
>>> context = Context({'break-string':8, 'allow':['a']})
>>> tf._doFormat('working at <a href="www.lovelysystems.com" name="lovelysystems">lovelysystems</a> is great!', context)
'working<br />at<br /><a href="www.lovelysystems.com" name="lovelysystems">lovelysy<br />stems</a> is<br />great!'
-
Option 'cut'
============
-We can also cut strings to a given length
+We can also cut strings to a given length::
>>> context = Context({'cut':20})
>>> rendered = tf._doFormat('ein superlangerstring mit ein paar kurzen strings', context)
>>> len(rendered) == 20
True
-
Option 'attach'
===============
-and attach a string to the expression
+and attach a string to the expression::
>>> context = Context({'cut':20, 'attach':'...'})
>>> tf._doFormat('ein superlangerstring mit ein paar kurzen strings', context)
'ein superlangerstrin...'
-
More information about the Checkins
mailing list